### Question:
SynchronousEventHub extends EventHub<E> { @Override @SuppressWarnings("deprecation") public void processEvent(E event) { for (Map.Entry<EventListener<E>, EventFilter<E>> curEntry : new HashMap<>(getEventListeners()).entrySet()) { try { if (curEntry.getValue().accept(event)) { curEntry.getKey().processEvent(event); } } catch (Exception exc) { LOG.warn("Exception thrown by event handler", exc); } } } SynchronousEventHub(); @Override @SuppressWarnings("deprecation") void processEvent(E event);  }### Answer:
@Test public void shouldDeliverToRegisteredListener() { @SuppressWarnings("unchecked") EventListener<TCSEvent> listener = mock(EventListener.class); hub.addEventListener(listener); TCSEvent event = new TCSEvent() { }; hub.processEvent(event); verify(listener).processEvent(event); }
@Test public void shouldNotDeliverToUnregisteredListener() { @SuppressWarnings("unchecked") EventListener<TCSEvent> listener = mock(EventListener.class); hub.addEventListener(listener); hub.removeEventListener(listener); TCSEvent event = new TCSEvent() { }; hub.processEvent(event); verify(listener, never()).processEvent(any(TCSEvent.class)); }
@Test @SuppressWarnings({"unchecked", "deprecation"}) public void testAcceptingListener() { EventListener<TCSEvent> acceptingListener = mock(EventListener.class); EventFilter<TCSEvent> acceptingFilter = mock(EventFilter.class); TCSEvent event = mock(TCSEvent.class); doReturn(true).when(acceptingFilter).accept(any(TCSEvent.class)); hub.addEventListener(acceptingListener, acceptingFilter); hub.processEvent(event); verify(acceptingFilter, times(1)).accept(any(TCSEvent.class)); verify(acceptingListener, times(1)).processEvent(event); }
@Test @SuppressWarnings({"unchecked", "deprecation"}) public void testRefusingListener() { EventListener<TCSEvent> refusingListener = mock(EventListener.class); EventFilter<TCSEvent> refusingFilter = mock(EventFilter.class); TCSEvent event = mock(TCSEvent.class); doReturn(false).when(refusingFilter).accept(any(TCSEvent.class)); hub.addEventListener(refusingListener, refusingFilter); hub.processEvent(event); verify(refusingFilter, times(1)).accept(any(TCSEvent.class)); verify(refusingListener, never()).processEvent(event); }