LogMessagesHandler extends SubscriptionHandler<LogMessage> { public void stop() { printAllPostponedMessages(); flushTimer.cancel(); } @Inject  LogMessagesHandler(LogMessageUnmarshaller unmarshaller,
                              ConsoleContainer consoleContainer,
                              TimerFactory timerFactory,
                              @NotNull @Assisted Runner runner,
                              @NotNull @Assisted ErrorHandler errorHandler); void stop();  }
@Test public void shouldStopWhenListOfMessageAreEmpty() throws Exception { logMessagesHandler.stop(); verify(consoleContainer, never()).print(eq(runner), isNull(String.class)); verify(flushTimer).cancel(); }
@Test public void shouldStop() throws Exception { when(logMessage1.getNumber()).thenReturn(3); when(logMessage2.getNumber()).thenReturn(2); when(logMessage3.getNumber()).thenReturn(4); logMessagesHandler.onMessage(message1); logMessagesHandler.onMessage(message2); logMessagesHandler.onMessage(message3); logMessagesHandler.stop(); verify(logMessage1).getText(); verify(consoleContainer).print(runner, MESSAGE1); verify(logMessage1, times(2)).getNumber(); verify(logMessage2).getText(); verify(consoleContainer).print(runner, MESSAGE2); verify(logMessage2, times(2)).getNumber(); verify(logMessage3).getText(); verify(consoleContainer).print(runner, MESSAGE3); verify(logMessage3, times(2)).getNumber(); verify(flushTimer).cancel(); }