diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/CombinedHttpHeadersTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/CombinedHttpHeadersTest.java index 06d0e0405e..4aa78227f6 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/CombinedHttpHeadersTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/CombinedHttpHeadersTest.java @@ -16,7 +16,7 @@ package io.netty.handler.codec.http; import io.netty.handler.codec.http.HttpHeadersTestUtils.HeaderValue; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; @@ -26,9 +26,10 @@ import static io.netty.handler.codec.http.HttpHeaderNames.SET_COOKIE; import static io.netty.util.AsciiString.contentEquals; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +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 CombinedHttpHeadersTest { private static final CharSequence HEADER_NAME = "testHeader"; @@ -140,11 +141,11 @@ public class CombinedHttpHeadersTest { assertEquals(HeaderValue.EIGHT.subset(6), headers.getAll(HEADER_NAME)); } - @Test (expected = NullPointerException.class) + @Test public void addCharSequencesCsvNullValue() { final CombinedHttpHeaders headers = newCombinedHttpHeaders(); final String value = null; - headers.add(HEADER_NAME, value); + assertThrows(NullPointerException.class, () -> headers.add(HEADER_NAME, value)); } @Test diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpHeadersTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpHeadersTest.java index fdbbaf6770..37a8bb747c 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpHeadersTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpHeadersTest.java @@ -18,7 +18,7 @@ package io.netty.handler.codec.http; import io.netty.handler.codec.http.HttpHeadersTestUtils.HeaderValue; import io.netty.util.AsciiString; import io.netty.util.internal.StringUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Iterator; @@ -30,19 +30,25 @@ import static io.netty.util.AsciiString.contentEquals; import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class DefaultHttpHeadersTest { private static final CharSequence HEADER_NAME = "testHeader"; - @Test(expected = IllegalArgumentException.class) + @Test public void nullHeaderNameNotAllowed() { - new DefaultHttpHeaders().add(null, "foo"); + assertThrows(IllegalArgumentException.class, () -> new DefaultHttpHeaders().add(null, "foo")); } - @Test(expected = IllegalArgumentException.class) + @Test public void emptyHeaderNameNotAllowed() { - new DefaultHttpHeaders().add(StringUtil.EMPTY_STRING, "foo"); + assertThrows(IllegalArgumentException.class, + () -> new DefaultHttpHeaders().add(StringUtil.EMPTY_STRING, "foo")); } @Test @@ -146,16 +152,16 @@ public class DefaultHttpHeadersTest { assertThat(AsciiString.contentEqualsIgnoreCase("FoO", "fOo"), is(true)); } - @Test(expected = NullPointerException.class) + @Test public void testSetNullHeaderValueValidate() { HttpHeaders headers = new DefaultHttpHeaders(true); - headers.set(of("test"), (CharSequence) null); + assertThrows(NullPointerException.class, () -> headers.set(of("test"), (CharSequence) null)); } - @Test(expected = NullPointerException.class) + @Test public void testSetNullHeaderValueNotValidate() { HttpHeaders headers = new DefaultHttpHeaders(false); - headers.set(of("test"), (CharSequence) null); + assertThrows(NullPointerException.class, () -> headers.set(of("test"), (CharSequence) null)); } @Test diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpRequestTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpRequestTest.java index fe35ba961e..9ddb597ae9 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpRequestTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpRequestTest.java @@ -16,11 +16,11 @@ package io.netty.handler.codec.http; import io.netty.util.AsciiString; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static io.netty.handler.codec.http.HttpHeadersTestUtils.of; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class DefaultHttpRequestTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpResponseTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpResponseTest.java index ef4a963f49..a713059864 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpResponseTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpResponseTest.java @@ -15,10 +15,10 @@ */ package io.netty.handler.codec.http; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class DefaultHttpResponseTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpChunkedInputTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpChunkedInputTest.java index 7a2d1452f2..c0904c15a4 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpChunkedInputTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpChunkedInputTest.java @@ -26,7 +26,7 @@ import io.netty.handler.stream.ChunkedNioStream; import io.netty.handler.stream.ChunkedStream; import io.netty.handler.stream.ChunkedWriteHandler; import io.netty.util.internal.PlatformDependent; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.File; @@ -34,7 +34,10 @@ import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.Channels; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; public class HttpChunkedInputTest { private static final byte[] BYTES = new byte[1024 * 64]; @@ -139,7 +142,7 @@ public class HttpChunkedInputTest { break; } if (lastHttpContent != null) { - assertTrue("Chunk must be DefaultHttpContent", lastHttpContent instanceof DefaultHttpContent); + assertTrue(lastHttpContent instanceof DefaultHttpContent, "Chunk must be DefaultHttpContent"); } ByteBuf buffer = httpContent.content(); @@ -157,7 +160,7 @@ public class HttpChunkedInputTest { } assertEquals(BYTES.length * inputs.length, read); - assertSame("Last chunk must be LastHttpContent.EMPTY_LAST_CONTENT", - LastHttpContent.EMPTY_LAST_CONTENT, lastHttpContent); + assertSame(LastHttpContent.EMPTY_LAST_CONTENT, lastHttpContent, + "Last chunk must be LastHttpContent.EMPTY_LAST_CONTENT"); } } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java index 145ab425d8..9ef5716070 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java @@ -37,7 +37,7 @@ import io.netty.handler.codec.PrematureChannelClosureException; import io.netty.util.CharsetUtil; import io.netty.util.NetUtil; import org.hamcrest.CoreMatchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.InetSocketAddress; import java.util.concurrent.CountDownLatch; @@ -47,7 +47,11 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class HttpClientCodecTest { @@ -213,7 +217,7 @@ public class HttpClientCodecTest { Consumer connectResponseConsumer = new Consumer(); sendRequestAndReadResponse(ch, HttpMethod.CONNECT, EMPTY_RESPONSE, connectResponseConsumer); - assertTrue("No connect response messages received.", connectResponseConsumer.getReceivedCount() > 0); + assertTrue(connectResponseConsumer.getReceivedCount() > 0, "No connect response messages received."); Consumer responseConsumer = new Consumer() { @Override void accept(Object object) { @@ -225,8 +229,8 @@ public class HttpClientCodecTest { } }; sendRequestAndReadResponse(ch, HttpMethod.GET, RESPONSE, responseConsumer); - assertTrue("No response messages received.", responseConsumer.getReceivedCount() > 0); - assertFalse("Channel finish failed.", ch.finish()); + assertTrue(responseConsumer.getReceivedCount() > 0, "No response messages received."); + assertFalse(ch.finish(), "Channel finish failed."); } private static void sendRequestAndReadResponse(EmbeddedChannel ch, HttpMethod httpMethod, String response) { @@ -235,10 +239,10 @@ public class HttpClientCodecTest { private static void sendRequestAndReadResponse(EmbeddedChannel ch, HttpMethod httpMethod, String response, Consumer responseConsumer) { - assertTrue("Channel outbound write failed.", - ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, httpMethod, "http://localhost/"))); - assertTrue("Channel inbound write failed.", - ch.writeInbound(Unpooled.copiedBuffer(response, CharsetUtil.ISO_8859_1))); + assertTrue(ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, httpMethod, "http://localhost/")), + "Channel outbound write failed."); + assertTrue(ch.writeInbound(Unpooled.copiedBuffer(response, CharsetUtil.ISO_8859_1)), + "Channel inbound write failed."); for (;;) { Object msg = ch.readOutbound(); @@ -287,22 +291,22 @@ public class HttpClientCodecTest { HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"); request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE); request.headers().set(HttpHeaderNames.UPGRADE, "TLS/1.2"); - assertTrue("Channel outbound write failed.", ch.writeOutbound(request)); + assertTrue(ch.writeOutbound(request), "Channel outbound write failed."); - assertTrue("Channel inbound write failed.", - ch.writeInbound(Unpooled.copiedBuffer(SWITCHING_PROTOCOLS_RESPONSE, CharsetUtil.ISO_8859_1))); + assertTrue(ch.writeInbound(Unpooled.copiedBuffer(SWITCHING_PROTOCOLS_RESPONSE, CharsetUtil.ISO_8859_1)), + "Channel inbound write failed."); Object switchingProtocolsResponse = ch.readInbound(); - assertNotNull("No response received", switchingProtocolsResponse); + assertNotNull(switchingProtocolsResponse, "No response received"); assertThat("Response was not decoded", switchingProtocolsResponse, instanceOf(FullHttpResponse.class)); ((FullHttpResponse) switchingProtocolsResponse).release(); - assertTrue("Channel inbound write failed", - ch.writeInbound(Unpooled.copiedBuffer(RESPONSE, CharsetUtil.ISO_8859_1))); + assertTrue(ch.writeInbound(Unpooled.copiedBuffer(RESPONSE, CharsetUtil.ISO_8859_1)), + "Channel inbound write failed"); Object finalResponse = ch.readInbound(); - assertNotNull("No response received", finalResponse); + assertNotNull(finalResponse, "No response received"); assertThat("Response was not decoded", finalResponse, instanceOf(FullHttpResponse.class)); ((FullHttpResponse) finalResponse).release(); - assertTrue("Channel finish failed", ch.finishAndReleaseAll()); + assertTrue(ch.finishAndReleaseAll(), "Channel finish failed"); } @Test diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientUpgradeHandlerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientUpgradeHandlerTest.java index 40d910093f..dde84466cc 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientUpgradeHandlerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientUpgradeHandlerTest.java @@ -23,12 +23,12 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +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.assertTrue; public class HttpClientUpgradeHandlerTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java index 901e424dd6..a5d52d4ccc 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java @@ -24,7 +24,7 @@ import io.netty.handler.codec.EncoderException; import io.netty.handler.codec.compression.ZlibWrapper; import io.netty.util.CharsetUtil; import io.netty.util.ReferenceCountUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static io.netty.handler.codec.http.HttpHeadersTestUtils.of; import static org.hamcrest.CoreMatchers.instanceOf; @@ -32,11 +32,11 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class HttpContentCompressorTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecoderTest.java index 4c9b02868d..5c8956e598 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecoderTest.java @@ -32,8 +32,7 @@ import io.netty.util.CharsetUtil; import io.netty.util.ReferenceCountUtil; import io.netty.util.internal.PlatformDependent; import org.apache.commons.io.IOUtils; -import org.junit.Assume; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.InputStream; import java.util.ArrayList; @@ -45,7 +44,13 @@ import java.util.concurrent.atomic.AtomicReference; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assumptions.assumeFalse; public class HttpContentDecoderTest { private static final String HELLO_WORLD = "hello, world"; @@ -191,7 +196,7 @@ public class HttpContentDecoderTest { public void testResponseBrotliDecompression() throws Throwable { Brotli.ensureAvailability(); // Failing on windows atm - Assume.assumeFalse(PlatformDependent.isWindows()); + assumeFalse(PlatformDependent.isWindows()); HttpResponseDecoder decoder = new HttpResponseDecoder(); HttpContentDecoder decompressor = new HttpContentDecompressor(); HttpObjectAggregator aggregator = new HttpObjectAggregator(Integer.MAX_VALUE); @@ -207,13 +212,12 @@ public class HttpContentDecoderTest { Object o = channel.readInbound(); assertThat(o, is(instanceOf(FullHttpResponse.class))); FullHttpResponse resp = (FullHttpResponse) o; - assertNull("Content-Encoding header should be removed", resp.headers().get(HttpHeaderNames.CONTENT_ENCODING)); - assertEquals("Content-Length header should match uncompressed string's length", - SAMPLE_STRING.length(), - resp.headers().getInt(HttpHeaderNames.CONTENT_LENGTH).intValue()); - assertEquals("Response body should match uncompressed string", - SAMPLE_STRING, - resp.content().toString(CharsetUtil.UTF_8)); + assertNull(resp.headers().get(HttpHeaderNames.CONTENT_ENCODING), "Content-Encoding header should be removed"); + assertEquals(SAMPLE_STRING.length(), + resp.headers().getInt(HttpHeaderNames.CONTENT_LENGTH).intValue(), + "Content-Length header should match uncompressed string's length"); + assertEquals(SAMPLE_STRING, resp.content().toString(CharsetUtil.UTF_8), + "Response body should match uncompressed string"); resp.release(); assertHasInboundMessages(channel, false); @@ -225,7 +229,7 @@ public class HttpContentDecoderTest { public void testResponseChunksBrotliDecompression() throws Throwable { Brotli.ensureAvailability(); // Failing on windows atm - Assume.assumeFalse(PlatformDependent.isWindows()); + assumeFalse(PlatformDependent.isWindows()); HttpResponseDecoder decoder = new HttpResponseDecoder(); HttpContentDecoder decompressor = new HttpContentDecompressor(); HttpObjectAggregator aggregator = new HttpObjectAggregator(Integer.MAX_VALUE); @@ -253,12 +257,11 @@ public class HttpContentDecoderTest { Object o = channel.readInbound(); assertThat(o, is(instanceOf(FullHttpResponse.class))); FullHttpResponse resp = (FullHttpResponse) o; - assertEquals("Content-Length header should match uncompressed string's length", - SAMPLE_STRING.length(), - resp.headers().getInt(HttpHeaderNames.CONTENT_LENGTH).intValue()); - assertEquals("Response body should match uncompressed string", - SAMPLE_STRING, - resp.content().toString(CharsetUtil.UTF_8)); + assertEquals(SAMPLE_STRING.length(), + resp.headers().getInt(HttpHeaderNames.CONTENT_LENGTH).intValue(), + "Content-Length header should match uncompressed string's length"); + assertEquals(SAMPLE_STRING, resp.content().toString(CharsetUtil.UTF_8), + "Response body should match uncompressed string"); resp.release(); assertHasInboundMessages(channel, false); @@ -511,11 +514,11 @@ public class HttpContentDecoderTest { assertThat(o, is(instanceOf(HttpResponse.class))); HttpResponse r = (HttpResponse) o; - assertFalse("Content-Length header not removed.", r.headers().contains(HttpHeaderNames.CONTENT_LENGTH)); + assertFalse(r.headers().contains(HttpHeaderNames.CONTENT_LENGTH), "Content-Length header not removed."); String transferEncoding = r.headers().get(HttpHeaderNames.TRANSFER_ENCODING); - assertNotNull("Content-length as well as transfer-encoding not set.", transferEncoding); - assertEquals("Unexpected transfer-encoding value.", HttpHeaderValues.CHUNKED.toString(), transferEncoding); + assertNotNull(transferEncoding, "Content-length as well as transfer-encoding not set."); + assertEquals(HttpHeaderValues.CHUNKED.toString(), transferEncoding, "Unexpected transfer-encoding value."); assertHasInboundMessages(channel, true); assertHasOutboundMessages(channel, false); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecompressorTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecompressorTest.java index cfe16cd8e1..557ee17ba1 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecompressorTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecompressorTest.java @@ -18,13 +18,15 @@ package io.netty.handler.codec.http; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; - import io.netty.channel.embedded.EmbeddedChannel; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.atomic.AtomicInteger; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class HttpContentDecompressorTest { // See https://github.com/netty/netty/issues/8915. @@ -53,18 +55,18 @@ public class HttpContentDecompressorTest { response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/json;charset=UTF-8"); response.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED); - Assert.assertTrue(channel.writeInbound(response)); + assertTrue(channel.writeInbound(response)); // we triggered read explicitly - Assert.assertEquals(1, readCalled.get()); + assertEquals(1, readCalled.get()); - Assert.assertTrue(channel.readInbound() instanceof HttpResponse); + assertTrue(channel.readInbound() instanceof HttpResponse); - Assert.assertFalse(channel.writeInbound(new DefaultHttpContent(Unpooled.EMPTY_BUFFER))); + assertFalse(channel.writeInbound(new DefaultHttpContent(Unpooled.EMPTY_BUFFER))); // read was triggered by the HttpContentDecompressor itself as it did not produce any message to the next // inbound handler. - Assert.assertEquals(2, readCalled.get()); - Assert.assertFalse(channel.finishAndReleaseAll()); + assertEquals(2, readCalled.get()); + assertFalse(channel.finishAndReleaseAll()); } } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentEncoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentEncoderTest.java index fcaee0405d..7d2a8202c1 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentEncoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentEncoderTest.java @@ -36,7 +36,11 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class HttpContentEncoderTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeadersTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeadersTest.java index c20dc53919..e7134d5a2e 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeadersTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeadersTest.java @@ -16,16 +16,17 @@ package io.netty.handler.codec.http; import io.netty.util.AsciiString; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; import static io.netty.handler.codec.http.HttpHeadersTestUtils.of; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +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 HttpHeadersTest { @@ -61,22 +62,22 @@ public class HttpHeadersTest { assertThat(AsciiString.contentEqualsIgnoreCase("FoO", "fOo"), is(true)); } - @Test(expected = NullPointerException.class) + @Test public void testSetNullHeaderValueValidate() { HttpHeaders headers = new DefaultHttpHeaders(true); - headers.set(of("test"), (CharSequence) null); + assertThrows(NullPointerException.class, () -> headers.set(of("test"), (CharSequence) null)); } - @Test(expected = NullPointerException.class) + @Test public void testSetNullHeaderValueNotValidate() { HttpHeaders headers = new DefaultHttpHeaders(false); - headers.set(of("test"), (CharSequence) null); + assertThrows(NullPointerException.class, () -> headers.set(of("test"), (CharSequence) null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testAddSelf() { HttpHeaders headers = new DefaultHttpHeaders(false); - headers.add(headers); + assertThrows(IllegalArgumentException.class, () -> headers.add(headers)); } @Test diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpInvalidMessageTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpInvalidMessageTest.java index ee33dbcd25..a063384e7d 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpInvalidMessageTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpInvalidMessageTest.java @@ -25,10 +25,10 @@ import org.junit.Test; import java.util.Random; import static io.netty.handler.codec.http.HttpHeadersTestUtils.of; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +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.assertTrue; public class HttpInvalidMessageTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpObjectAggregatorTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpObjectAggregatorTest.java index a2c4ce6517..a11ab4fac6 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpObjectAggregatorTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpObjectAggregatorTest.java @@ -37,14 +37,14 @@ import static io.netty.handler.codec.http.HttpHeadersTestUtils.of; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class HttpObjectAggregatorTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java index 3e15abe5a3..1ca2e1d6b4 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java @@ -31,11 +31,11 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class HttpRequestDecoderTest { private static final byte[] CONTENT_CRLF_DELIMITERS = createContent("\r\n"); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestEncoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestEncoderTest.java index 6bd6415a35..4d2b10d6de 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestEncoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestEncoderTest.java @@ -31,7 +31,10 @@ import java.util.concurrent.ExecutionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; -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.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** */ diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseDecoderTest.java index 9f2f07e3ac..8ad4066583 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseDecoderTest.java @@ -21,7 +21,7 @@ import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.codec.PrematureChannelClosureException; import io.netty.handler.codec.TooLongFrameException; import io.netty.util.CharsetUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; @@ -33,11 +33,11 @@ import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +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.assertTrue; public class HttpResponseDecoderTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseEncoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseEncoderTest.java index cc531ab404..09338489d7 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseEncoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseEncoderTest.java @@ -20,14 +20,17 @@ import io.netty.buffer.Unpooled; import io.netty.channel.FileRegion; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.util.CharsetUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.channels.WritableByteChannel; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -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.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; public class HttpResponseEncoderTest { private static final long INTEGER_OVERFLOW = (long) Integer.MAX_VALUE + 1; diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseStatusTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseStatusTest.java index c16778bcb2..f190dbd807 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseStatusTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseStatusTest.java @@ -16,11 +16,12 @@ package io.netty.handler.codec.http; import io.netty.util.AsciiString; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static io.netty.handler.codec.http.HttpResponseStatus.parseLine; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; public class HttpResponseStatusTest { @Test @@ -46,14 +47,14 @@ public class HttpResponseStatusTest { assertEquals("FOO", customStatus.reasonPhrase()); } - @Test(expected = IllegalArgumentException.class) + @Test public void parseLineStringMalformedCode() { - parseLine("200a"); + assertThrows(IllegalArgumentException.class, () -> parseLine("200a")); } - @Test(expected = IllegalArgumentException.class) + @Test public void parseLineStringMalformedCodeWithPhrase() { - parseLine("200a foo"); + assertThrows(IllegalArgumentException.class, () -> parseLine("200a foo")); } @Test @@ -79,13 +80,13 @@ public class HttpResponseStatusTest { assertEquals("FOO", customStatus.reasonPhrase()); } - @Test(expected = IllegalArgumentException.class) + @Test public void parseLineAsciiStringMalformedCode() { - parseLine(new AsciiString("200a")); + assertThrows(IllegalArgumentException.class, () -> parseLine(new AsciiString("200a"))); } - @Test(expected = IllegalArgumentException.class) + @Test public void parseLineAsciiStringMalformedCodeWithPhrase() { - parseLine(new AsciiString("200a foo")); + assertThrows(IllegalArgumentException.class, () -> parseLine(new AsciiString("200a foo"))); } } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerCodecTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerCodecTest.java index 144362d5ec..0ffdc9b744 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerCodecTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerCodecTest.java @@ -19,11 +19,14 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.util.CharsetUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class HttpServerCodecTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerExpectContinueHandlerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerExpectContinueHandlerTest.java index 8f72e17875..d0c198c2d1 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerExpectContinueHandlerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerExpectContinueHandlerTest.java @@ -21,7 +21,8 @@ import org.junit.Test; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class HttpServerExpectContinueHandlerTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerKeepAliveHandlerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerKeepAliveHandlerTest.java index 9f48389de4..c7d576d63d 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerKeepAliveHandlerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerKeepAliveHandlerTest.java @@ -37,9 +37,9 @@ import static io.netty.handler.codec.http.HttpUtil.isKeepAlive; import static io.netty.handler.codec.http.HttpUtil.setContentLength; import static io.netty.handler.codec.http.HttpUtil.setKeepAlive; import static io.netty.handler.codec.http.HttpUtil.setTransferEncodingChunked; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; @RunWith(Parameterized.class) public class HttpServerKeepAliveHandlerTest { @@ -111,8 +111,8 @@ public class HttpServerKeepAliveHandlerTest { channel.writeAndFlush(response); HttpResponse writtenResponse = channel.readOutbound(); - assertEquals("channel.isOpen", isKeepAliveResponseExpected, channel.isOpen()); - assertEquals("response keep-alive", isKeepAliveResponseExpected, isKeepAlive(writtenResponse)); + assertEquals(isKeepAliveResponseExpected, channel.isOpen(), "channel.isOpen"); + assertEquals(isKeepAliveResponseExpected, isKeepAlive(writtenResponse), "response keep-alive"); ReferenceCountUtil.release(writtenResponse); assertFalse(channel.finishAndReleaseAll()); } @@ -167,8 +167,8 @@ public class HttpServerKeepAliveHandlerTest { channel.writeAndFlush(response.retainedDuplicate()); HttpResponse firstResponse = channel.readOutbound(); - assertTrue("channel.isOpen", channel.isOpen()); - assertTrue("response keep-alive", isKeepAlive(firstResponse)); + assertTrue(channel.isOpen(), "channel.isOpen"); + assertTrue(isKeepAlive(firstResponse), "response keep-alive"); ReferenceCountUtil.release(firstResponse); requestForwarded = channel.readInbound(); @@ -177,8 +177,8 @@ public class HttpServerKeepAliveHandlerTest { channel.writeAndFlush(informationalResp); HttpResponse writtenInfoResp = channel.readOutbound(); - assertTrue("channel.isOpen", channel.isOpen()); - assertTrue("response keep-alive", isKeepAlive(writtenInfoResp)); + assertTrue(channel.isOpen(), "channel.isOpen"); + assertTrue(isKeepAlive(writtenInfoResp), "response keep-alive"); ReferenceCountUtil.release(writtenInfoResp); if (!StringUtil.isNullOrEmpty(setResponseConnection)) { @@ -189,8 +189,8 @@ public class HttpServerKeepAliveHandlerTest { setupMessageLength(response); channel.writeAndFlush(response.retainedDuplicate()); HttpResponse secondResponse = channel.readOutbound(); - assertEquals("channel.isOpen", isKeepAliveResponseExpected, channel.isOpen()); - assertEquals("response keep-alive", isKeepAliveResponseExpected, isKeepAlive(secondResponse)); + assertEquals(isKeepAliveResponseExpected, channel.isOpen(), "channel.isOpen"); + assertEquals(isKeepAliveResponseExpected, isKeepAlive(secondResponse), "response keep-alive"); ReferenceCountUtil.release(secondResponse); requestForwarded = channel.readInbound(); @@ -200,8 +200,8 @@ public class HttpServerKeepAliveHandlerTest { if (isKeepAliveResponseExpected) { channel.writeAndFlush(response); HttpResponse finalResponse = channel.readOutbound(); - assertFalse("channel.isOpen", channel.isOpen()); - assertFalse("response keep-alive", isKeepAlive(finalResponse)); + assertFalse(channel.isOpen(), "channel.isOpen"); + assertFalse(isKeepAlive(finalResponse), "response keep-alive"); } ReferenceCountUtil.release(response); assertFalse(channel.finishAndReleaseAll()); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerUpgradeHandlerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerUpgradeHandlerTest.java index da773f6f42..3f8baf0114 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerUpgradeHandlerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerUpgradeHandlerTest.java @@ -31,7 +31,12 @@ import io.netty.handler.codec.http.HttpServerUpgradeHandler.UpgradeCodec; import io.netty.handler.codec.http.HttpServerUpgradeHandler.UpgradeCodecFactory; import io.netty.util.CharsetUtil; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class HttpServerUpgradeHandlerTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpUtilTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpUtilTest.java index 59dcdfef9a..e8fd49d994 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpUtilTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpUtilTest.java @@ -27,11 +27,11 @@ import io.netty.util.ReferenceCountUtil; import org.junit.Test; import static io.netty.handler.codec.http.HttpHeadersTestUtils.of; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +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.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class HttpUtilTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringDecoderTest.java index a19e66abc8..24324cd8c7 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringDecoderTest.java @@ -16,8 +16,7 @@ package io.netty.handler.codec.http; import io.netty.util.CharsetUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.URI; import java.net.URISyntaxException; @@ -26,12 +25,17 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class QueryStringDecoderTest { @Test public void testBasicUris() throws URISyntaxException { QueryStringDecoder d = new QueryStringDecoder(new URI("http://localhost/path")); - Assert.assertEquals(0, d.parameters().size()); + assertEquals(0, d.parameters().size()); } @Test @@ -39,68 +43,68 @@ public class QueryStringDecoderTest { QueryStringDecoder d; d = new QueryStringDecoder("/foo"); - Assert.assertEquals("/foo", d.path()); - Assert.assertEquals(0, d.parameters().size()); + assertEquals("/foo", d.path()); + assertEquals(0, d.parameters().size()); d = new QueryStringDecoder("/foo%20bar"); - Assert.assertEquals("/foo bar", d.path()); - Assert.assertEquals(0, d.parameters().size()); + assertEquals("/foo bar", d.path()); + assertEquals(0, d.parameters().size()); d = new QueryStringDecoder("/foo?a=b=c"); - Assert.assertEquals("/foo", d.path()); - Assert.assertEquals(1, d.parameters().size()); - Assert.assertEquals(1, d.parameters().get("a").size()); - Assert.assertEquals("b=c", d.parameters().get("a").get(0)); + assertEquals("/foo", d.path()); + assertEquals(1, d.parameters().size()); + assertEquals(1, d.parameters().get("a").size()); + assertEquals("b=c", d.parameters().get("a").get(0)); d = new QueryStringDecoder("/foo?a=1&a=2"); - Assert.assertEquals("/foo", d.path()); - Assert.assertEquals(1, d.parameters().size()); - Assert.assertEquals(2, d.parameters().get("a").size()); - Assert.assertEquals("1", d.parameters().get("a").get(0)); - Assert.assertEquals("2", d.parameters().get("a").get(1)); + assertEquals("/foo", d.path()); + assertEquals(1, d.parameters().size()); + assertEquals(2, d.parameters().get("a").size()); + assertEquals("1", d.parameters().get("a").get(0)); + assertEquals("2", d.parameters().get("a").get(1)); d = new QueryStringDecoder("/foo%20bar?a=1&a=2"); - Assert.assertEquals("/foo bar", d.path()); - Assert.assertEquals(1, d.parameters().size()); - Assert.assertEquals(2, d.parameters().get("a").size()); - Assert.assertEquals("1", d.parameters().get("a").get(0)); - Assert.assertEquals("2", d.parameters().get("a").get(1)); + assertEquals("/foo bar", d.path()); + assertEquals(1, d.parameters().size()); + assertEquals(2, d.parameters().get("a").size()); + assertEquals("1", d.parameters().get("a").get(0)); + assertEquals("2", d.parameters().get("a").get(1)); d = new QueryStringDecoder("/foo?a=&a=2"); - Assert.assertEquals("/foo", d.path()); - Assert.assertEquals(1, d.parameters().size()); - Assert.assertEquals(2, d.parameters().get("a").size()); - Assert.assertEquals("", d.parameters().get("a").get(0)); - Assert.assertEquals("2", d.parameters().get("a").get(1)); + assertEquals("/foo", d.path()); + assertEquals(1, d.parameters().size()); + assertEquals(2, d.parameters().get("a").size()); + assertEquals("", d.parameters().get("a").get(0)); + assertEquals("2", d.parameters().get("a").get(1)); d = new QueryStringDecoder("/foo?a=1&a="); - Assert.assertEquals("/foo", d.path()); - Assert.assertEquals(1, d.parameters().size()); - Assert.assertEquals(2, d.parameters().get("a").size()); - Assert.assertEquals("1", d.parameters().get("a").get(0)); - Assert.assertEquals("", d.parameters().get("a").get(1)); + assertEquals("/foo", d.path()); + assertEquals(1, d.parameters().size()); + assertEquals(2, d.parameters().get("a").size()); + assertEquals("1", d.parameters().get("a").get(0)); + assertEquals("", d.parameters().get("a").get(1)); d = new QueryStringDecoder("/foo?a=1&a=&a="); - Assert.assertEquals("/foo", d.path()); - Assert.assertEquals(1, d.parameters().size()); - Assert.assertEquals(3, d.parameters().get("a").size()); - Assert.assertEquals("1", d.parameters().get("a").get(0)); - Assert.assertEquals("", d.parameters().get("a").get(1)); - Assert.assertEquals("", d.parameters().get("a").get(2)); + assertEquals("/foo", d.path()); + assertEquals(1, d.parameters().size()); + assertEquals(3, d.parameters().get("a").size()); + assertEquals("1", d.parameters().get("a").get(0)); + assertEquals("", d.parameters().get("a").get(1)); + assertEquals("", d.parameters().get("a").get(2)); d = new QueryStringDecoder("/foo?a=1=&a==2"); - Assert.assertEquals("/foo", d.path()); - Assert.assertEquals(1, d.parameters().size()); - Assert.assertEquals(2, d.parameters().get("a").size()); - Assert.assertEquals("1=", d.parameters().get("a").get(0)); - Assert.assertEquals("=2", d.parameters().get("a").get(1)); + assertEquals("/foo", d.path()); + assertEquals(1, d.parameters().size()); + assertEquals(2, d.parameters().get("a").size()); + assertEquals("1=", d.parameters().get("a").get(0)); + assertEquals("=2", d.parameters().get("a").get(1)); d = new QueryStringDecoder("/foo?abc=1%2023&abc=124%20"); - Assert.assertEquals("/foo", d.path()); - Assert.assertEquals(1, d.parameters().size()); - Assert.assertEquals(2, d.parameters().get("abc").size()); - Assert.assertEquals("1 23", d.parameters().get("abc").get(0)); - Assert.assertEquals("124 ", d.parameters().get("abc").get(1)); + assertEquals("/foo", d.path()); + assertEquals(1, d.parameters().size()); + assertEquals(2, d.parameters().get("abc").size()); + assertEquals("1 23", d.parameters().get("abc").get(0)); + assertEquals("124 ", d.parameters().get("abc").get(1)); } @Test @@ -139,32 +143,32 @@ public class QueryStringDecoderTest { @Test public void testPathSpecific() { // decode escaped characters - Assert.assertEquals("/foo bar/", new QueryStringDecoder("/foo%20bar/?").path()); - Assert.assertEquals("/foo\r\n\\bar/", new QueryStringDecoder("/foo%0D%0A\\bar/?").path()); + assertEquals("/foo bar/", new QueryStringDecoder("/foo%20bar/?").path()); + assertEquals("/foo\r\n\\bar/", new QueryStringDecoder("/foo%0D%0A\\bar/?").path()); // a 'fragment' after '#' should be cuted (see RFC 3986) - Assert.assertEquals("", new QueryStringDecoder("#123").path()); - Assert.assertEquals("foo", new QueryStringDecoder("foo?bar#anchor").path()); - Assert.assertEquals("/foo-bar", new QueryStringDecoder("/foo-bar#anchor").path()); - Assert.assertEquals("/foo-bar", new QueryStringDecoder("/foo-bar#a#b?c=d").path()); + assertEquals("", new QueryStringDecoder("#123").path()); + assertEquals("foo", new QueryStringDecoder("foo?bar#anchor").path()); + assertEquals("/foo-bar", new QueryStringDecoder("/foo-bar#anchor").path()); + assertEquals("/foo-bar", new QueryStringDecoder("/foo-bar#a#b?c=d").path()); // '+' is not escape ' ' for the path - Assert.assertEquals("+", new QueryStringDecoder("+").path()); - Assert.assertEquals("/foo+bar/", new QueryStringDecoder("/foo+bar/?").path()); - Assert.assertEquals("/foo++", new QueryStringDecoder("/foo++?index.php").path()); - Assert.assertEquals("/foo +", new QueryStringDecoder("/foo%20+?index.php").path()); - Assert.assertEquals("/foo+ ", new QueryStringDecoder("/foo+%20").path()); + assertEquals("+", new QueryStringDecoder("+").path()); + assertEquals("/foo+bar/", new QueryStringDecoder("/foo+bar/?").path()); + assertEquals("/foo++", new QueryStringDecoder("/foo++?index.php").path()); + assertEquals("/foo +", new QueryStringDecoder("/foo%20+?index.php").path()); + assertEquals("/foo+ ", new QueryStringDecoder("/foo+%20").path()); } @Test public void testExcludeFragment() { // a 'fragment' after '#' should be cuted (see RFC 3986) - Assert.assertEquals("a", new QueryStringDecoder("?a#anchor").parameters().keySet().iterator().next()); - Assert.assertEquals("b", new QueryStringDecoder("?a=b#anchor").parameters().get("a").get(0)); - Assert.assertTrue(new QueryStringDecoder("?#").parameters().isEmpty()); - Assert.assertTrue(new QueryStringDecoder("?#anchor").parameters().isEmpty()); - Assert.assertTrue(new QueryStringDecoder("#?a=b#anchor").parameters().isEmpty()); - Assert.assertTrue(new QueryStringDecoder("?#a=b#anchor").parameters().isEmpty()); + assertEquals("a", new QueryStringDecoder("?a#anchor").parameters().keySet().iterator().next()); + assertEquals("b", new QueryStringDecoder("?a=b#anchor").parameters().get("a").get(0)); + assertTrue(new QueryStringDecoder("?#").parameters().isEmpty()); + assertTrue(new QueryStringDecoder("?#anchor").parameters().isEmpty()); + assertTrue(new QueryStringDecoder("#?a=b#anchor").parameters().isEmpty()); + assertTrue(new QueryStringDecoder("?#a=b#anchor").parameters().isEmpty()); } @Test @@ -178,20 +182,20 @@ public class QueryStringDecoderTest { buf.append(i); buf.append('&'); } - Assert.assertEquals(1024, new QueryStringDecoder(buf.toString()).parameters().size()); + assertEquals(1024, new QueryStringDecoder(buf.toString()).parameters().size()); } @Test public void testHasPath() { QueryStringDecoder decoder = new QueryStringDecoder("1=2", false); - Assert.assertEquals("", decoder.path()); + assertEquals("", decoder.path()); Map> params = decoder.parameters(); - Assert.assertEquals(1, params.size()); - Assert.assertTrue(params.containsKey("1")); + assertEquals(1, params.size()); + assertTrue(params.containsKey("1")); List param = params.get("1"); - Assert.assertNotNull(param); - Assert.assertEquals(1, param.size()); - Assert.assertEquals("2", param.get(0)); + assertNotNull(param); + assertEquals(1, param.size()); + assertEquals("2", param.get(0)); } @Test @@ -224,9 +228,9 @@ public class QueryStringDecoderTest { final String expected = tests[i + 1]; try { final String decoded = QueryStringDecoder.decodeComponent(encoded); - Assert.assertEquals(expected, decoded); + assertEquals(expected, decoded); } catch (IllegalArgumentException e) { - Assert.assertEquals(expected, e.getMessage()); + assertEquals(expected, e.getMessage()); } } } @@ -240,8 +244,8 @@ public class QueryStringDecoderTest { 1024, semicolonIsNormalChar); QueryStringDecoder ad = new QueryStringDecoder(actual, CharsetUtil.UTF_8, true, 1024, semicolonIsNormalChar); - Assert.assertEquals(ed.path(), ad.path()); - Assert.assertEquals(ed.parameters(), ad.parameters()); + assertEquals(ed.path(), ad.path()); + assertEquals(ed.parameters(), ad.parameters()); } // See #189 @@ -249,29 +253,29 @@ public class QueryStringDecoderTest { public void testURI() { URI uri = URI.create("http://localhost:8080/foo?param1=value1¶m2=value2¶m3=value3"); QueryStringDecoder decoder = new QueryStringDecoder(uri); - Assert.assertEquals("/foo", decoder.path()); - Assert.assertEquals("/foo", decoder.rawPath()); - Assert.assertEquals("param1=value1¶m2=value2¶m3=value3", decoder.rawQuery()); + assertEquals("/foo", decoder.path()); + assertEquals("/foo", decoder.rawPath()); + assertEquals("param1=value1¶m2=value2¶m3=value3", decoder.rawQuery()); Map> params = decoder.parameters(); - Assert.assertEquals(3, params.size()); + assertEquals(3, params.size()); Iterator>> entries = params.entrySet().iterator(); Entry> entry = entries.next(); - Assert.assertEquals("param1", entry.getKey()); - Assert.assertEquals(1, entry.getValue().size()); - Assert.assertEquals("value1", entry.getValue().get(0)); + assertEquals("param1", entry.getKey()); + assertEquals(1, entry.getValue().size()); + assertEquals("value1", entry.getValue().get(0)); entry = entries.next(); - Assert.assertEquals("param2", entry.getKey()); - Assert.assertEquals(1, entry.getValue().size()); - Assert.assertEquals("value2", entry.getValue().get(0)); + assertEquals("param2", entry.getKey()); + assertEquals(1, entry.getValue().size()); + assertEquals("value2", entry.getValue().get(0)); entry = entries.next(); - Assert.assertEquals("param3", entry.getKey()); - Assert.assertEquals(1, entry.getValue().size()); - Assert.assertEquals("value3", entry.getValue().get(0)); + assertEquals("param3", entry.getKey()); + assertEquals(1, entry.getValue().size()); + assertEquals("value3", entry.getValue().get(0)); - Assert.assertFalse(entries.hasNext()); + assertFalse(entries.hasNext()); } // See #189 @@ -279,30 +283,30 @@ public class QueryStringDecoderTest { public void testURISlashPath() { URI uri = URI.create("http://localhost:8080/?param1=value1¶m2=value2¶m3=value3"); QueryStringDecoder decoder = new QueryStringDecoder(uri); - Assert.assertEquals("/", decoder.path()); - Assert.assertEquals("/", decoder.rawPath()); - Assert.assertEquals("param1=value1¶m2=value2¶m3=value3", decoder.rawQuery()); + assertEquals("/", decoder.path()); + assertEquals("/", decoder.rawPath()); + assertEquals("param1=value1¶m2=value2¶m3=value3", decoder.rawQuery()); Map> params = decoder.parameters(); - Assert.assertEquals(3, params.size()); + assertEquals(3, params.size()); Iterator>> entries = params.entrySet().iterator(); Entry> entry = entries.next(); - Assert.assertEquals("param1", entry.getKey()); - Assert.assertEquals(1, entry.getValue().size()); - Assert.assertEquals("value1", entry.getValue().get(0)); + assertEquals("param1", entry.getKey()); + assertEquals(1, entry.getValue().size()); + assertEquals("value1", entry.getValue().get(0)); entry = entries.next(); - Assert.assertEquals("param2", entry.getKey()); - Assert.assertEquals(1, entry.getValue().size()); - Assert.assertEquals("value2", entry.getValue().get(0)); + assertEquals("param2", entry.getKey()); + assertEquals(1, entry.getValue().size()); + assertEquals("value2", entry.getValue().get(0)); entry = entries.next(); - Assert.assertEquals("param3", entry.getKey()); - Assert.assertEquals(1, entry.getValue().size()); - Assert.assertEquals("value3", entry.getValue().get(0)); + assertEquals("param3", entry.getKey()); + assertEquals(1, entry.getValue().size()); + assertEquals("value3", entry.getValue().get(0)); - Assert.assertFalse(entries.hasNext()); + assertFalse(entries.hasNext()); } // See #189 @@ -310,30 +314,30 @@ public class QueryStringDecoderTest { public void testURINoPath() { URI uri = URI.create("http://localhost:8080?param1=value1¶m2=value2¶m3=value3"); QueryStringDecoder decoder = new QueryStringDecoder(uri); - Assert.assertEquals("", decoder.path()); - Assert.assertEquals("", decoder.rawPath()); - Assert.assertEquals("param1=value1¶m2=value2¶m3=value3", decoder.rawQuery()); + assertEquals("", decoder.path()); + assertEquals("", decoder.rawPath()); + assertEquals("param1=value1¶m2=value2¶m3=value3", decoder.rawQuery()); Map> params = decoder.parameters(); - Assert.assertEquals(3, params.size()); + assertEquals(3, params.size()); Iterator>> entries = params.entrySet().iterator(); Entry> entry = entries.next(); - Assert.assertEquals("param1", entry.getKey()); - Assert.assertEquals(1, entry.getValue().size()); - Assert.assertEquals("value1", entry.getValue().get(0)); + assertEquals("param1", entry.getKey()); + assertEquals(1, entry.getValue().size()); + assertEquals("value1", entry.getValue().get(0)); entry = entries.next(); - Assert.assertEquals("param2", entry.getKey()); - Assert.assertEquals(1, entry.getValue().size()); - Assert.assertEquals("value2", entry.getValue().get(0)); + assertEquals("param2", entry.getKey()); + assertEquals(1, entry.getValue().size()); + assertEquals("value2", entry.getValue().get(0)); entry = entries.next(); - Assert.assertEquals("param3", entry.getKey()); - Assert.assertEquals(1, entry.getValue().size()); - Assert.assertEquals("value3", entry.getValue().get(0)); + assertEquals("param3", entry.getKey()); + assertEquals(1, entry.getValue().size()); + assertEquals("value3", entry.getValue().get(0)); - Assert.assertFalse(entries.hasNext()); + assertFalse(entries.hasNext()); } // See https://github.com/netty/netty/issues/1833 @@ -341,37 +345,37 @@ public class QueryStringDecoderTest { public void testURI2() { URI uri = URI.create("http://foo.com/images;num=10?query=name;value=123"); QueryStringDecoder decoder = new QueryStringDecoder(uri); - Assert.assertEquals("/images;num=10", decoder.path()); - Assert.assertEquals("/images;num=10", decoder.rawPath()); - Assert.assertEquals("query=name;value=123", decoder.rawQuery()); + assertEquals("/images;num=10", decoder.path()); + assertEquals("/images;num=10", decoder.rawPath()); + assertEquals("query=name;value=123", decoder.rawQuery()); Map> params = decoder.parameters(); - Assert.assertEquals(2, params.size()); + assertEquals(2, params.size()); Iterator>> entries = params.entrySet().iterator(); Entry> entry = entries.next(); - Assert.assertEquals("query", entry.getKey()); - Assert.assertEquals(1, entry.getValue().size()); - Assert.assertEquals("name", entry.getValue().get(0)); + assertEquals("query", entry.getKey()); + assertEquals(1, entry.getValue().size()); + assertEquals("name", entry.getValue().get(0)); entry = entries.next(); - Assert.assertEquals("value", entry.getKey()); - Assert.assertEquals(1, entry.getValue().size()); - Assert.assertEquals("123", entry.getValue().get(0)); + assertEquals("value", entry.getKey()); + assertEquals(1, entry.getValue().size()); + assertEquals("123", entry.getValue().get(0)); - Assert.assertFalse(entries.hasNext()); + assertFalse(entries.hasNext()); } @Test public void testEmptyStrings() { QueryStringDecoder pathSlash = new QueryStringDecoder("path/"); - Assert.assertEquals("path/", pathSlash.rawPath()); - Assert.assertEquals("", pathSlash.rawQuery()); + assertEquals("path/", pathSlash.rawPath()); + assertEquals("", pathSlash.rawQuery()); QueryStringDecoder pathQuestion = new QueryStringDecoder("path?"); - Assert.assertEquals("path", pathQuestion.rawPath()); - Assert.assertEquals("", pathQuestion.rawQuery()); + assertEquals("path", pathQuestion.rawPath()); + assertEquals("", pathQuestion.rawQuery()); QueryStringDecoder empty = new QueryStringDecoder(""); - Assert.assertEquals("", empty.rawPath()); - Assert.assertEquals("", empty.rawQuery()); + assertEquals("", empty.rawPath()); + assertEquals("", empty.rawQuery()); } } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringEncoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringEncoderTest.java index 6d77d15fd9..5c93758ad3 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringEncoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringEncoderTest.java @@ -15,12 +15,13 @@ */ package io.netty.handler.codec.http; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.URI; import java.nio.charset.Charset; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class QueryStringEncoderTest { @Test @@ -29,47 +30,47 @@ public class QueryStringEncoderTest { e = new QueryStringEncoder("/foo"); e.addParam("a", "b=c"); - Assert.assertEquals("/foo?a=b%3Dc", e.toString()); - Assert.assertEquals(new URI("/foo?a=b%3Dc"), e.toUri()); + assertEquals("/foo?a=b%3Dc", e.toString()); + assertEquals(new URI("/foo?a=b%3Dc"), e.toUri()); e = new QueryStringEncoder("/foo/\u00A5"); e.addParam("a", "\u00A5"); - Assert.assertEquals("/foo/\u00A5?a=%C2%A5", e.toString()); - Assert.assertEquals(new URI("/foo/\u00A5?a=%C2%A5"), e.toUri()); + assertEquals("/foo/\u00A5?a=%C2%A5", e.toString()); + assertEquals(new URI("/foo/\u00A5?a=%C2%A5"), e.toUri()); e = new QueryStringEncoder("/foo/\u00A5"); e.addParam("a", "abc\u00A5"); - Assert.assertEquals("/foo/\u00A5?a=abc%C2%A5", e.toString()); - Assert.assertEquals(new URI("/foo/\u00A5?a=abc%C2%A5"), e.toUri()); + assertEquals("/foo/\u00A5?a=abc%C2%A5", e.toString()); + assertEquals(new URI("/foo/\u00A5?a=abc%C2%A5"), e.toUri()); e = new QueryStringEncoder("/foo"); e.addParam("a", "1"); e.addParam("b", "2"); - Assert.assertEquals("/foo?a=1&b=2", e.toString()); - Assert.assertEquals(new URI("/foo?a=1&b=2"), e.toUri()); + assertEquals("/foo?a=1&b=2", e.toString()); + assertEquals(new URI("/foo?a=1&b=2"), e.toUri()); e = new QueryStringEncoder("/foo"); e.addParam("a", "1"); e.addParam("b", ""); e.addParam("c", null); e.addParam("d", null); - Assert.assertEquals("/foo?a=1&b=&c&d", e.toString()); - Assert.assertEquals(new URI("/foo?a=1&b=&c&d"), e.toUri()); + assertEquals("/foo?a=1&b=&c&d", e.toString()); + assertEquals(new URI("/foo?a=1&b=&c&d"), e.toUri()); } @Test public void testNonDefaultEncoding() throws Exception { QueryStringEncoder e = new QueryStringEncoder("/foo/\u00A5", Charset.forName("UTF-16")); e.addParam("a", "\u00A5"); - Assert.assertEquals("/foo/\u00A5?a=%FE%FF%00%A5", e.toString()); - Assert.assertEquals(new URI("/foo/\u00A5?a=%FE%FF%00%A5"), e.toUri()); + assertEquals("/foo/\u00A5?a=%FE%FF%00%A5", e.toString()); + assertEquals(new URI("/foo/\u00A5?a=%FE%FF%00%A5"), e.toUri()); } @Test public void testWhitespaceEncoding() throws Exception { QueryStringEncoder e = new QueryStringEncoder("/foo"); e.addParam("a", "b c"); - Assert.assertEquals("/foo?a=b%20c", e.toString()); - Assert.assertEquals(new URI("/foo?a=b%20c"), e.toUri()); + assertEquals("/foo?a=b%20c", e.toString()); + assertEquals(new URI("/foo?a=b%20c"), e.toUri()); } } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/ReadOnlyHttpHeadersTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/ReadOnlyHttpHeadersTest.java index 5155ee27d7..4d32eb4d99 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/ReadOnlyHttpHeadersTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/ReadOnlyHttpHeadersTest.java @@ -16,7 +16,7 @@ package io.netty.handler.codec.http; import io.netty.util.AsciiString; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Iterator; import java.util.List; @@ -30,10 +30,11 @@ import static io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_JSON; import static io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_OCTET_STREAM; import static io.netty.handler.codec.http.HttpHeaderValues.CLOSE; import static io.netty.handler.codec.http.HttpHeaderValues.ZERO; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +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 class ReadOnlyHttpHeadersTest { @Test @@ -113,22 +114,22 @@ public class ReadOnlyHttpHeadersTest { assertTrue(APPLICATION_OCTET_STREAM.contentEqualsIgnoreCase(names.get(1))); } - @Test(expected = IllegalArgumentException.class) + @Test public void validateNamesFail() { - new ReadOnlyHttpHeaders(true, - ACCEPT, APPLICATION_JSON, AsciiString.cached(" ")); + assertThrows(IllegalArgumentException.class, () -> new ReadOnlyHttpHeaders(true, + ACCEPT, APPLICATION_JSON, AsciiString.cached(" "))); } - @Test(expected = IllegalArgumentException.class) + @Test public void emptyHeaderName() { - new ReadOnlyHttpHeaders(true, - ACCEPT, APPLICATION_JSON, AsciiString.cached(" "), ZERO); + assertThrows(IllegalArgumentException.class, () -> new ReadOnlyHttpHeaders(true, + ACCEPT, APPLICATION_JSON, AsciiString.cached(" "), ZERO)); } - @Test(expected = IllegalArgumentException.class) + @Test public void headerWithoutValue() { - new ReadOnlyHttpHeaders(false, - ACCEPT, APPLICATION_JSON, CONTENT_LENGTH); + assertThrows(IllegalArgumentException.class, () -> new ReadOnlyHttpHeaders(false, + ACCEPT, APPLICATION_JSON, CONTENT_LENGTH)); } private static void assert3ParisEquals(Iterator> itr) { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ClientCookieDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ClientCookieDecoderTest.java index cf9d127fb6..ca7c7419f3 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ClientCookieDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ClientCookieDecoderTest.java @@ -17,7 +17,7 @@ package io.netty.handler.codec.http.cookie; import io.netty.handler.codec.DateFormatter; import io.netty.handler.codec.http.cookie.CookieHeaderNames.SameSite; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Calendar; @@ -29,7 +29,12 @@ import java.util.TimeZone; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -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.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ClientCookieDecoderTest { @Test @@ -42,10 +47,10 @@ public class ClientCookieDecoderTest { assertNotNull(cookie); assertEquals("myValue", cookie.value()); assertEquals(".adomainsomewhere", cookie.domain()); - assertNotEquals("maxAge should be defined when parsing cookie " + cookieString, - Long.MIN_VALUE, cookie.maxAge()); - assertTrue("maxAge should be about 50ms when parsing cookie " + cookieString, - cookie.maxAge() >= 40 && cookie.maxAge() <= 60); + assertNotEquals(Long.MIN_VALUE, cookie.maxAge(), + "maxAge should be defined when parsing cookie " + cookieString); + assertTrue(cookie.maxAge() >= 40 && cookie.maxAge() <= 60, + "maxAge should be about 50ms when parsing cookie " + cookieString); assertEquals("/apathsomewhere", cookie.path()); assertTrue(cookie.isSecure()); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ClientCookieEncoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ClientCookieEncoderTest.java index 90bc70c769..78267dd15e 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ClientCookieEncoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ClientCookieEncoderTest.java @@ -15,9 +15,10 @@ */ package io.netty.handler.codec.http.cookie; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ClientCookieEncoderTest { @@ -47,9 +48,10 @@ public class ClientCookieEncoderTest { ClientCookieEncoder.STRICT.encode(new DefaultCookie("myCookie", "\"foo\"")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testRejectCookieValueWithSemicolon() { - ClientCookieEncoder.STRICT.encode(new DefaultCookie("myCookie", "foo;bar")); + assertThrows(IllegalArgumentException.class, + () -> ClientCookieEncoder.STRICT.encode(new DefaultCookie("myCookie", "foo;bar"))); } @Test diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ServerCookieDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ServerCookieDecoderTest.java index 74faa4a4c2..78aa88be58 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ServerCookieDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ServerCookieDecoderTest.java @@ -16,12 +16,15 @@ package io.netty.handler.codec.http.cookie; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Iterator; import java.util.Set; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ServerCookieDecoderTest { @Test diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ServerCookieEncoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ServerCookieEncoderTest.java index 0381cb5e4c..e48b868f18 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ServerCookieEncoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/cookie/ServerCookieEncoderTest.java @@ -17,10 +17,10 @@ package io.netty.handler.codec.http.cookie; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import io.netty.handler.codec.DateFormatter; @@ -34,7 +34,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import io.netty.handler.codec.http.cookie.CookieHeaderNames.SameSite; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ServerCookieEncoderTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/cors/CorsConfigTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/cors/CorsConfigTest.java index 00cc726e9d..4784a372a1 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/cors/CorsConfigTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/cors/CorsConfigTest.java @@ -19,7 +19,7 @@ import io.netty.handler.codec.http.EmptyHttpHeaders; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpMethod; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static io.netty.handler.codec.http.HttpHeadersTestUtils.of; import static io.netty.handler.codec.http.cors.CorsConfigBuilder.forAnyOrigin; @@ -30,6 +30,7 @@ import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; public class CorsConfigTest { @@ -125,9 +126,10 @@ public class CorsConfigTest { assertThat(cors.preflightResponseHeaders(), equalTo((HttpHeaders) EmptyHttpHeaders.INSTANCE)); } - @Test (expected = IllegalArgumentException.class) + @Test public void shouldThrowIfValueIsNull() { - forOrigin("*").preflightResponseHeader("HeaderName", new Object[]{null}).build(); + assertThrows(IllegalArgumentException.class, + () -> forOrigin("*").preflightResponseHeader("HeaderName", new Object[]{null}).build()); } @Test diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/cors/CorsHandlerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/cors/CorsHandlerTest.java index a0e0cc29ea..c0e07a7857 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/cors/CorsHandlerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/cors/CorsHandlerTest.java @@ -27,7 +27,7 @@ import io.netty.handler.codec.http.HttpUtil; import io.netty.util.AsciiString; import io.netty.util.ReferenceCountUtil; import org.hamcrest.core.IsEqual; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/AbstractDiskHttpDataTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/AbstractDiskHttpDataTest.java index d212ae6ee2..e686405306 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/AbstractDiskHttpDataTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/AbstractDiskHttpDataTest.java @@ -18,7 +18,7 @@ package io.netty.handler.codec.http.multipart; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.util.internal.PlatformDependent; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.FileOutputStream; @@ -28,8 +28,8 @@ import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; import static io.netty.util.CharsetUtil.UTF_8; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; /** * {@link AbstractDiskHttpData} test cases @@ -58,8 +58,8 @@ public class AbstractDiskHttpDataTest { ByteBuf buf2 = test.getChunk(1024); assertEquals(buf2.readerIndex(), 0); assertEquals(buf2.writerIndex(), 1024); - assertFalse("Arrays should not be equal", - Arrays.equals(ByteBufUtil.getBytes(buf1), ByteBufUtil.getBytes(buf2))); + assertFalse(Arrays.equals(ByteBufUtil.getBytes(buf1), ByteBufUtil.getBytes(buf2)), + "Arrays should not be equal"); } finally { test.delete(); } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpDataTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpDataTest.java index 1befe5b04f..4b906e47db 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpDataTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpDataTest.java @@ -21,7 +21,7 @@ import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; import io.netty.util.internal.PlatformDependent; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.File; @@ -35,7 +35,10 @@ import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; import static io.netty.util.CharsetUtil.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** {@link AbstractMemoryHttpData} test cases. */ public class AbstractMemoryHttpDataTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/DefaultHttpDataFactoryTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/DefaultHttpDataFactoryTest.java index eab2f14a2b..2af577ed82 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/DefaultHttpDataFactoryTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/DefaultHttpDataFactoryTest.java @@ -18,21 +18,21 @@ package io.netty.handler.codec.http.multipart; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.DefaultHttpRequest; import io.netty.handler.codec.http.HttpRequest; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static io.netty.handler.codec.http.HttpHeaderValues.IDENTITY; import static io.netty.handler.codec.http.HttpMethod.POST; import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; import static io.netty.handler.codec.http.multipart.HttpPostBodyUtil.DEFAULT_TEXT_CONTENT_TYPE; import static io.netty.util.CharsetUtil.UTF_8; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class DefaultHttpDataFactoryTest { // req1 equals req2 @@ -41,19 +41,19 @@ public class DefaultHttpDataFactoryTest { private DefaultHttpDataFactory factory; - @BeforeClass + @BeforeAll public static void assertReq1EqualsReq2() { // Before doing anything, assert that the requests are equal assertEquals(req1.hashCode(), req2.hashCode()); assertTrue(req1.equals(req2)); } - @Before + @BeforeEach public void setupFactory() { factory = new DefaultHttpDataFactory(); } - @After + @AfterEach public void cleanupFactory() { factory.cleanAllHttpData(); } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/DeleteFileOnExitHookTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/DeleteFileOnExitHookTest.java index 7f0fc6a7fa..fb1799f204 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/DeleteFileOnExitHookTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/DeleteFileOnExitHookTest.java @@ -18,8 +18,8 @@ package io.netty.handler.codec.http.multipart; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.DefaultHttpRequest; import io.netty.handler.codec.http.HttpRequest; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.FilenameFilter; @@ -27,7 +27,9 @@ import java.io.IOException; import static io.netty.handler.codec.http.HttpMethod.POST; import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; -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.assertTrue; /** * Test DeleteFileOnExitHook @@ -37,7 +39,7 @@ public class DeleteFileOnExitHookTest { private static final String HOOK_TEST_TMP = "target/DeleteFileOnExitHookTest/tmp"; private FileUpload fu; - @Before + @BeforeEach public void setUp() throws IOException { DefaultHttpDataFactory defaultHttpDataFactory = new DefaultHttpDataFactory(true); defaultHttpDataFactory.setBaseDir(HOOK_TEST_TMP); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/DiskFileUploadTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/DiskFileUploadTest.java index 0ed936786d..96e101eecb 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/DiskFileUploadTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/DiskFileUploadTest.java @@ -22,7 +22,7 @@ import io.netty.buffer.Unpooled; import io.netty.util.CharsetUtil; import io.netty.util.internal.PlatformDependent; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.FileInputStream; @@ -32,13 +32,13 @@ import java.io.InputStream; import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class DiskFileUploadTest { @Test diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostMultiPartRequestDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostMultiPartRequestDecoderTest.java index 4d516bb71c..d7d3ab8342 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostMultiPartRequestDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostMultiPartRequestDecoderTest.java @@ -28,17 +28,17 @@ import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpVersion; import io.netty.util.CharsetUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Arrays; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class HttpPostMultiPartRequestDecoderTest { @@ -173,22 +173,22 @@ public class HttpPostMultiPartRequestDecoderTest { assertEquals(inMemory, data.isInMemory()); if (data.isInMemory()) { // To be done only if not inMemory: assertEquals(data.get().length, fileSize); - assertFalse("Capacity should be higher than 1M", data.getByteBuf().capacity() - < 1024 * 1024); + assertFalse(data.getByteBuf().capacity() < 1024 * 1024, + "Capacity should be higher than 1M"); } - assertTrue("Capacity should be less than 1M", decoder.getCurrentAllocatedCapacity() - < 1024 * 1024); + assertTrue(decoder.getCurrentAllocatedCapacity() < 1024 * 1024, + "Capacity should be less than 1M"); InterfaceHttpData[] httpDatas = decoder.getBodyHttpDatas().toArray(new InterfaceHttpData[0]); for (InterfaceHttpData httpData : httpDatas) { - assertEquals("Before cleanAllHttpData should be 1", 1, httpData.refCnt()); + assertEquals(1, httpData.refCnt(), "Before cleanAllHttpData should be 1"); } factory.cleanAllHttpData(); for (InterfaceHttpData httpData : httpDatas) { - assertEquals("Before cleanAllHttpData should be 1 if in Memory", inMemory? 1 : 0, httpData.refCnt()); + assertEquals(inMemory? 1 : 0, httpData.refCnt(), "Before cleanAllHttpData should be 1 if in Memory"); } decoder.destroy(); for (InterfaceHttpData httpData : httpDatas) { - assertEquals("RefCnt should be 0", 0, httpData.refCnt()); + assertEquals(0, httpData.refCnt(), "RefCnt should be 0"); } } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestDecoderTest.java index fe3dae0187..89c03d9800 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestDecoderTest.java @@ -32,13 +32,18 @@ import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.codec.http.LastHttpContent; import io.netty.util.CharsetUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.URLEncoder; import java.nio.charset.UnsupportedCharsetException; import java.util.Arrays; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * {@link HttpPostRequestDecoder} test case. @@ -97,8 +102,8 @@ public class HttpPostRequestDecoderTest { MemoryFileUpload upload = (MemoryFileUpload) decoder.next(); // Validate data has been parsed correctly as it was passed into request. - assertEquals("Invalid decoded data [data=" + data.replaceAll("\r", "\\\\r") + ", upload=" + upload + ']', - data, upload.getString(CharsetUtil.UTF_8)); + assertEquals(data, upload.getString(CharsetUtil.UTF_8), + "Invalid decoded data [data=" + data.replaceAll("\r", "\\\\r") + ", upload=" + upload + ']'); upload.release(); decoder.destroy(); buf.release(); @@ -266,7 +271,7 @@ public class HttpPostRequestDecoderTest { aDecoder.offer(LastHttpContent.EMPTY_LAST_CONTENT); - assertTrue("Should have a piece of data", aDecoder.hasNext()); + assertTrue(aDecoder.hasNext(), "Should have a piece of data"); InterfaceHttpData aDecodedData = aDecoder.next(); assertEquals(InterfaceHttpData.HttpDataType.Attribute, aDecodedData.getHttpDataType()); @@ -465,10 +470,10 @@ public class HttpPostRequestDecoderTest { final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req); assertFalse(decoder.getBodyHttpDatas().isEmpty()); InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0); - assertTrue("the item should be a FileUpload", part1 instanceof FileUpload); + assertTrue(part1 instanceof FileUpload, "the item should be a FileUpload"); FileUpload fileUpload = (FileUpload) part1; byte[] fileBytes = fileUpload.get(); - assertTrue("the filecontent should not be decoded", filecontent.equals(new String(fileBytes))); + assertTrue(filecontent.equals(new String(fileBytes)), "the filecontent should not be decoded"); decoder.destroy(); assertTrue(req.release()); } @@ -580,9 +585,9 @@ public class HttpPostRequestDecoderTest { final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req); assertFalse(decoder.getBodyHttpDatas().isEmpty()); InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0); - assertTrue("the item should be a FileUpload", part1 instanceof FileUpload); + assertTrue(part1 instanceof FileUpload, "the item should be a FileUpload"); FileUpload fileUpload = (FileUpload) part1; - assertEquals("the filename should be decoded", filename, fileUpload.getFilename()); + assertEquals(filename, fileUpload.getFilename(), "the filename should be decoded"); decoder.destroy(); assertTrue(req.release()); } @@ -616,9 +621,9 @@ public class HttpPostRequestDecoderTest { final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req); assertFalse(decoder.getBodyHttpDatas().isEmpty()); InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0); - assertTrue("the item should be a FileUpload", part1 instanceof FileUpload); + assertTrue(part1 instanceof FileUpload, "the item should be a FileUpload"); FileUpload fileUpload = (FileUpload) part1; - assertEquals("the filename should be decoded", filename, fileUpload.getFilename()); + assertEquals(filename, fileUpload.getFilename(), "the filename should be decoded"); decoder.destroy(); assertTrue(req.release()); } @@ -758,25 +763,28 @@ public class HttpPostRequestDecoderTest { assertTrue(req.release()); } - @Test(expected = HttpPostRequestDecoder.ErrorDataDecoderException.class) + @Test public void testNotLeak() { FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", Unpooled.copiedBuffer("a=1&&b=2", CharsetUtil.US_ASCII)); try { - new HttpPostStandardRequestDecoder(request).destroy(); + assertThrows(HttpPostRequestDecoder.ErrorDataDecoderException.class, + () -> new HttpPostStandardRequestDecoder(request).destroy()); } finally { assertTrue(request.release()); } } - @Test(expected = HttpPostRequestDecoder.ErrorDataDecoderException.class) + @Test public void testNotLeakDirectBufferWhenWrapIllegalArgumentException() { - testNotLeakWhenWrapIllegalArgumentException(Unpooled.directBuffer()); + assertThrows(HttpPostRequestDecoder.ErrorDataDecoderException.class, + () -> testNotLeakWhenWrapIllegalArgumentException(Unpooled.directBuffer())); } - @Test(expected = HttpPostRequestDecoder.ErrorDataDecoderException.class) + @Test public void testNotLeakHeapBufferWhenWrapIllegalArgumentException() { - testNotLeakWhenWrapIllegalArgumentException(Unpooled.buffer()); + assertThrows(HttpPostRequestDecoder.ErrorDataDecoderException.class, + () -> testNotLeakWhenWrapIllegalArgumentException(Unpooled.buffer())); } private static void testNotLeakWhenWrapIllegalArgumentException(ByteBuf buf) { @@ -830,9 +838,9 @@ public class HttpPostRequestDecoderTest { final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req); assertFalse(decoder.getBodyHttpDatas().isEmpty()); InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0); - assertTrue("the item should be a FileUpload", part1 instanceof FileUpload); + assertTrue(part1 instanceof FileUpload, "the item should be a FileUpload"); FileUpload fileUpload = (FileUpload) part1; - assertEquals("the filename should be decoded", filename, fileUpload.getFilename()); + assertEquals(filename, fileUpload.getFilename(), "the filename should be decoded"); decoder.destroy(); assertTrue(req.release()); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoderTest.java index ffb64143f0..d1810cc08c 100755 --- a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoderTest.java @@ -30,7 +30,7 @@ import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder.EncoderMode; import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder.ErrorDataEncoderException; import io.netty.util.CharsetUtil; import io.netty.util.internal.StringUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.File; @@ -41,10 +41,10 @@ import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_DISPOSITION; import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH; import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TRANSFER_ENCODING; import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** {@link HttpPostRequestEncoder} test case. */ public class HttpPostRequestEncoderTest { @@ -345,9 +345,9 @@ public class HttpPostRequestEncoderTest { HttpContent httpContent = encoder.readChunk((ByteBufAllocator) null); ByteBuf content = httpContent.content(); int refCnt = content.refCnt(); - assertTrue("content: " + content + " content.unwrap(): " + content.unwrap() + " refCnt: " + refCnt, - (content.unwrap() == content || content.unwrap() == null) && refCnt == 1 || - content.unwrap() != content && refCnt == 2); + assertTrue((content.unwrap() == content || content.unwrap() == null) && refCnt == 1 || + content.unwrap() != content && refCnt == 2, + "content: " + content + " content.unwrap(): " + content.unwrap() + " refCnt: " + refCnt); httpContent.release(); } encoder.cleanFiles(); @@ -401,10 +401,10 @@ public class HttpPostRequestEncoderTest { checkNextChunkSize(encoder, 8080); HttpContent httpContent = encoder.readChunk((ByteBufAllocator) null); - assertTrue("Expected LastHttpContent is not received", httpContent instanceof LastHttpContent); + assertTrue(httpContent instanceof LastHttpContent, "Expected LastHttpContent is not received"); httpContent.release(); - assertTrue("Expected end of input is not receive", encoder.isEndOfInput()); + assertTrue(encoder.isEndOfInput(), "Expected end of input is not receive"); } @Test @@ -423,10 +423,10 @@ public class HttpPostRequestEncoderTest { checkNextChunkSize(encoder, 8080); HttpContent httpContent = encoder.readChunk((ByteBufAllocator) null); - assertTrue("Expected LastHttpContent is not received", httpContent instanceof LastHttpContent); + assertTrue(httpContent instanceof LastHttpContent, "Expected LastHttpContent is not received"); httpContent.release(); - assertTrue("Expected end of input is not receive", encoder.isEndOfInput()); + assertTrue(encoder.isEndOfInput(), "Expected end of input is not receive"); } private static void checkNextChunkSize(HttpPostRequestEncoder encoder, int sizeWithoutDelimiter) throws Exception { @@ -441,8 +441,8 @@ public class HttpPostRequestEncoderTest { int readable = httpContent.content().readableBytes(); boolean expectedSize = readable >= expectedSizeMin && readable <= expectedSizeMax; - assertTrue("Chunk size is not in expected range (" + expectedSizeMin + " - " + expectedSizeMax + "), was: " - + readable, expectedSize); + assertTrue(expectedSize, "Chunk size is not in expected range (" + expectedSizeMin + " - " + + expectedSizeMax + "), was: " + readable); httpContent.release(); } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/MemoryFileUploadTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/MemoryFileUploadTest.java index 1a65ce0ded..167c8c3c20 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/MemoryFileUploadTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/MemoryFileUploadTest.java @@ -15,8 +15,9 @@ */ package io.netty.handler.codec.http.multipart; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class MemoryFileUploadTest { @@ -24,6 +25,6 @@ public class MemoryFileUploadTest { public final void testMemoryFileUploadEquals() { MemoryFileUpload f1 = new MemoryFileUpload("m1", "m1", "application/json", null, null, 100); - Assert.assertEquals(f1, f1); + assertEquals(f1, f1); } } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocket00FrameEncoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocket00FrameEncoderTest.java index 2b04581ff9..c428e316f7 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocket00FrameEncoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocket00FrameEncoderTest.java @@ -17,8 +17,11 @@ package io.netty.handler.codec.http.websocketx; import io.netty.buffer.ByteBuf; import io.netty.channel.embedded.EmbeddedChannel; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class WebSocket00FrameEncoderTest { @@ -26,19 +29,19 @@ public class WebSocket00FrameEncoderTest { @Test public void testMultipleWebSocketCloseFrames() { EmbeddedChannel channel = new EmbeddedChannel(new WebSocket00FrameEncoder()); - Assert.assertTrue(channel.writeOutbound(new CloseWebSocketFrame())); - Assert.assertTrue(channel.writeOutbound(new CloseWebSocketFrame())); - Assert.assertTrue(channel.finish()); + assertTrue(channel.writeOutbound(new CloseWebSocketFrame())); + assertTrue(channel.writeOutbound(new CloseWebSocketFrame())); + assertTrue(channel.finish()); assertCloseWebSocketFrame(channel); assertCloseWebSocketFrame(channel); - Assert.assertNull(channel.readOutbound()); + assertNull(channel.readOutbound()); } private static void assertCloseWebSocketFrame(EmbeddedChannel channel) { ByteBuf buf = channel.readOutbound(); - Assert.assertEquals(2, buf.readableBytes()); - Assert.assertEquals((byte) 0xFF, buf.readByte()); - Assert.assertEquals((byte) 0x00, buf.readByte()); + assertEquals(2, buf.readableBytes()); + assertEquals((byte) 0xFF, buf.readByte()); + assertEquals((byte) 0x00, buf.readByte()); buf.release(); } } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocket08EncoderDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocket08EncoderDecoderTest.java index ab233bbd2a..2edc7bd35d 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocket08EncoderDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocket08EncoderDecoderTest.java @@ -18,8 +18,13 @@ package io.netty.handler.codec.http.websocketx; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.embedded.EmbeddedChannel; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests the WebSocket08FrameEncoder and Decoder implementation.
@@ -73,13 +78,13 @@ public class WebSocket08EncoderDecoderTest { executeProtocolViolationTest(outChannel, inChannel, maxPayloadLength + 1, expectedStatus, errorMessage); CloseWebSocketFrame response = inChannel.readOutbound(); - Assert.assertNotNull(response); - Assert.assertEquals(expectedStatus.code(), response.statusCode()); - Assert.assertEquals(errorMessage, response.reasonText()); + assertNotNull(response); + assertEquals(expectedStatus.code(), response.statusCode()); + assertEquals(errorMessage, response.reasonText()); response.release(); - Assert.assertFalse(inChannel.finish()); - Assert.assertFalse(outChannel.finish()); + assertFalse(inChannel.finish()); + assertFalse(outChannel.finish()); // Without auto-close config = WebSocketDecoderConfig.newBuilder() @@ -92,10 +97,10 @@ public class WebSocket08EncoderDecoderTest { executeProtocolViolationTest(outChannel, inChannel, maxPayloadLength + 1, expectedStatus, errorMessage); response = inChannel.readOutbound(); - Assert.assertNull(response); + assertNull(response); - Assert.assertFalse(inChannel.finish()); - Assert.assertFalse(outChannel.finish()); + assertFalse(inChannel.finish()); + assertFalse(outChannel.finish()); // Release test data binTestData.release(); @@ -112,11 +117,11 @@ public class WebSocket08EncoderDecoderTest { } BinaryWebSocketFrame exceedingFrame = inChannel.readInbound(); - Assert.assertNull(exceedingFrame); + assertNull(exceedingFrame); - Assert.assertNotNull(corrupted); - Assert.assertEquals(expectedStatus, corrupted.closeStatus()); - Assert.assertEquals(errorMessage, corrupted.getMessage()); + assertNotNull(corrupted); + assertEquals(expectedStatus, corrupted.closeStatus()); + assertEquals(errorMessage, corrupted.getMessage()); } @Test @@ -177,10 +182,10 @@ public class WebSocket08EncoderDecoderTest { transfer(outChannel, inChannel); Object decoded = inChannel.readInbound(); - Assert.assertNotNull(decoded); - Assert.assertTrue(decoded instanceof TextWebSocketFrame); + assertNotNull(decoded); + assertTrue(decoded instanceof TextWebSocketFrame); TextWebSocketFrame txt = (TextWebSocketFrame) decoded; - Assert.assertEquals(txt.text(), testStr); + assertEquals(txt.text(), testStr); txt.release(); } @@ -192,13 +197,13 @@ public class WebSocket08EncoderDecoderTest { transfer(outChannel, inChannel); Object decoded = inChannel.readInbound(); - Assert.assertNotNull(decoded); - Assert.assertTrue(decoded instanceof BinaryWebSocketFrame); + assertNotNull(decoded); + assertTrue(decoded instanceof BinaryWebSocketFrame); BinaryWebSocketFrame binFrame = (BinaryWebSocketFrame) decoded; int readable = binFrame.content().readableBytes(); - Assert.assertEquals(readable, testDataLength); + assertEquals(readable, testDataLength); for (int i = 0; i < testDataLength; i++) { - Assert.assertEquals(binTestData.getByte(i), binFrame.content().getByte(i)); + assertEquals(binTestData.getByte(i), binFrame.content().getByte(i)); } binFrame.release(); } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocket08FrameDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocket08FrameDecoderTest.java index 07b06156dc..4795a8faab 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocket08FrameDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocket08FrameDecoderTest.java @@ -15,14 +15,14 @@ package io.netty.handler.codec.http.websocketx; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.embedded.EmbeddedChannel; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.HashSet; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker07Test.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker07Test.java index ff938c0fe3..692bc3bbe6 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker07Test.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker07Test.java @@ -19,11 +19,11 @@ import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaders; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.URI; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class WebSocketClientHandshaker07Test extends WebSocketClientHandshakerTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshakerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshakerTest.java index c3b17267ad..76d2b2fb9c 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshakerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshakerTest.java @@ -35,12 +35,15 @@ import io.netty.handler.codec.http.HttpResponseDecoder; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpVersion; import io.netty.util.CharsetUtil; - -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.net.URI; +import java.util.concurrent.TimeUnit; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public abstract class WebSocketClientHandshakerTest { protected abstract WebSocketClientHandshaker newHandshaker(URI uri, String subprotocol, HttpHeaders headers, @@ -256,12 +259,14 @@ public abstract class WebSocketClientHandshakerTest { } } - @Test(timeout = 3000) + @Test + @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS) public void testHttpResponseAndFrameInSameBuffer() { testHttpResponseAndFrameInSameBuffer(false); } - @Test(timeout = 3000) + @Test + @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS) public void testHttpResponseAndFrameInSameBufferCodec() { testHttpResponseAndFrameInSameBuffer(true); } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketCloseStatusTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketCloseStatusTest.java index 223c12ce3d..9f9e43ea99 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketCloseStatusTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketCloseStatusTest.java @@ -20,13 +20,13 @@ import java.util.TreeSet; import org.assertj.core.api.ThrowableAssert; import org.hamcrest.Matchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; import static io.netty.handler.codec.http.websocketx.WebSocketCloseStatus.*; diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketFrameAggregatorTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketFrameAggregatorTest.java index 505b2377cd..2339db61c4 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketFrameAggregatorTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketFrameAggregatorTest.java @@ -21,8 +21,13 @@ import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.codec.TooLongFrameException; import io.netty.util.CharsetUtil; import io.netty.util.ReferenceCountUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class WebSocketFrameAggregatorTest { @@ -46,29 +51,29 @@ public class WebSocketFrameAggregatorTest { channel.writeInbound(new PongWebSocketFrame(Unpooled.wrappedBuffer(content1))); channel.writeInbound(new ContinuationWebSocketFrame(true, 0, Unpooled.wrappedBuffer(content3))); - Assert.assertTrue(channel.finish()); + assertTrue(channel.finish()); BinaryWebSocketFrame frame = channel.readInbound(); - Assert.assertTrue(frame.isFinalFragment()); - Assert.assertEquals(1, frame.rsv()); - Assert.assertArrayEquals(content1, toBytes(frame.content())); + assertTrue(frame.isFinalFragment()); + assertEquals(1, frame.rsv()); + assertArrayEquals(content1, toBytes(frame.content())); PingWebSocketFrame frame2 = channel.readInbound(); - Assert.assertTrue(frame2.isFinalFragment()); - Assert.assertEquals(0, frame2.rsv()); - Assert.assertArrayEquals(content1, toBytes(frame2.content())); + assertTrue(frame2.isFinalFragment()); + assertEquals(0, frame2.rsv()); + assertArrayEquals(content1, toBytes(frame2.content())); PongWebSocketFrame frame3 = channel.readInbound(); - Assert.assertTrue(frame3.isFinalFragment()); - Assert.assertEquals(0, frame3.rsv()); - Assert.assertArrayEquals(content1, toBytes(frame3.content())); + assertTrue(frame3.isFinalFragment()); + assertEquals(0, frame3.rsv()); + assertArrayEquals(content1, toBytes(frame3.content())); BinaryWebSocketFrame frame4 = channel.readInbound(); - Assert.assertTrue(frame4.isFinalFragment()); - Assert.assertEquals(0, frame4.rsv()); - Assert.assertArrayEquals(aggregatedContent, toBytes(frame4.content())); + assertTrue(frame4.isFinalFragment()); + assertEquals(0, frame4.rsv()); + assertArrayEquals(aggregatedContent, toBytes(frame4.content())); - Assert.assertNull(channel.readInbound()); + assertNull(channel.readInbound()); } @Test @@ -81,29 +86,29 @@ public class WebSocketFrameAggregatorTest { channel.writeInbound(new PongWebSocketFrame(Unpooled.wrappedBuffer(content1))); channel.writeInbound(new ContinuationWebSocketFrame(true, 0, Unpooled.wrappedBuffer(content3))); - Assert.assertTrue(channel.finish()); + assertTrue(channel.finish()); TextWebSocketFrame frame = channel.readInbound(); - Assert.assertTrue(frame.isFinalFragment()); - Assert.assertEquals(1, frame.rsv()); - Assert.assertArrayEquals(content1, toBytes(frame.content())); + assertTrue(frame.isFinalFragment()); + assertEquals(1, frame.rsv()); + assertArrayEquals(content1, toBytes(frame.content())); PingWebSocketFrame frame2 = channel.readInbound(); - Assert.assertTrue(frame2.isFinalFragment()); - Assert.assertEquals(0, frame2.rsv()); - Assert.assertArrayEquals(content1, toBytes(frame2.content())); + assertTrue(frame2.isFinalFragment()); + assertEquals(0, frame2.rsv()); + assertArrayEquals(content1, toBytes(frame2.content())); PongWebSocketFrame frame3 = channel.readInbound(); - Assert.assertTrue(frame3.isFinalFragment()); - Assert.assertEquals(0, frame3.rsv()); - Assert.assertArrayEquals(content1, toBytes(frame3.content())); + assertTrue(frame3.isFinalFragment()); + assertEquals(0, frame3.rsv()); + assertArrayEquals(content1, toBytes(frame3.content())); TextWebSocketFrame frame4 = channel.readInbound(); - Assert.assertTrue(frame4.isFinalFragment()); - Assert.assertEquals(0, frame4.rsv()); - Assert.assertArrayEquals(aggregatedContent, toBytes(frame4.content())); + assertTrue(frame4.isFinalFragment()); + assertEquals(0, frame4.rsv()); + assertArrayEquals(aggregatedContent, toBytes(frame4.content())); - Assert.assertNull(channel.readInbound()); + assertNull(channel.readInbound()); } @Test @@ -113,7 +118,7 @@ public class WebSocketFrameAggregatorTest { channel.writeInbound(new BinaryWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content1))); try { channel.writeInbound(new ContinuationWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content2))); - Assert.fail(); + fail(); } catch (TooLongFrameException e) { // expected } @@ -124,7 +129,7 @@ public class WebSocketFrameAggregatorTest { channel.writeInbound(new BinaryWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content1))); try { channel.writeInbound(new ContinuationWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content2))); - Assert.fail(); + fail(); } catch (TooLongFrameException e) { // expected } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeExceptionTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeExceptionTest.java index eb7491e0e5..e9ec9d7b86 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeExceptionTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeExceptionTest.java @@ -22,9 +22,11 @@ import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpVersion; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; public class WebSocketHandshakeExceptionTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeHandOverTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeHandOverTest.java index 1d50ba4fe7..7881f7628d 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeHandOverTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeHandOverTest.java @@ -29,13 +29,19 @@ import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpServerCodec; import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler.ClientHandshakeStateEvent; import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler.ServerHandshakeStateEvent; -import org.junit.Before; -import org.junit.Test; +import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.net.URI; import java.util.concurrent.CompletionException; +import org.junit.jupiter.api.Timeout; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class WebSocketHandshakeHandOverTest { @@ -66,7 +72,7 @@ public class WebSocketHandshakeHandOverTest { } } - @Before + @BeforeEach public void setUp() { serverReceivedHandshake = false; serverHandshakeComplete = null; @@ -124,7 +130,7 @@ public class WebSocketHandshakeHandOverTest { assertTrue(clientReceivedMessage); } - @Test(expected = WebSocketHandshakeException.class) + @Test public void testClientHandshakeTimeout() throws Throwable { EmbeddedChannel serverChannel = createServerChannel(new SimpleChannelInboundHandler() { @Override @@ -178,9 +184,9 @@ public class WebSocketHandshakeHandOverTest { assertFalse(clientReceivedMessage); // Should throw WebSocketHandshakeException try { - handshakeHandler.getHandshakeFuture().syncUninterruptibly(); - } catch (CompletionException e) { - throw e.getCause(); + assertTrue(assertThrows(CompletionException.class, + () -> handshakeHandler.getHandshakeFuture().syncUninterruptibly()) + .getCause() instanceof WebSocketHandshakeException); } finally { serverChannel.finishAndReleaseAll(); } @@ -220,7 +226,8 @@ public class WebSocketHandshakeHandOverTest { } } - @Test(timeout = 10000) + @Test + @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS) public void testClientHandshakerForceClose() throws Exception { final WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker( new URI("ws://localhost:1234/test"), WebSocketVersion.V13, null, true, diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketProtocolHandlerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketProtocolHandlerTest.java index 912bb16be3..f30d7928ec 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketProtocolHandlerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketProtocolHandlerTest.java @@ -26,13 +26,16 @@ import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.flow.FlowControlHandler; import io.netty.util.ReferenceCountUtil; import org.hamcrest.Matchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.atomic.AtomicReference; import static io.netty.util.CharsetUtil.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; -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.assertTrue; /** * Tests common, abstract class functionality in {@link WebSocketClientProtocolHandler}. diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00Test.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00Test.java index 95e2e76899..2283dc1b72 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00Test.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00Test.java @@ -30,12 +30,12 @@ import io.netty.handler.codec.http.HttpResponseDecoder; import io.netty.handler.codec.http.HttpResponseEncoder; import io.netty.handler.codec.http.LastHttpContent; import io.netty.util.CharsetUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; public class WebSocketServerHandshaker00Test extends WebSocketServerHandshakerTest { @@ -115,16 +115,16 @@ public class WebSocketServerHandshaker00Test extends WebSocketServerHandshakerTe ch2.writeInbound((ByteBuf) ch.readOutbound()); HttpResponse res = ch2.readInbound(); - Assert.assertEquals("ws://example.com/chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_LOCATION)); + assertEquals("ws://example.com/chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_LOCATION)); if (subProtocol) { - Assert.assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL)); + assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL)); } else { - Assert.assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL)); + assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL)); } LastHttpContent content = ch2.readInbound(); - Assert.assertEquals("8jKS'y:G*Co,Wxa-", content.content().toString(CharsetUtil.US_ASCII)); + assertEquals("8jKS'y:G*Co,Wxa-", content.content().toString(CharsetUtil.US_ASCII)); content.release(); req.release(); } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08Test.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08Test.java index 0b8ead2814..153d918759 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08Test.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08Test.java @@ -28,10 +28,11 @@ import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseDecoder; import io.netty.handler.codec.http.HttpResponseEncoder; import io.netty.util.ReferenceCountUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static io.netty.handler.codec.http.HttpVersion.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class WebSocketServerHandshaker08Test extends WebSocketServerHandshakerTest { @@ -83,12 +84,12 @@ public class WebSocketServerHandshaker08Test extends WebSocketServerHandshakerTe ch2.writeInbound(resBuf); HttpResponse res = ch2.readInbound(); - Assert.assertEquals( + assertEquals( "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT)); if (subProtocol) { - Assert.assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL)); + assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL)); } else { - Assert.assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL)); + assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL)); } ReferenceCountUtil.release(res); req.release(); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker13Test.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker13Test.java index 86de2c13d9..5dc6590a7f 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker13Test.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker13Test.java @@ -33,16 +33,16 @@ import io.netty.handler.codec.http.HttpServerCodec; import io.netty.util.ReferenceCountUtil; import io.netty.util.ReferenceCounted; import org.hamcrest.CoreMatchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Iterator; import static io.netty.handler.codec.http.HttpVersion.*; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +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.fail; public class WebSocketServerHandshaker13Test extends WebSocketServerHandshakerTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactoryTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactoryTest.java index e0f72701fc..f978e92220 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactoryTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactoryTest.java @@ -22,9 +22,12 @@ import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.util.ReferenceCountUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; -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.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class WebSocketServerHandshakerFactoryTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerTest.java index 159c596682..9d6e6638b6 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerTest.java @@ -24,9 +24,12 @@ import io.netty.handler.codec.http.HttpHeaderValues; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpVersion; -import org.junit.Test; +import org.junit.jupiter.api.Test; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public abstract class WebSocketServerHandshakerTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandlerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandlerTest.java index 6d949f055f..6ad2dc6087 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandlerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandlerTest.java @@ -34,21 +34,25 @@ import io.netty.handler.codec.http.HttpServerCodec; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.util.CharsetUtil; import io.netty.util.ReferenceCountUtil; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.ArrayDeque; import java.util.Queue; import static io.netty.handler.codec.http.HttpResponseStatus.*; import static io.netty.handler.codec.http.HttpVersion.*; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class WebSocketServerProtocolHandlerTest { private final Queue responses = new ArrayDeque<>(); - @Before + @BeforeEach public void setUp() { responses.clear(); } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketUtf8FrameValidatorTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketUtf8FrameValidatorTest.java index de74391788..42e900269a 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketUtf8FrameValidatorTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketUtf8FrameValidatorTest.java @@ -19,8 +19,14 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.codec.CorruptedFrameException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class WebSocketUtf8FrameValidatorTest { @@ -39,19 +45,19 @@ public class WebSocketUtf8FrameValidatorTest { TextWebSocketFrame frame = new TextWebSocketFrame(Unpooled.copiedBuffer(data)); try { channel.writeInbound(frame); - Assert.fail(); + fail(); } catch (CorruptedFrameException e) { // expected exception } - Assert.assertTrue(channel.finish()); + assertTrue(channel.finish()); ByteBuf buf = channel.readOutbound(); - Assert.assertNotNull(buf); + assertNotNull(buf); try { - Assert.assertFalse(buf.isReadable()); + assertFalse(buf.isReadable()); } finally { buf.release(); } - Assert.assertNull(channel.readOutbound()); - Assert.assertEquals(0, frame.refCnt()); + assertNull(channel.readOutbound()); + assertEquals(0, frame.refCnt()); } } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketUtilTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketUtilTest.java index f351dc0c18..6dc87e4c9d 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketUtilTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketUtilTest.java @@ -15,11 +15,11 @@ */ package io.netty.handler.codec.http.websocketx; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.ThreadLocalRandom; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class WebSocketUtilTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketClientExtensionHandlerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketClientExtensionHandlerTest.java index c75d21bf21..37295b20ae 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketClientExtensionHandlerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketClientExtensionHandlerTest.java @@ -24,10 +24,13 @@ import io.netty.handler.codec.http.HttpResponse; import java.util.Collections; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionTestUtil.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.any; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; @@ -218,7 +221,7 @@ public class WebSocketClientExtensionHandlerTest { verify(fallbackExtensionMock).newExtensionDecoder(); } - @Test(expected = CodecException.class) + @Test public void testIfMainAndFallbackUseRSV1WillFail() { // initialize when(mainHandshakerMock.newRequestData()). @@ -248,7 +251,12 @@ public class WebSocketClientExtensionHandlerTest { req2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS)); HttpResponse res = newUpgradeResponse("main, fallback"); - ch.writeInbound(res); + try { + ch.writeInbound(res); + } catch (CodecException e) { + return; + } + fail("Expected to encounter a CodecException"); // test assertEquals(2, reqExts.size()); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionFilterProviderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionFilterProviderTest.java index 96dff5e520..ef80950e14 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionFilterProviderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionFilterProviderTest.java @@ -15,9 +15,10 @@ */ package io.netty.handler.codec.http.websocketx.extensions; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class WebSocketExtensionFilterProviderTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionFilterTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionFilterTest.java index 0f3fa29db3..7eced821e8 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionFilterTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionFilterTest.java @@ -21,9 +21,10 @@ import io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame; import io.netty.handler.codec.http.websocketx.PingWebSocketFrame; import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class WebSocketExtensionFilterTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionUtilTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionUtilTest.java index eab3b3ba46..41345661cb 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionUtilTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionUtilTest.java @@ -19,12 +19,14 @@ import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaderValues; import io.netty.handler.codec.http.HttpHeaders; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; -import static org.junit.Assert.*; import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionUtil.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class WebSocketExtensionUtilTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketServerExtensionHandlerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketServerExtensionHandlerTest.java index 2f04ccf42d..d64a002f3b 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketServerExtensionHandlerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketServerExtensionHandlerTest.java @@ -25,10 +25,14 @@ import java.io.IOException; import java.util.Collections; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionTestUtil.*; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.*; public class WebSocketServerExtensionHandlerTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/DeflateFrameClientExtensionHandshakerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/DeflateFrameClientExtensionHandshakerTest.java index a3c21e2a42..e46e0854c7 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/DeflateFrameClientExtensionHandshakerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/DeflateFrameClientExtensionHandshakerTest.java @@ -17,7 +17,11 @@ package io.netty.handler.codec.http.websocketx.extensions.compression; import static io.netty.handler.codec.http.websocketx.extensions.compression. DeflateFrameServerExtensionHandshaker.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtension; import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData; @@ -25,7 +29,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class DeflateFrameClientExtensionHandshakerTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/DeflateFrameServerExtensionHandshakerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/DeflateFrameServerExtensionHandshakerTest.java index bf22ba3e67..64143cbe4c 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/DeflateFrameServerExtensionHandshakerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/DeflateFrameServerExtensionHandshakerTest.java @@ -17,7 +17,11 @@ package io.netty.handler.codec.http.websocketx.extensions.compression; import static io.netty.handler.codec.http.websocketx.extensions.compression. DeflateFrameServerExtensionHandshaker.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtension; import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData; @@ -25,7 +29,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class DeflateFrameServerExtensionHandshakerTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerFrameDeflateDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerFrameDeflateDecoderTest.java index 741a14e1e7..121fd2011b 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerFrameDeflateDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerFrameDeflateDecoderTest.java @@ -22,13 +22,17 @@ import io.netty.handler.codec.compression.ZlibCodecFactory; import io.netty.handler.codec.compression.ZlibWrapper; import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Random; import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension.*; import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class PerFrameDeflateDecoderTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerFrameDeflateEncoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerFrameDeflateEncoderTest.java index 982b26eb96..ceba96f8e7 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerFrameDeflateEncoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerFrameDeflateEncoderTest.java @@ -24,12 +24,16 @@ import io.netty.handler.codec.compression.ZlibWrapper; import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; import io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame; import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Random; import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class PerFrameDeflateEncoderTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateClientExtensionHandshakerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateClientExtensionHandshakerTest.java index d348c15722..d44244ed6e 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateClientExtensionHandshakerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateClientExtensionHandshakerTest.java @@ -18,7 +18,11 @@ package io.netty.handler.codec.http.websocketx.extensions.compression; import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension.RSV1; import static io.netty.handler.codec.http.websocketx.extensions.compression. PerMessageDeflateServerExtensionHandshaker.*; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import io.netty.buffer.Unpooled; import io.netty.channel.embedded.EmbeddedChannel; @@ -31,7 +35,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PerMessageDeflateClientExtensionHandshakerTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateDecoderTest.java index 68c785afd6..7f354669ba 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateDecoderTest.java @@ -28,14 +28,19 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension; import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Random; import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter.*; import static io.netty.handler.codec.http.websocketx.extensions.compression.DeflateDecoder.*; import static io.netty.util.CharsetUtil.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class PerMessageDeflateDecoderTest { @@ -260,7 +265,7 @@ public class PerMessageDeflateDecoderTest { assertFalse(decoderChannel.finish()); } - @Test(expected = DecoderException.class) + @Test public void testIllegalStateWhenDecompressionInProgress() { WebSocketExtensionFilter selectivityDecompressionFilter = frame -> frame.content().readableBytes() < 100; @@ -295,7 +300,7 @@ public class PerMessageDeflateDecoderTest { //final part throwing exception try { - decoderChannel.writeInbound(finalPart); + assertThrows(DecoderException.class, () -> decoderChannel.writeInbound(finalPart)); } finally { assertTrue(finalPart.release()); assertFalse(encoderChannel.finishAndReleaseAll()); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateEncoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateEncoderTest.java index 17d548adf6..97e41def27 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateEncoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateEncoderTest.java @@ -28,7 +28,7 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension; import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Random; @@ -36,7 +36,12 @@ import java.util.Random; import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter.*; import static io.netty.handler.codec.http.websocketx.extensions.compression.DeflateDecoder.*; import static io.netty.util.CharsetUtil.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class PerMessageDeflateEncoderTest { @@ -232,7 +237,7 @@ public class PerMessageDeflateEncoderTest { assertFalse(decoderChannel.finish()); } - @Test(expected = EncoderException.class) + @Test public void testIllegalStateWhenCompressionInProgress() { WebSocketExtensionFilter selectivityCompressionFilter = frame -> frame.content().readableBytes() < 100; EmbeddedChannel encoderChannel = new EmbeddedChannel( @@ -257,7 +262,7 @@ public class PerMessageDeflateEncoderTest { //final part throwing exception try { - encoderChannel.writeOutbound(finalPart); + assertThrows(EncoderException.class, () -> encoderChannel.writeOutbound(finalPart)); } finally { assertTrue(finalPart.release()); assertFalse(encoderChannel.finishAndReleaseAll()); @@ -281,14 +286,14 @@ public class PerMessageDeflateEncoderTest { assertFalse(encoderChannel.finish()); } - @Test(expected = EncoderException.class) + @Test public void testCodecExceptionForNotFinEmptyFrame() { EmbeddedChannel encoderChannel = new EmbeddedChannel(new PerMessageDeflateEncoder(9, 15, false)); TextWebSocketFrame emptyNotFinFrame = new TextWebSocketFrame(false, 0, ""); try { - encoderChannel.writeOutbound(emptyNotFinFrame); + assertThrows(EncoderException.class, () -> encoderChannel.writeOutbound(emptyNotFinFrame)); } finally { // EmptyByteBuf buffer assertFalse(emptyNotFinFrame.release()); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateServerExtensionHandshakerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateServerExtensionHandshakerTest.java index 4b930039ea..8a23a0a828 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateServerExtensionHandshakerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateServerExtensionHandshakerTest.java @@ -17,7 +17,11 @@ package io.netty.handler.codec.http.websocketx.extensions.compression; import static io.netty.handler.codec.http.websocketx.extensions.compression. PerMessageDeflateServerExtensionHandshaker.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtension; import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData; @@ -25,7 +29,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PerMessageDeflateServerExtensionHandshakerTest { diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/WebSocketServerCompressionHandlerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/WebSocketServerCompressionHandlerTest.java index a4c25b501f..ad3005f5b2 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/WebSocketServerCompressionHandlerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/WebSocketServerCompressionHandlerTest.java @@ -25,12 +25,16 @@ import io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensio import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static io.netty.handler.codec.http.websocketx.extensions.compression. PerMessageDeflateServerExtensionHandshaker.*; import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionTestUtil.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class WebSocketServerCompressionHandlerTest { @@ -48,10 +52,10 @@ public class WebSocketServerCompressionHandlerTest { List exts = WebSocketExtensionUtil.extractExtensions( res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS)); - Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name()); - Assert.assertTrue(exts.get(0).parameters().isEmpty()); - Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); - Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); + assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name()); + assertTrue(exts.get(0).parameters().isEmpty()); + assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); + assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); } @Test @@ -69,10 +73,10 @@ public class WebSocketServerCompressionHandlerTest { List exts = WebSocketExtensionUtil.extractExtensions( res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS)); - Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name()); - Assert.assertEquals("10", exts.get(0).parameters().get(CLIENT_MAX_WINDOW)); - Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); - Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); + assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name()); + assertEquals("10", exts.get(0).parameters().get(CLIENT_MAX_WINDOW)); + assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); + assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); } @Test @@ -90,10 +94,10 @@ public class WebSocketServerCompressionHandlerTest { List exts = WebSocketExtensionUtil.extractExtensions( res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS)); - Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name()); - Assert.assertTrue(exts.get(0).parameters().isEmpty()); - Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); - Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); + assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name()); + assertTrue(exts.get(0).parameters().isEmpty()); + assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); + assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); } @Test @@ -111,10 +115,10 @@ public class WebSocketServerCompressionHandlerTest { List exts = WebSocketExtensionUtil.extractExtensions( res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS)); - Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name()); - Assert.assertEquals("10", exts.get(0).parameters().get(SERVER_MAX_WINDOW)); - Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); - Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); + assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name()); + assertEquals("10", exts.get(0).parameters().get(SERVER_MAX_WINDOW)); + assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); + assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); } @Test @@ -130,9 +134,9 @@ public class WebSocketServerCompressionHandlerTest { HttpResponse res2 = ch.readOutbound(); - Assert.assertFalse(res2.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS)); - Assert.assertNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); - Assert.assertNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); + assertFalse(res2.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS)); + assertNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); + assertNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); } @Test @@ -147,9 +151,9 @@ public class WebSocketServerCompressionHandlerTest { HttpResponse res2 = ch.readOutbound(); - Assert.assertFalse(res2.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS)); - Assert.assertNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); - Assert.assertNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); + assertFalse(res2.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS)); + assertNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); + assertNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); } @Test @@ -166,10 +170,10 @@ public class WebSocketServerCompressionHandlerTest { List exts = WebSocketExtensionUtil.extractExtensions( res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS)); - Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name()); - Assert.assertTrue(exts.get(0).parameters().isEmpty()); - Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); - Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); + assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name()); + assertTrue(exts.get(0).parameters().isEmpty()); + assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); + assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); } @Test @@ -188,10 +192,10 @@ public class WebSocketServerCompressionHandlerTest { List exts = WebSocketExtensionUtil.extractExtensions( res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS)); - Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name()); - Assert.assertTrue(exts.get(0).parameters().isEmpty()); - Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); - Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); + assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name()); + assertTrue(exts.get(0).parameters().isEmpty()); + assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class)); + assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class)); } }