Repository: netty/netty
File: codec-compression/src/test/java/io/netty/handler/codec/compression/ZstdEncoderTest.java (Java)

Code before:

        assertTrue(channel.finish());

        ByteBuf decompressed = readDecompressed(dataLength);
        assertEquals(data, decompressed);

        decompressed.release();
        data.release();
    }

    @ParameterizedTest
    @MethodSource("smallData")
    public void testCompressionOfSmallBatchedFlow(final ByteBuf data) throws Exception {
        testCompressionOfBatchedFlow(data);
    }

    @Test
    public void testCompressionOfTinyData() throws Exception {
        ByteBuf data = Unpooled.copiedBuffer("Hello, World", CharsetUtil.UTF_8);
        assertTrue(channel.writeOutbound(data));
        assertTrue(channel.finish());

        ByteBuf out = channel.readOutbound();
        assertThat(out.readableBytes()).isPositive();
        out.release();
        asssertNull(out.readOutbound());
    }

    @Override
    protected ByteBuf decompress(ByteBuf compressed, int originalLength) throws Exception {
        byte[] decompressed = new byte[originalLength];
        try (ZstdInputStream zstdIs = new ZstdInputStream(new ByteBufInputStream(compressed, true))) {

            int remaining = originalLength;
            while (remaining > 0) {
                int read = zstdIs.read(decompressed, originalLength - remaining, remaining);
                if (read > 0) {
                    remaining -= read;
                } else {
                    break;
                }
            }
            assertEquals(-1, zstdIs.read());
        }

        return Unpooled.wrappedBuffer(decompressed);
    }
}


Review comment (suggestion):
```suggestion
        asssertNull(channel.readOutbound());
```

Code after:

        assertTrue(channel.finish());

        ByteBuf decompressed = readDecompressed(dataLength);
        assertEquals(data, decompressed);

        decompressed.release();
        data.release();
    }

    @ParameterizedTest
    @MethodSource("smallData")
    public void testCompressionOfSmallBatchedFlow(final ByteBuf data) throws Exception {
        testCompressionOfBatchedFlow(data);
    }

    @Test
    public void testCompressionOfTinyData() throws Exception {
        ByteBuf data = Unpooled.copiedBuffer("Hello, World", CharsetUtil.UTF_8);
        assertTrue(channel.writeOutbound(data));
        assertTrue(channel.finish());

        ByteBuf out = channel.readOutbound();
        assertThat(out.readableBytes()).isPositive();
        out.release();
        assertNull(channel.readOutbound());
    }

    @Override
    protected ByteBuf decompress(ByteBuf compressed, int originalLength) throws Exception {
        byte[] decompressed = new byte[originalLength];
        try (ZstdInputStream zstdIs = new ZstdInputStream(new ByteBufInputStream(compressed, true))) {

            int remaining = originalLength;
            while (remaining > 0) {
                int read = zstdIs.read(decompressed, originalLength - remaining, remaining);
                if (read > 0) {
                    remaining -= read;
                } else {
                    break;
                }
            }
            assertEquals(-1, zstdIs.read());
        }

        return Unpooled.wrappedBuffer(decompressed);
    }
}