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:
parent
6ffb001caf
commit
a63a4d99e0
@ -42,12 +42,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 {
|
||||||
|
@ -47,13 +47,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;
|
||||||
@ -69,9 +67,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);
|
||||||
@ -136,7 +133,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(
|
||||||
@ -423,32 +419,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();
|
||||||
|
Loading…
Reference in New Issue
Block a user