Fix resource leaks in ByteArrayEncoderTest
This commit is contained in:
parent
b1e7cefe32
commit
0b1acf35c9
@ -18,16 +18,16 @@ package io.netty.handler.codec.bytes;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import io.netty.util.internal.EmptyArrays;
|
import io.netty.util.internal.EmptyArrays;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static io.netty.buffer.Unpooled.*;
|
import static io.netty.buffer.Unpooled.*;
|
||||||
import static org.hamcrest.core.Is.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@SuppressWarnings("ZeroLengthArrayAllocation")
|
|
||||||
public class ByteArrayEncoderTest {
|
public class ByteArrayEncoderTest {
|
||||||
|
|
||||||
private EmbeddedChannel ch;
|
private EmbeddedChannel ch;
|
||||||
@ -37,18 +37,25 @@ public class ByteArrayEncoderTest {
|
|||||||
ch = new EmbeddedChannel(new ByteArrayEncoder());
|
ch = new EmbeddedChannel(new ByteArrayEncoder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
assertThat(ch.finish(), is(false));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncode() {
|
public void testEncode() {
|
||||||
byte[] b = new byte[2048];
|
byte[] b = new byte[2048];
|
||||||
new Random().nextBytes(b);
|
new Random().nextBytes(b);
|
||||||
ch.writeOutbound(b);
|
ch.writeOutbound(b);
|
||||||
assertThat((ByteBuf) ch.readOutbound(), is(wrappedBuffer(b)));
|
ByteBuf encoded = ch.readOutbound();
|
||||||
|
assertThat(encoded, is(wrappedBuffer(b)));
|
||||||
|
encoded.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeEmpty() {
|
public void testEncodeEmpty() {
|
||||||
ch.writeOutbound(EmptyArrays.EMPTY_BYTES);
|
ch.writeOutbound(EmptyArrays.EMPTY_BYTES);
|
||||||
assertThat((ByteBuf) ch.readOutbound(), is(EMPTY_BUFFER));
|
assertThat((ByteBuf) ch.readOutbound(), is(sameInstance(EMPTY_BUFFER)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user