BackendSessionHandler extends AbstractSessionNettyHandler { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if(!(msg instanceof ByteBuf)) { logger.error("[channelRead] InCorrect Type: {}", msg.getClass().getName()); throw new ResourceIncorrectException("Unexpected type for read: {}" + msg.getClass().getName()); } tunnel.forwardToFrontend((ByteBuf) msg); ctx.fireChannelRead(msg); } BackendSessionHandler(Tunnel tunnel); @Override void channelRead(ChannelHandlerContext ctx, Object msg);  }
@Test public void channelRead() { String expected = "HEllo world"; doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object object = invocation.getArguments()[0]; Assert.assertTrue(object instanceof ByteBuf); Assert.assertEquals(expected, ((ByteBuf)object).toString(Charset.defaultCharset())); return null; } }).when(tunnel).forwardToFrontend(any()); channel.writeInbound(Unpooled.copiedBuffer(expected.getBytes())); verify(tunnel).forwardToFrontend(any()); }