NetworkListenerImpl implements NetworkListener { @Override public void onRead(NetworkChannel channel, ByteBuf buffer) { component.tell(new DataRead(channel, buffer), 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 onRead() { MockComponent component = new MockComponent(); NetworkListenerImpl listener = new NetworkListenerImpl(component); StubNetworkChannel expectedChannel = new StubNetworkChannel(); ByteBuffer buf = ByteBuffer.allocate(1); ByteBuf expectedBuffer = Unpooled.wrappedBuffer(buf); listener.onRead(expectedChannel, expectedBuffer); assertEquals("Expected component to receive 1 message", 1, component.getMessages().size()); assertTrue("Expected message to be instanceof DataRead", component.getMessages().get(0) instanceof DataRead); DataRead read = (DataRead)component.getMessages().get(0); assertSame("Expected same buffer in message", expectedBuffer, read.buffer); assertSame("Expected same channel in message", expectedChannel, read.channel); }