Repository: netty/netty
File: buffer/src/test/java/io/netty/buffer/ByteBufStreamTest.java (Java)

Code before:
            });
        } finally {
            buf.release();
            in.close();
        }
    }

    @Test
    public void testReleaseOnCloseInByteBufOutputStream() throws Exception {
        ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer(16);
        buf.writeBytes(new byte[] { 1, 2, 3, 4, 5, 6 });
        final ByteBufOutputStream out = new ByteBufOutputStream(buf, true);
        try {
            out.writeBoolean(true);
            out.writeBoolean(false);
            out.writeByte(42);
            out.writeByte(224);
            out.writeBytes("Hello, World!");
            out.write(new byte[]{1, 3, 3, 4}, 0, 0);
        } finally {
            out.close();
        }
        // When releaseOnClose is set to true, ByteBuf will be automatically released after calling the close method of
        // ByteBufOutputStream.
        int i = ReferenceCountUtil.refCnt(out.buffer());
        assertEquals(0, i);
    }

    @Test
    public void testGeneralByteBufOutputStream() throws Exception {
        // case1
        ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer(16);
        buf.writeBytes(new byte[] { 1, 2, 3, 4, 5, 6 });
        final ByteBufOutputStream out = new ByteBufOutputStream(buf, false);
        try {
            out.writeBoolean(true);
            out.writeBoolean(false);
            out.writeByte(42);
            out.writeByte(224);
            out.writeBytes("Hello, World!");
            out.write(new byte[]{1, 3, 3, 4}, 0, 0);
        } finally {
            out.close();
        }
        int i = ReferenceCountUtil.refCnt(out.buffer());
        assertEquals(1, i);

        // When releaseOnClose is not set or releaseOnClose is false, ByteBuf must be released manually.
        out.buffer().release();
        i = ReferenceCountUtil.refCnt(out.buffer());
        assertEquals(0, i);

Review comment (suggestion):
```suggestion
        assertEquals(0, out.buffer().refCnt());
```

Code after:
            });
        } finally {
            buf.release();
            in.close();
        }
    }

    @Test
    public void testReleaseOnCloseInByteBufOutputStream() throws Exception {
        ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer(16);
        buf.writeBytes(new byte[] { 1, 2, 3, 4, 5, 6 });
        final ByteBufOutputStream out = new ByteBufOutputStream(buf, true);
        try {
            out.writeBoolean(true);
            out.writeBoolean(false);
            out.writeByte(42);
            out.writeByte(224);
            out.writeBytes("Hello, World!");
            out.write(new byte[]{1, 3, 3, 4}, 0, 0);
        } finally {
            out.close();
        }
        // When releaseOnClose is set to true, ByteBuf will be automatically released after calling the close method of
        // ByteBufOutputStream.
        assertEquals(0, out.buffer().refCnt());
    }

    @Test
    public void testGeneralByteBufOutputStream() throws Exception {
        // case1
        ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer(16);
        buf.writeBytes(new byte[] { 1, 2, 3, 4, 5, 6 });
        final ByteBufOutputStream out = new ByteBufOutputStream(buf, false);
        try {
            out.writeBoolean(true);
            out.writeBoolean(false);
            out.writeByte(42);
            out.writeByte(224);
            out.writeBytes("Hello, World!");
            out.write(new byte[]{1, 3, 3, 4}, 0, 0);
        } finally {
            out.close();
        }
        assertEquals(1, out.buffer().refCnt());

        // When releaseOnClose is not set or releaseOnClose is false, ByteBuf must be released manually.
        out.buffer().release();
        assertEquals(0, out.buffer().refCnt());
    }
}