NetworkListenerImpl implements NetworkListener { @Override public void onClose(NetworkChannel channel) { component.tell(new ConnectionError(channel, new IOException("Network connection closed by server")), 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 onClose() { MockComponent component = new MockComponent(); NetworkListenerImpl listener = new NetworkListenerImpl(component); StubNetworkChannel expectedChannel = new StubNetworkChannel(); listener.onClose(expectedChannel); 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); assertNotNull("Expected a cause to be filled in in the message", error.cause); }