]> source.dussan.org Git - sonarqube.git/commitdiff
Don't use sleep in unit test
authorDavid Gageot <david@gageot.net>
Mon, 2 Jul 2012 14:42:47 +0000 (16:42 +0200)
committerDavid Gageot <david@gageot.net>
Mon, 2 Jul 2012 14:43:46 +0000 (16:43 +0200)
sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java

index 81ca22c657d8e646a5850817615abc82d1e575bd..8b34d1efc5d4772219ec7b1e1582d7929934d4ba 100644 (file)
@@ -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);
   }
 
   /**