From c4936fe9a73fd48bff4d5a911af153eb07a42a6b Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Sun, 16 Feb 2014 11:49:25 -0800 Subject: [PATCH] Fix resource leaks in ByteArrayEncoderTest --- .../codec/bytes/ByteArrayEncoderTest.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/codec/src/test/java/io/netty/handler/codec/bytes/ByteArrayEncoderTest.java b/codec/src/test/java/io/netty/handler/codec/bytes/ByteArrayEncoderTest.java index 9e46212819..608a2754b6 100644 --- a/codec/src/test/java/io/netty/handler/codec/bytes/ByteArrayEncoderTest.java +++ b/codec/src/test/java/io/netty/handler/codec/bytes/ByteArrayEncoderTest.java @@ -19,17 +19,16 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.util.internal.EmptyArrays; +import org.junit.After; import org.junit.Before; import org.junit.Test; import java.util.Random; import static io.netty.buffer.Unpooled.*; -import static org.hamcrest.core.Is.*; -import static org.hamcrest.core.IsNull.*; +import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; -@SuppressWarnings("ZeroLengthArrayAllocation") public class ByteArrayEncoderTest { private EmbeddedChannel ch; @@ -39,18 +38,25 @@ public class ByteArrayEncoderTest { ch = new EmbeddedChannel(new ByteArrayEncoder()); } + @After + public void tearDown() { + assertThat(ch.finish(), is(false)); + } + @Test public void testEncode() { byte[] b = new byte[2048]; new Random().nextBytes(b); ch.writeOutbound(b); - assertThat((ByteBuf) ch.readOutbound(), is(wrappedBuffer(b))); + ByteBuf encoded = (ByteBuf) ch.readOutbound(); + assertThat(encoded, is(wrappedBuffer(b))); + encoded.release(); } @Test public void testEncodeEmpty() { ch.writeOutbound(EmptyArrays.EMPTY_BYTES); - assertThat((ByteBuf) ch.readOutbound(), is(Unpooled.EMPTY_BUFFER)); + assertThat((ByteBuf) ch.readOutbound(), is(sameInstance(EMPTY_BUFFER))); } @Test