From 7a5d9db0ec416aa1a8de8a8c065232b7dc9f9c12 Mon Sep 17 00:00:00 2001 From: Riley Park Date: Wed, 26 May 2021 01:36:59 -0700 Subject: [PATCH] Migrate handler-proxy tests to JUnit 5 (#11313) Motivation: JUnit 5 is more expressive, extensible, and composable in many ways, and it's better able to run tests in parallel. Modifications: Use JUnit5 in handler-proxy tests Result: Related to https://github.com/netty/netty/issues/10757 --- .../handler/proxy/HttpProxyHandlerTest.java | 7 ++-- .../netty/handler/proxy/ProxyHandlerTest.java | 33 +++++++------------ 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/handler-proxy/src/test/java/io/netty/handler/proxy/HttpProxyHandlerTest.java b/handler-proxy/src/test/java/io/netty/handler/proxy/HttpProxyHandlerTest.java index a782f68be7..64a6396f1a 100644 --- a/handler-proxy/src/test/java/io/netty/handler/proxy/HttpProxyHandlerTest.java +++ b/handler-proxy/src/test/java/io/netty/handler/proxy/HttpProxyHandlerTest.java @@ -43,12 +43,15 @@ import io.netty.handler.proxy.HttpProxyHandler.HttpProxyConnectException; import io.netty.util.NetUtil; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.InetAddress; import java.net.InetSocketAddress; -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 static org.mockito.Mockito.*; public class HttpProxyHandlerTest { diff --git a/handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java b/handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java index 2067716054..44c32ca04c 100644 --- a/handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java +++ b/handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java @@ -48,13 +48,11 @@ import io.netty.util.internal.EmptyArrays; import io.netty.util.internal.StringUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.net.InetSocketAddress; import java.util.ArrayList; @@ -70,9 +68,8 @@ import java.util.Random; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.fail; -@RunWith(Parameterized.class) public class ProxyHandlerTest { private static final InternalLogger logger = InternalLoggerFactory.getInstance(ProxyHandlerTest.class); @@ -138,7 +135,6 @@ public class ProxyHandlerTest { // look for "Seed used: *" debug message in test logs private static final long reproducibleSeed = 0L; - @Parameters(name = "{index}: {0}") public static List testItems() { List items = Arrays.asList( @@ -425,32 +421,27 @@ public class ProxyHandlerTest { return params; } - @AfterClass + @AfterAll public static void stopServers() { for (ProxyServer p: allProxies) { p.stop(); } } - private final TestItem testItem; - - public ProxyHandlerTest(TestItem testItem) { - this.testItem = testItem; - } - - @Before + @BeforeEach public void clearServerExceptions() throws Exception { for (ProxyServer p: allProxies) { p.clearExceptions(); } } - @Test - public void test() throws Exception { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("testItems") + public void test(TestItem testItem) throws Exception { testItem.test(); } - @After + @AfterEach public void checkServerExceptions() throws Exception { for (ProxyServer p: allProxies) { p.checkExceptions();