Fix resource leaks in ByteArrayEncoderTest

This commit is contained in:
Trustin Lee 2014-02-16 11:49:25 -08:00
parent 728417abd5
commit a0378af850

View File

@ -18,17 +18,16 @@ package io.netty.handler.codec.bytes;
import io.netty.buffer.ByteBuf;
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;
@ -38,18 +37,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 = ch.readOutbound();
assertThat(encoded, is(wrappedBuffer(b)));
encoded.release();
}
@Test
public void testEncodeEmpty() {
ch.writeOutbound(EmptyArrays.EMPTY_BYTES);
assertThat((ByteBuf) ch.readOutbound(), is(EMPTY_BUFFER));
assertThat((ByteBuf) ch.readOutbound(), is(sameInstance(EMPTY_BUFFER)));
}
@Test