### Question:
MultiPacketCodec extends MessageToPacketCodec { @Override public Object decode(Connection connection, ByteBuf in) throws CodecException { MultiMessage multiMessage = null; while (in.readableBytes() > 0) { int readerIndex = in.readerIndex(); try { Object msg = super.decode(connection, in); if (multiMessage == null) { multiMessage = MultiMessage.create(); } multiMessage.addMessage(msg); } catch (PacketUnknownCodecException | PacketSizeLimitCodecException e) { in.readerIndex(readerIndex); throw e; } catch (PacketNotIntactCodecException e) { in.readerIndex(readerIndex); break; } } return multiMessage; } MultiPacketCodec();  MultiPacketCodec(PacketToMessageConverter converter);  MultiPacketCodec(PacketToMessageConverter converter, PacketCodec packetCodec); @Override void encode(Connection connection, Object message, ByteBuf out); @Override Object decode(Connection connection, ByteBuf in);  }### Answer:
@DisplayName("test_decode_WithNotIntact") @Test void testDecodeWithNotIntact() { ByteBuf out = PooledByteBufAllocator.DEFAULT.heapBuffer(); out.writeByte(0xbc); out.writeByte(0xc0); out.writeByte(1); out.writeByte(0); out.writeInt(1); out.writeByte(0); out.writeInt(1); MultiMessage msg = (MultiMessage) codec.decode(connection, out); assertNull(msg); }
@DisplayName("test_decode_WithHugePacket") @Test void testDecodeWithHugePacket() { ByteBuf out = PooledByteBufAllocator.DEFAULT.heapBuffer(); out.writeByte(0xbc); out.writeByte(0xc0); out.writeByte(1); out.writeByte(0); out.writeInt(1); out.writeByte(0); out.writeInt(10 * 1024 * 1024 + 1); try { codec.decode(connection, out); fail(); } catch (CodecException e) { assertEquals(PacketSizeLimitCodecException.class, e.getClass()); } }
@DisplayName("test_decode_WithUnknownPacket") @Test void testDecodeWithUnknownPacket() { ByteBuf out = PooledByteBufAllocator.DEFAULT.heapBuffer(); out.writeByte(0xc0); out.writeByte(0xbc); out.writeByte(1); out.writeByte(0); out.writeInt(1); out.writeByte(0); out.writeInt(0); try { codec.decode(connection, out); fail(); } catch (CodecException e) { assertEquals(PacketUnknownCodecException.class, e.getClass()); } }
@DisplayName("test_decode") @Test void testDecode() { ByteBuf out = PooledByteBufAllocator.DEFAULT.heapBuffer(); out.writeByte(0xbc); out.writeByte(0xc0); out.writeByte(1); out.writeByte(0); out.writeInt(1); out.writeByte(0); out.writeInt(12); out.writeBytes("Hello,World!".getBytes()); out.writeByte(0xbc); out.writeByte(0xc0); out.writeByte(1); out.writeByte(0); out.writeInt(1); out.writeByte(0); out.writeInt(4); out.writeBytes("HaHa".getBytes()); MultiMessage msg = (MultiMessage) codec.decode(connection, out); assertEquals(2, msg.size()); assertEquals("Hello,World!", new String(((Packet)msg.get(0)).getPayload())); assertEquals("HaHa", new String(((Packet)msg.get(1)).getPayload())); }