MySQLPacketCodecEngine implements DatabasePacketCodecEngine<MySQLPacket> { @Override public void encode(final ChannelHandlerContext context, final MySQLPacket message, final ByteBuf out) { try (MySQLPacketPayload payload = new MySQLPacketPayload(context.alloc().buffer())) { message.write(payload); out.writeMediumLE(payload.getByteBuf().readableBytes()); out.writeByte(message.getSequenceId()); out.writeBytes(payload.getByteBuf()); } }  @Override boolean isValidHeader(final int readableBytes); @Override void decode(final ChannelHandlerContext context, final ByteBuf in, final List<Object> out, final int readableBytes); @Override void encode(final ChannelHandlerContext context, final MySQLPacket message, final ByteBuf out); @Override MySQLPacketPayload createPacketPayload(final ByteBuf message);  }
@Test public void assertEncode() { ByteBufAllocator byteBufAllocator = mock(ByteBufAllocator.class); when(context.alloc()).thenReturn(byteBufAllocator); ByteBuf payloadByteBuf = mock(ByteBuf.class); when(byteBufAllocator.buffer()).thenReturn(payloadByteBuf); when(payloadByteBuf.readableBytes()).thenReturn(50); MySQLPacket actualMessage = mock(MySQLPacket.class); when(actualMessage.getSequenceId()).thenReturn(1); new MySQLPacketCodecEngine().encode(context, actualMessage, byteBuf); verify(actualMessage).write(ArgumentMatchers.any()); verify(byteBuf).writeMediumLE(50); verify(byteBuf).writeByte(1); verify(byteBuf).writeBytes(payloadByteBuf); }