DefaultNettyClient implements NettyClient { @Override public void sendRequest(ByteBuf byteBuf) { channel.writeAndFlush(byteBuf); } DefaultNettyClient(Channel channel); @Override void sendRequest(ByteBuf byteBuf); @Override void sendRequest(ByteBuf byteBuf, final ByteBufReceiver byteBufReceiver); @Override void onTimeout(ByteBufReceiver byteBufReceiver, int timeoutMill); @Override void handleResponse(Channel channel, ByteBuf byteBuf); @Override Channel channel(); @Override String toString();  }
@Test public void testSendRequest() throws Exception { String msg = "test\r\n"; AtomicBoolean callReceive = new AtomicBoolean(false); Mockito.doAnswer(invocation -> { callReceive.set(true); ByteBuf byteBuf = invocation.getArgumentAt(1, ByteBuf.class); Assert.assertEquals(msg, byteBuf.toString()); return ByteBufReceiver.RECEIVER_RESULT.SUCCESS; }).when(receiver).receive(Mockito.any(), Mockito.any()); nettyClient.sendRequest(Unpooled.copiedBuffer(msg.getBytes()), receiver); waitConditionUntilTimeOut(callReceive::get, 2000); }