@Test public void listenerIsNotifiedAboutConditionErrorEvent() throws Exception { final RobotAgentEventListener listener = mock(RobotAgentEventListener.class); when(listener.isHandlingEvents()).thenReturn(true); final RobotAgentEventDispatcher dispatcher = new RobotAgentEventDispatcher(null, listener); final ImmutableMap<String, String> attributes = ImmutableMap.of("error", "Error evaluating condition"); final String json = toJson(ImmutableMap.of("condition_result", newArrayList(attributes))); dispatcher.runEventsLoop(readerFor(json)); verify(listener).eventsProcessingAboutToStart(); verify(listener, atLeast(1)).isHandlingEvents(); verify(listener).handleConditionEvaluated(new ConditionEvaluatedEvent("Error evaluating condition")); verify(listener).eventsProcessingFinished(); verifyNoMoreInteractions(listener); }
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);   }