Migrate codec to junit5 (#11426) (#11430)

Motivation:

We should update to use junit5 in all modules.

Modifications:

Adjust codec tests to use junit5

Result:

Part of https://github.com/netty/netty/issues/10757
This commit is contained in:
Norman Maurer 2021-06-30 14:12:50 +02:00 committed by GitHub
parent be606df4f0
commit 3716575102
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 20 deletions

View File

@ -21,13 +21,17 @@ import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.CharsetUtil;
import io.netty.util.ReferenceCountUtil;
import org.apache.commons.compress.utils.IOUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.io.IOException;
import java.util.Arrays;
import java.util.Queue;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class JdkZlibTest extends ZlibTest {
@ -42,10 +46,15 @@ public class JdkZlibTest extends ZlibTest {
return new JdkZlibDecoder(wrapper, maxAllocation);
}
@Test(expected = DecompressionException.class)
@Test
@Override
public void testZLIB_OR_NONE3() throws Exception {
super.testZLIB_OR_NONE3();
assertThrows(DecompressionException.class, new Executable() {
@Override
public void execute() throws Throwable {
JdkZlibTest.super.testZLIB_OR_NONE3();
}
});
}
@Test

View File

@ -15,7 +15,10 @@
*/
package io.netty.handler.codec.compression;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class ZlibCrossTest2 extends ZlibTest {
@ -29,9 +32,14 @@ public class ZlibCrossTest2 extends ZlibTest {
return new JdkZlibDecoder(wrapper, maxAllocation);
}
@Test(expected = DecompressionException.class)
@Test
@Override
public void testZLIB_OR_NONE3() throws Exception {
super.testZLIB_OR_NONE3();
assertThrows(DecompressionException.class, new Executable() {
@Override
public void execute() throws Throwable {
ZlibCrossTest2.super.testZLIB_OR_NONE3();
}
});
}
}

View File

@ -25,7 +25,8 @@ import io.netty.util.CharsetUtil;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.EmptyArrays;
import io.netty.util.internal.PlatformDependent;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -35,7 +36,11 @@ import java.util.zip.DeflaterOutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public abstract class ZlibTest {
@ -209,7 +214,7 @@ public abstract class ZlibTest {
buf.release();
decoded = true;
}
assertFalse("should decode nothing", decoded);
assertFalse(decoded, "should decode nothing");
assertFalse(chDecoderZlib.finish());
} finally {
@ -366,19 +371,20 @@ public abstract class ZlibTest {
public void testMaxAllocation() throws Exception {
int maxAllocation = 1024;
ZlibDecoder decoder = createDecoder(ZlibWrapper.ZLIB, maxAllocation);
EmbeddedChannel chDecoder = new EmbeddedChannel(decoder);
final EmbeddedChannel chDecoder = new EmbeddedChannel(decoder);
TestByteBufAllocator alloc = new TestByteBufAllocator(chDecoder.alloc());
chDecoder.config().setAllocator(alloc);
try {
chDecoder.writeInbound(Unpooled.wrappedBuffer(deflate(BYTES_LARGE)));
fail("decompressed size > maxAllocation, so should have thrown exception");
} catch (DecompressionException e) {
assertTrue(e.getMessage().startsWith("Decompression buffer has reached maximum size"));
assertEquals(maxAllocation, alloc.getMaxAllocation());
assertTrue(decoder.isClosed());
assertFalse(chDecoder.finish());
}
DecompressionException e = assertThrows(DecompressionException.class, new Executable() {
@Override
public void execute() throws Throwable {
chDecoder.writeInbound(Unpooled.wrappedBuffer(deflate(BYTES_LARGE)));
}
});
assertTrue(e.getMessage().startsWith("Decompression buffer has reached maximum size"));
assertEquals(maxAllocation, alloc.getMaxAllocation());
assertTrue(decoder.isClosed());
assertFalse(chDecoder.finish());
}
private static byte[] gzip(byte[] bytes) throws IOException {