@Test
    public void testDecodeIllegalPacket() throws Exception {
        ChannelHandlerContext context = new MockedChannelHandlerContext();
        ByteBuf byteBuf = Unpooled.buffer(8);
        byteBuf.writeByte((byte) 13);
        ProtocolCodeBasedDecoder decoder = new ProtocolCodeBasedDecoder(1);

        int readerIndex = byteBuf.readerIndex();
        Assert.assertEquals(0, readerIndex);

        Exception exception = null;
        try {
            // decode exception
            decoder.decode(context, byteBuf, new ArrayList<Object>());
        } catch (Exception e) {
            // ignore
            exception = e;
        }
        Assert.assertNotNull(exception);

        readerIndex = byteBuf.readerIndex();
        Assert.assertEquals(0, readerIndex);
    }
@author chengyi (mark.lx@antfin.com) 2021-05-24 20:07
src/test/java/com/alipay/remoting/codec/ProtocolCodeBasedDecoderTest.java