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
This commit is contained in:
Riley Park 2021-05-26 01:36:59 -07:00 committed by GitHub
parent a1e672b5f5
commit 7a5d9db0ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 23 deletions

View File

@ -43,12 +43,15 @@ import io.netty.handler.proxy.HttpProxyHandler.HttpProxyConnectException;
import io.netty.util.NetUtil; import io.netty.util.NetUtil;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; 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.*; import static org.mockito.Mockito.*;
public class HttpProxyHandlerTest { public class HttpProxyHandlerTest {

View File

@ -48,13 +48,11 @@ import io.netty.util.internal.EmptyArrays;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.After; import org.junit.jupiter.api.AfterAll;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.ArrayList; import java.util.ArrayList;
@ -70,9 +68,8 @@ import java.util.Random;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat; 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 { public class ProxyHandlerTest {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(ProxyHandlerTest.class); 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 // look for "Seed used: *" debug message in test logs
private static final long reproducibleSeed = 0L; private static final long reproducibleSeed = 0L;
@Parameters(name = "{index}: {0}")
public static List<Object[]> testItems() { public static List<Object[]> testItems() {
List<TestItem> items = Arrays.asList( List<TestItem> items = Arrays.asList(
@ -425,32 +421,27 @@ public class ProxyHandlerTest {
return params; return params;
} }
@AfterClass @AfterAll
public static void stopServers() { public static void stopServers() {
for (ProxyServer p: allProxies) { for (ProxyServer p: allProxies) {
p.stop(); p.stop();
} }
} }
private final TestItem testItem; @BeforeEach
public ProxyHandlerTest(TestItem testItem) {
this.testItem = testItem;
}
@Before
public void clearServerExceptions() throws Exception { public void clearServerExceptions() throws Exception {
for (ProxyServer p: allProxies) { for (ProxyServer p: allProxies) {
p.clearExceptions(); p.clearExceptions();
} }
} }
@Test @ParameterizedTest(name = "{index}: {0}")
public void test() throws Exception { @MethodSource("testItems")
public void test(TestItem testItem) throws Exception {
testItem.test(); testItem.test();
} }
@After @AfterEach
public void checkServerExceptions() throws Exception { public void checkServerExceptions() throws Exception {
for (ProxyServer p: allProxies) { for (ProxyServer p: allProxies) {
p.checkExceptions(); p.checkExceptions();