@Test public void shouldPeriodicallyProcessQueue() throws Exception { NotificationQueueElement queueElement = mock(NotificationQueueElement.class); Notification notification = mock(Notification.class); when(queueElement.getNotification()).thenReturn(notification); 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, times(3)) .deliver(notification); // 3 times - 1 on start, 1 after delay, 1 on stop }