### Question:
ConnectionEventPublisher extends ConnectionEventListener implements EventSource<T>, EventPublisher { @Override public void onCustomEvent(Object event) { listeners.invokeListeners(customEventAction, event); } ConnectionEventPublisher();  ConnectionEventPublisher(ConnectionEventPublisher<T> toCopy); @Override void onByteRead(final long bytesRead); @Override void onByteWritten(long bytesWritten); @Override void onFlushStart(); @Override void onFlushComplete(final long duration, final TimeUnit timeUnit); @Override void onWriteStart(); @Override void onWriteSuccess(final long duration, final TimeUnit timeUnit); @Override void onWriteFailed(final long duration, final TimeUnit timeUnit, final Throwable throwable); @Override void onConnectionCloseStart(); @Override void onConnectionCloseSuccess(final long duration, final TimeUnit timeUnit); @Override void onConnectionCloseFailed(final long duration, final TimeUnit timeUnit, final Throwable throwable); @Override void onCustomEvent(Object event); @Override void onCustomEvent(Object event, long duration, TimeUnit timeUnit); @Override void onCustomEvent(Object event, long duration, TimeUnit timeUnit, Throwable throwable); @Override void onCustomEvent(Object event, Throwable throwable); @Override Subscription subscribe(T listener); @Override boolean publishingEnabled(); ConnectionEventPublisher<T> copy();  }### Answer:
@Test(timeout = 60000) public void testCustomEvent() throws Exception { Object event = "Hello"; rule.publisher.onCustomEvent(event); rule.listener.assertMethodsCalled(Event.CustomEvent); assertThat("Listener not called with event.", rule.listener.getCustomEvent(), is(event)); }
@Test(timeout = 60000) public void testCustomEventWithError() throws Exception { final Throwable expected = new NullPointerException("Deliberate"); Object event = "Hello"; rule.publisher.onCustomEvent(event, expected); rule.listener.assertMethodsCalled(Event.CustomEventWithError); assertThat("Listener not called with event.", rule.listener.getCustomEvent(), is(event)); assertThat("Listener not called with error.", rule.listener.getRecievedError(), is(expected)); }
@Test(timeout = 60000) public void testCustomEventWithDuration() throws Exception { Object event = "Hello"; rule.publisher.onCustomEvent(event, 1, TimeUnit.MILLISECONDS); rule.listener.assertMethodsCalled(Event.CustomEventWithDuration); assertThat("Listener not called with event.", rule.listener.getCustomEvent(), is(event)); assertThat("Listener not called with duration.", rule.listener.getDuration(), is(1L)); assertThat("Listener not called with time unit.", rule.listener.getTimeUnit(), is(TimeUnit.MILLISECONDS)); }
@Test(timeout = 60000) public void testCustomEventWithDurationAndError() throws Exception { final Throwable expected = new NullPointerException("Deliberate"); Object event = "Hello"; rule.publisher.onCustomEvent(event, 1, TimeUnit.MILLISECONDS, expected); rule.listener.assertMethodsCalled(Event.CustomEventWithDurationAndError); assertThat("Listener not called with event.", rule.listener.getCustomEvent(), is(event)); assertThat("Listener not called with duration.", rule.listener.getDuration(), is(1L)); assertThat("Listener not called with time unit.", rule.listener.getTimeUnit(), is(TimeUnit.MILLISECONDS)); assertThat("Listener not called with error.", rule.listener.getRecievedError(), is(expected)); }