NetworkListenerImpl implements NetworkListener { @Override public void onError(NetworkChannel channel, Exception exception) { component.tell(new ConnectionError(channel, exception), ComponentImpl.NOBODY); } NetworkListenerImpl(Component component); @Override void onRead(NetworkChannel channel, ByteBuf buffer); @Override void onClose(NetworkChannel channel); @Override void onError(NetworkChannel channel, Exception exception);  }
@Test public void onError() { MockComponent component = new MockComponent(); NetworkListenerImpl listener = new NetworkListenerImpl(component); StubNetworkChannel expectedChannel = new StubNetworkChannel(); Exception expectedException = new Exception(); listener.onError(expectedChannel, expectedException); assertEquals("Expected component to receive 1 message", 1, component.getMessages().size()); assertTrue("Expected message to be instanceof ConnectionError", component.getMessages().get(0) instanceof ConnectionError); ConnectionError error = (ConnectionError)component.getMessages().get(0); assertSame("Expected same channel in message", expectedChannel, error.channel); assertSame("Expected same exception in message", expectedException, error.cause); }