DefaultEventManager implements EventManager { @Override public void on(Event event) { if (eventListeners != null) { for (EventListener listener : eventListeners) { switch (event.getType()) { case MAPPING_STARTED: listener.onMappingStarted(event); break; case MAPPING_PRE_WRITING_DEST_VALUE: listener.onPreWritingDestinationValue(event); break; case MAPPING_POST_WRITING_DEST_VALUE: listener.onPostWritingDestinationValue(event); break; case MAPPING_FINISHED: listener.onMappingFinished(event); break; default: throw new MappingException("Unsupported event type: " + event.getType()); } } } } DefaultEventManager(List<? extends EventListener> eventListeners); @Override void on(Event event);  }
@Test public void handlesEmptyListeners() { Event mockedEvent = mock(DefaultEvent.class); when(mockedEvent.getType()).thenReturn(EventTypes.MAPPING_STARTED); EventManager manager = new DefaultEventManager(new ArrayList<>(0)); manager.on(mockedEvent); assertTrue(true); }
@Test public void handlesNullListeners() { Event mockedEvent = mock(DefaultEvent.class); when(mockedEvent.getType()).thenReturn(EventTypes.MAPPING_FINISHED); EventManager manager = new DefaultEventManager(null); manager.on(mockedEvent); assertTrue(true); }
@Test public void handlesOnMappingStarted() { Event mockedEvent = mock(DefaultEvent.class); when(mockedEvent.getType()).thenReturn(EventTypes.MAPPING_STARTED); EventListener listener = mock(EventListener.class); List<EventListener> listeners = new ArrayList<>(1); listeners.add(listener); EventManager manager = new DefaultEventManager(listeners); manager.on(mockedEvent); verify(listener).onMappingStarted(mockedEvent); assertTrue(true); }
@Test public void handlesOnMappingPreWrite() { Event mockedEvent = mock(DefaultEvent.class); when(mockedEvent.getType()).thenReturn(EventTypes.MAPPING_PRE_WRITING_DEST_VALUE); EventListener listener = mock(EventListener.class); List<EventListener> listeners = new ArrayList<>(1); listeners.add(listener); EventManager manager = new DefaultEventManager(listeners); manager.on(mockedEvent); verify(listener).onPreWritingDestinationValue(mockedEvent); assertTrue(true); }
@Test public void handlesOnMappingPostWrite() { Event mockedEvent = mock(DefaultEvent.class); when(mockedEvent.getType()).thenReturn(EventTypes.MAPPING_POST_WRITING_DEST_VALUE); EventListener listener = mock(EventListener.class); List<EventListener> listeners = new ArrayList<>(1); listeners.add(listener); EventManager manager = new DefaultEventManager(listeners); manager.on(mockedEvent); verify(listener).onPostWritingDestinationValue(mockedEvent); assertTrue(true); }
@Test public void handlesOnMappingFinished() { Event mockedEvent = mock(DefaultEvent.class); when(mockedEvent.getType()).thenReturn(EventTypes.MAPPING_FINISHED); EventListener listener = mock(EventListener.class); List<EventListener> listeners = new ArrayList<>(1); listeners.add(listener); EventManager manager = new DefaultEventManager(listeners); manager.on(mockedEvent); verify(listener).onMappingFinished(mockedEvent); assertTrue(true); }