diff options
author | David Gageot <david@gageot.net> | 2012-07-02 16:42:47 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-07-02 16:43:46 +0200 |
commit | 5106a5b25a89a4f02556952e7fd975e2da437f08 (patch) | |
tree | fe6d58803d7f31047ecc04d92f1a253456198b01 /sonar-server/src/test | |
parent | 29e05cee1b47b44273c5247cad4895a9c76d7e39 (diff) | |
download | sonarqube-5106a5b25a89a4f02556952e7fd975e2da437f08.tar.gz sonarqube-5106a5b25a89a4f02556952e7fd975e2da437f08.zip |
Don't use sleep in unit test
Diffstat (limited to 'sonar-server/src/test')
-rw-r--r-- | sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java b/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java index 81ca22c657d..8b34d1efc5d 100644 --- a/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java +++ b/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java @@ -86,16 +86,19 @@ public class NotificationServiceTest { @Test public void shouldPeriodicallyProcessQueue() throws Exception { NotificationQueueElement queueElement = mock(NotificationQueueElement.class); - Notification notification = mock(Notification.class); - when(queueElement.getNotification()).thenReturn(notification); + Notification startNotification = mock(Notification.class); + Notification afterDelayNotification = mock(Notification.class); + Notification stopNotification = mock(Notification.class); + when(queueElement.getNotification()).thenReturn(startNotification, afterDelayNotification, stopNotification); when(manager.getFromQueue()).thenReturn(queueElement).thenReturn(null).thenReturn(queueElement).thenReturn(null).thenReturn(queueElement).thenReturn(null); doNothing().when(service).deliver(any(Notification.class)); service.start(); - Thread.sleep(1500); // sleep 1.5 second to process queue - service.stop(); + verify(service, timeout(15000)).deliver(startNotification); + verify(service, timeout(1500)).deliver(afterDelayNotification); - verify(service, times(3)).deliver(notification); // 3 times - 1 on start, 1 after delay, 1 on stop + service.stop(); + verify(service, timeout(1500)).deliver(stopNotification); } /** |