Fix resource leaks in ByteArrayEncoderTest
This commit is contained in:
parent
04dab876b6
commit
c4936fe9a7
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user