@Test public void whenAtLeastOneListenerIsHandlingEvents_allAreNotifiedAboutIt() throws Exception { final RobotAgentEventListener listener1 = mock(RobotAgentEventListener.class); final RobotAgentEventListener listener2 = mock(RobotAgentEventListener.class); final RobotAgentEventListener listener3 = mock(RobotAgentEventListener.class); when(listener1.isHandlingEvents()).thenReturn(false); when(listener2.isHandlingEvents()).thenReturn(true); when(listener3.isHandlingEvents()).thenReturn(false); final RobotAgentEventDispatcher dispatcher = new RobotAgentEventDispatcher(null, listener1, listener2, listener3); final String json = toJson(ImmutableMap.of("ready_to_start", 1)); dispatcher.runEventsLoop(readerFor(json)); verify(listener1).eventsProcessingAboutToStart(); verify(listener1, atLeast(0)).isHandlingEvents(); verify(listener1).handleAgentIsReadyToStart(new ReadyToStartEvent(null)); verify(listener1).eventsProcessingFinished(); verifyNoMoreInteractions(listener1); verify(listener2).eventsProcessingAboutToStart(); verify(listener2, atLeast(1)).isHandlingEvents(); verify(listener2).handleAgentIsReadyToStart(new ReadyToStartEvent(null)); verify(listener2).eventsProcessingFinished(); verifyNoMoreInteractions(listener2); verify(listener3).eventsProcessingAboutToStart(); verify(listener3, atLeast(0)).isHandlingEvents(); verify(listener3).handleAgentIsReadyToStart(new ReadyToStartEvent(null)); verify(listener3).eventsProcessingFinished(); verifyNoMoreInteractions(listener3); }
void runEventsLoop(final BufferedReader eventReader) throws IOException, RobotAgentEventsListenerException { try { for (final RobotAgentEventListener listener : eventsListeners) { listener.eventsProcessingAboutToStart(); } eventsLoop(eventReader); } finally { for (final RobotAgentEventListener listener : eventsListeners) { listener.eventsProcessingFinished(); } } }
RobotAgentEventDispatcher { void runEventsLoop(final BufferedReader eventReader) throws IOException, RobotAgentEventsListenerException { try { for (final RobotAgentEventListener listener : eventsListeners) { listener.eventsProcessingAboutToStart(); } eventsLoop(eventReader); } finally { for (final RobotAgentEventListener listener : eventsListeners) { listener.eventsProcessingFinished(); } } } }
RobotAgentEventDispatcher { void runEventsLoop(final BufferedReader eventReader) throws IOException, RobotAgentEventsListenerException { try { for (final RobotAgentEventListener listener : eventsListeners) { listener.eventsProcessingAboutToStart(); } eventsLoop(eventReader); } finally { for (final RobotAgentEventListener listener : eventsListeners) { listener.eventsProcessingFinished(); } } } RobotAgentEventDispatcher(final AgentClient client, final RobotAgentEventListener... eventsListeners); }
RobotAgentEventDispatcher { void runEventsLoop(final BufferedReader eventReader) throws IOException, RobotAgentEventsListenerException { try { for (final RobotAgentEventListener listener : eventsListeners) { listener.eventsProcessingAboutToStart(); } eventsLoop(eventReader); } finally { for (final RobotAgentEventListener listener : eventsListeners) { listener.eventsProcessingFinished(); } } } RobotAgentEventDispatcher(final AgentClient client, final RobotAgentEventListener... eventsListeners);  }
RobotAgentEventDispatcher { void runEventsLoop(final BufferedReader eventReader) throws IOException, RobotAgentEventsListenerException { try { for (final RobotAgentEventListener listener : eventsListeners) { listener.eventsProcessingAboutToStart(); } eventsLoop(eventReader); } finally { for (final RobotAgentEventListener listener : eventsListeners) { listener.eventsProcessingFinished(); } } } RobotAgentEventDispatcher(final AgentClient client, final RobotAgentEventListener... eventsListeners);   }