### Question:
MySQLLengthFieldBasedFrameEncoder extends MessageToByteEncoder { @Override protected void encode(final ChannelHandlerContext ctx, final Object msg, final ByteBuf out) { ByteBuf byteBuf = ((AbstractPacket) msg).toByteBuf(); HeaderPacket h = new HeaderPacket(); h.setPacketBodyLength(byteBuf.readableBytes()); h.setPacketSequenceNumber(((AbstractPacket) msg).getSequenceNumber()); out.writeBytes(h.toByteBuf()); out.writeBytes(byteBuf); }    }### Answer:
@Test public void assertEncode() { MySQLLengthFieldBasedFrameEncoder encoder = new MySQLLengthFieldBasedFrameEncoder(); encoder.encode(null, packet, outByteBuf); verify(outByteBuf, times(2)).writeBytes(any(ByteBuf.class)); verify(outByteBuf).writeBytes(packetByteBuf); }