Skip to content

Commit

Permalink
chore: remove smelling sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
webatspeed committed Oct 11, 2022
1 parent d9a04e1 commit 346c67e
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.caritas.cob.messageservice.api.service;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -10,7 +10,6 @@
import de.caritas.cob.messageservice.userservice.generated.web.LiveproxyControllerApi;
import java.lang.management.ManagementFactory;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.RandomStringUtils;
import org.jeasy.random.EasyRandom;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -59,8 +58,7 @@ void sendLiveEventShouldRunInAnotherThread() {
}

@Test
void sendLiveEventShouldNeverCallAuthenticatedUserMethodsWhenAccessTokenGiven()
throws InterruptedException {
void sendLiveEventShouldNeverCallAuthenticatedUserMethodsWhenAccessTokenGiven() {
when(liveproxyControllerApi.getApiClient()).thenReturn(apiClient);

underTest.sendLiveEvent(
Expand All @@ -69,13 +67,12 @@ void sendLiveEventShouldNeverCallAuthenticatedUserMethodsWhenAccessTokenGiven()
Optional.of(easyRandom.nextLong())
);

TimeUnit.SECONDS.sleep(1); // wait for the async thread
verify(authenticatedUser, never()).getAccessToken();
verify(authenticatedUser, timeout(1000).times(0))
.getAccessToken();
}

@Test
void sendLiveEventShouldCallAuthenticatedUserMethodsWhenAccessTokenMissing()
throws InterruptedException {
void sendLiveEventShouldCallAuthenticatedUserMethodsWhenAccessTokenMissing() {
when(liveproxyControllerApi.getApiClient()).thenReturn(apiClient);

underTest.sendLiveEvent(
Expand All @@ -84,7 +81,6 @@ void sendLiveEventShouldCallAuthenticatedUserMethodsWhenAccessTokenMissing()
Optional.of(easyRandom.nextLong())
);

TimeUnit.SECONDS.sleep(1); // wait for the async thread
verify(authenticatedUser).getAccessToken();
verify(authenticatedUser, timeout(1000)).getAccessToken();
}
}

0 comments on commit 346c67e

Please sign in to comment.