ServerEventRelay implements EventRelay, EventHandler { @Override public void sendEventMessage(MotechEvent event) { verifyEventNotNull(event); Set<EventListener> listeners = getEventListeners(event); if (!listeners.isEmpty()) { splitEvent(event, listeners); } } @Autowired  ServerEventRelay(OutboundEventGateway outboundEventGateway, EventListenerRegistry eventListenerRegistry, MotechEventConfig motechEventConfig,
                            EventAdmin osgiEventAdmin, BundleContext bundleContext); @Override void sendEventMessage(MotechEvent event); @Override void broadcastEventMessage(MotechEvent event); void relayQueueEvent(MotechEvent event); void relayTopicEvent(MotechEvent event); @Override void handleEvent(Event osgiEvent);  }
@Test public void testSplitEvents() throws Exception { MotechEvent motechEvent = createEvent(); setUpListeners(SUBJECT, eventListener, secondaryEventListener); eventRelay.sendEventMessage(motechEvent); ArgumentCaptor<MotechEvent> argumentCaptor = ArgumentCaptor.forClass(MotechEvent.class); verify(outboundEventGateway, times(2)).sendEventMessage(argumentCaptor.capture()); MotechEvent capturedEvent; capturedEvent = argumentCaptor.getAllValues().get(0); assertEquals(capturedEvent.getMessageDestination(), LISTENER_IDENTIFIER); capturedEvent = argumentCaptor.getAllValues().get(1); assertEquals(capturedEvent.getMessageDestination(), SECONDARY_LISTENER_IDENTIFIER); }