Skip to content

Commit ee6587d

Browse files
authored
Migrate tests to JUnit 5 (#1830)
* Migrate tests to JUnit 5 * Use Amazon Corretto JDK 11
1 parent 67cc582 commit ee6587d

File tree

128 files changed

+2405
-3977
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+2405
-3977
lines changed

.github/workflows/maven.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v3
20+
- uses: actions/setup-java@v3
21+
with:
22+
distribution: 'corretto'
23+
java-version: '11'
2024
- name: Run Tests
2125
run: mvn -B -ntp clean test

client/src/main/java/org/asynchttpclient/request/body/multipart/FileLikePart.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ public abstract class FileLikePart extends PartBase {
4444
* FilePart Constructor.
4545
*
4646
* @param name the name for this part
47-
* @param contentType the content type for this part, if <code>null</code> try to figure out from the fileName mime type
47+
* @param contentType the content type for this part, if {@code null} try to figure out from the fileName mime type
4848
* @param charset the charset encoding for this part
4949
* @param fileName the fileName
5050
* @param contentId the content id
5151
* @param transferEncoding the transfer encoding
5252
*/
53-
public FileLikePart(String name, String contentType, Charset charset, String fileName, String contentId, String transferEncoding) {
53+
protected FileLikePart(String name, String contentType, Charset charset, String fileName, String contentId, String transferEncoding) {
5454
super(name,
5555
computeContentType(contentType, fileName),
5656
charset,

client/src/main/java/org/asynchttpclient/request/body/multipart/FilePart.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import java.io.File;
1616
import java.nio.charset.Charset;
1717

18-
import static org.asynchttpclient.util.Assertions.assertNotNull;
19-
2018
public class FilePart extends FileLikePart {
2119

2220
private final File file;
@@ -55,6 +53,10 @@ public FilePart(String name, File file, String contentType, Charset charset, Str
5553
this.file = file;
5654
}
5755

56+
private File assertNotNull(File file, String file1) {
57+
return null;
58+
}
59+
5860
public File getFile() {
5961
return file;
6062
}

client/src/main/java/org/asynchttpclient/util/Assertions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ public static <T> T assertNotNull(T value, String name) {
2727

2828
public static String assertNotEmpty(String value, String name) {
2929
assertNotNull(value, name);
30-
if (value.length() == 0)
30+
if (value.length() == 0) {
3131
throw new IllegalArgumentException("empty " + name);
32+
}
3233
return value;
3334
}
3435
}

client/src/test/java/org/asynchttpclient/AbstractBasicTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@
1919
import org.eclipse.jetty.server.Server;
2020
import org.eclipse.jetty.server.ServerConnector;
2121
import org.eclipse.jetty.server.handler.AbstractHandler;
22+
import org.junit.jupiter.api.AfterAll;
23+
import org.junit.jupiter.api.BeforeAll;
2224
import org.slf4j.Logger;
2325
import org.slf4j.LoggerFactory;
24-
import org.testng.annotations.AfterClass;
25-
import org.testng.annotations.BeforeClass;
2626

2727
import static org.asynchttpclient.test.TestUtils.addHttpConnector;
2828

2929
public abstract class AbstractBasicTest {
3030

31-
protected static final int TIMEOUT = 30;
31+
protected static final Logger logger = LoggerFactory.getLogger(AbstractBasicTest.class);
3232

33-
protected final Logger logger = LoggerFactory.getLogger(getClass());
33+
protected static final int TIMEOUT = 30;
3434

35-
protected Server server;
36-
protected int port1 = -1;
37-
protected int port2 = -1;
35+
protected static Server server;
36+
protected static int port1 = -1;
37+
protected static int port2 = -1;
3838

39-
@BeforeClass(alwaysRun = true)
40-
public void setUpGlobal() throws Exception {
39+
@BeforeAll
40+
public static void setUpGlobal() throws Exception {
4141
server = new Server();
4242
ServerConnector connector1 = addHttpConnector(server);
4343
server.setHandler(configureHandler());
@@ -50,22 +50,22 @@ public void setUpGlobal() throws Exception {
5050
logger.info("Local HTTP server started successfully");
5151
}
5252

53-
@AfterClass(alwaysRun = true)
54-
public void tearDownGlobal() throws Exception {
53+
@AfterAll
54+
public static void tearDownGlobal() throws Exception {
5555
if (server != null) {
5656
server.stop();
5757
}
5858
}
5959

60-
protected String getTargetUrl() {
60+
protected static String getTargetUrl() {
6161
return String.format("http://localhost:%d/foo/test", port1);
6262
}
6363

6464
protected String getTargetUrl2() {
6565
return String.format("https://localhost:%d/foo/test", port2);
6666
}
6767

68-
public AbstractHandler configureHandler() throws Exception {
68+
public static AbstractHandler configureHandler() throws Exception {
6969
return new EchoHandler();
7070
}
7171

client/src/test/java/org/asynchttpclient/AsyncHttpClientDefaultsTest.java

Lines changed: 62 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,113 +15,135 @@
1515

1616
import org.asynchttpclient.config.AsyncHttpClientConfigDefaults;
1717
import org.asynchttpclient.config.AsyncHttpClientConfigHelper;
18-
import org.testng.Assert;
19-
import org.testng.annotations.Test;
18+
import org.junit.jupiter.api.Test;
2019

2120
import java.lang.reflect.Method;
2221

2322
import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.ASYNC_CLIENT_CONFIG_ROOT;
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertFalse;
25+
import static org.junit.jupiter.api.Assertions.assertTrue;
26+
import static org.junit.jupiter.api.Assertions.fail;
2427

25-
@Test
2628
public class AsyncHttpClientDefaultsTest {
2729

30+
@Test
2831
public void testDefaultMaxTotalConnections() {
29-
Assert.assertEquals(AsyncHttpClientConfigDefaults.defaultMaxConnections(), -1);
32+
assertEquals(AsyncHttpClientConfigDefaults.defaultMaxConnections(), -1);
3033
testIntegerSystemProperty("maxConnections", "defaultMaxConnections", "100");
3134
}
3235

36+
@Test
3337
public void testDefaultMaxConnectionPerHost() {
34-
Assert.assertEquals(AsyncHttpClientConfigDefaults.defaultMaxConnectionsPerHost(), -1);
38+
assertEquals(AsyncHttpClientConfigDefaults.defaultMaxConnectionsPerHost(), -1);
3539
testIntegerSystemProperty("maxConnectionsPerHost", "defaultMaxConnectionsPerHost", "100");
3640
}
3741

42+
@Test
3843
public void testDefaultConnectTimeOut() {
39-
Assert.assertEquals(AsyncHttpClientConfigDefaults.defaultConnectTimeout(), 5 * 1000);
44+
assertEquals(AsyncHttpClientConfigDefaults.defaultConnectTimeout(), 5 * 1000);
4045
testIntegerSystemProperty("connectTimeout", "defaultConnectTimeout", "100");
4146
}
4247

48+
@Test
4349
public void testDefaultPooledConnectionIdleTimeout() {
44-
Assert.assertEquals(AsyncHttpClientConfigDefaults.defaultPooledConnectionIdleTimeout(), 60 * 1000);
50+
assertEquals(AsyncHttpClientConfigDefaults.defaultPooledConnectionIdleTimeout(), 60 * 1000);
4551
testIntegerSystemProperty("pooledConnectionIdleTimeout", "defaultPooledConnectionIdleTimeout", "100");
4652
}
4753

54+
@Test
4855
public void testDefaultReadTimeout() {
49-
Assert.assertEquals(AsyncHttpClientConfigDefaults.defaultReadTimeout(), 60 * 1000);
56+
assertEquals(AsyncHttpClientConfigDefaults.defaultReadTimeout(), 60 * 1000);
5057
testIntegerSystemProperty("readTimeout", "defaultReadTimeout", "100");
5158
}
5259

60+
@Test
5361
public void testDefaultRequestTimeout() {
54-
Assert.assertEquals(AsyncHttpClientConfigDefaults.defaultRequestTimeout(), 60 * 1000);
62+
assertEquals(AsyncHttpClientConfigDefaults.defaultRequestTimeout(), 60 * 1000);
5563
testIntegerSystemProperty("requestTimeout", "defaultRequestTimeout", "100");
5664
}
5765

66+
@Test
5867
public void testDefaultConnectionTtl() {
59-
Assert.assertEquals(AsyncHttpClientConfigDefaults.defaultConnectionTtl(), -1);
68+
assertEquals(AsyncHttpClientConfigDefaults.defaultConnectionTtl(), -1);
6069
testIntegerSystemProperty("connectionTtl", "defaultConnectionTtl", "100");
6170
}
6271

72+
@Test
6373
public void testDefaultFollowRedirect() {
64-
Assert.assertFalse(AsyncHttpClientConfigDefaults.defaultFollowRedirect());
74+
assertFalse(AsyncHttpClientConfigDefaults.defaultFollowRedirect());
6575
testBooleanSystemProperty("followRedirect", "defaultFollowRedirect", "true");
6676
}
6777

78+
@Test
6879
public void testDefaultMaxRedirects() {
69-
Assert.assertEquals(AsyncHttpClientConfigDefaults.defaultMaxRedirects(), 5);
80+
assertEquals(AsyncHttpClientConfigDefaults.defaultMaxRedirects(), 5);
7081
testIntegerSystemProperty("maxRedirects", "defaultMaxRedirects", "100");
7182
}
7283

84+
@Test
7385
public void testDefaultCompressionEnforced() {
74-
Assert.assertFalse(AsyncHttpClientConfigDefaults.defaultCompressionEnforced());
86+
assertFalse(AsyncHttpClientConfigDefaults.defaultCompressionEnforced());
7587
testBooleanSystemProperty("compressionEnforced", "defaultCompressionEnforced", "true");
7688
}
7789

90+
@Test
7891
public void testDefaultUserAgent() {
79-
Assert.assertEquals(AsyncHttpClientConfigDefaults.defaultUserAgent(), "AHC/2.1");
92+
assertEquals(AsyncHttpClientConfigDefaults.defaultUserAgent(), "AHC/2.1");
8093
testStringSystemProperty("userAgent", "defaultUserAgent", "MyAHC");
8194
}
8295

96+
@Test
8397
public void testDefaultUseProxySelector() {
84-
Assert.assertFalse(AsyncHttpClientConfigDefaults.defaultUseProxySelector());
98+
assertFalse(AsyncHttpClientConfigDefaults.defaultUseProxySelector());
8599
testBooleanSystemProperty("useProxySelector", "defaultUseProxySelector", "true");
86100
}
87101

102+
@Test
88103
public void testDefaultUseProxyProperties() {
89-
Assert.assertFalse(AsyncHttpClientConfigDefaults.defaultUseProxyProperties());
104+
assertFalse(AsyncHttpClientConfigDefaults.defaultUseProxyProperties());
90105
testBooleanSystemProperty("useProxyProperties", "defaultUseProxyProperties", "true");
91106
}
92107

108+
@Test
93109
public void testDefaultStrict302Handling() {
94-
Assert.assertFalse(AsyncHttpClientConfigDefaults.defaultStrict302Handling());
110+
assertFalse(AsyncHttpClientConfigDefaults.defaultStrict302Handling());
95111
testBooleanSystemProperty("strict302Handling", "defaultStrict302Handling", "true");
96112
}
97113

114+
@Test
98115
public void testDefaultAllowPoolingConnection() {
99-
Assert.assertTrue(AsyncHttpClientConfigDefaults.defaultKeepAlive());
116+
assertTrue(AsyncHttpClientConfigDefaults.defaultKeepAlive());
100117
testBooleanSystemProperty("keepAlive", "defaultKeepAlive", "false");
101118
}
102119

120+
@Test
103121
public void testDefaultMaxRequestRetry() {
104-
Assert.assertEquals(AsyncHttpClientConfigDefaults.defaultMaxRequestRetry(), 5);
122+
assertEquals(AsyncHttpClientConfigDefaults.defaultMaxRequestRetry(), 5);
105123
testIntegerSystemProperty("maxRequestRetry", "defaultMaxRequestRetry", "100");
106124
}
107125

126+
@Test
108127
public void testDefaultDisableUrlEncodingForBoundRequests() {
109-
Assert.assertFalse(AsyncHttpClientConfigDefaults.defaultDisableUrlEncodingForBoundRequests());
128+
assertFalse(AsyncHttpClientConfigDefaults.defaultDisableUrlEncodingForBoundRequests());
110129
testBooleanSystemProperty("disableUrlEncodingForBoundRequests", "defaultDisableUrlEncodingForBoundRequests", "true");
111130
}
112131

132+
@Test
113133
public void testDefaultUseInsecureTrustManager() {
114-
Assert.assertFalse(AsyncHttpClientConfigDefaults.defaultUseInsecureTrustManager());
134+
assertFalse(AsyncHttpClientConfigDefaults.defaultUseInsecureTrustManager());
115135
testBooleanSystemProperty("useInsecureTrustManager", "defaultUseInsecureTrustManager", "false");
116136
}
117137

138+
@Test
118139
public void testDefaultHashedWheelTimerTickDuration() {
119-
Assert.assertEquals(AsyncHttpClientConfigDefaults.defaultHashedWheelTimerTickDuration(), 100);
140+
assertEquals(AsyncHttpClientConfigDefaults.defaultHashedWheelTimerTickDuration(), 100);
120141
testIntegerSystemProperty("hashedWheelTimerTickDuration", "defaultHashedWheelTimerTickDuration", "100");
121142
}
122143

144+
@Test
123145
public void testDefaultHashedWheelTimerSize() {
124-
Assert.assertEquals(AsyncHttpClientConfigDefaults.defaultHashedWheelTimerSize(), 512);
146+
assertEquals(AsyncHttpClientConfigDefaults.defaultHashedWheelTimerSize(), 512);
125147
testIntegerSystemProperty("hashedWheelTimerSize", "defaultHashedWheelTimerSize", "512");
126148
}
127149

@@ -131,45 +153,48 @@ private void testIntegerSystemProperty(String propertyName, String methodName, S
131153
AsyncHttpClientConfigHelper.reloadProperties();
132154
try {
133155
Method method = AsyncHttpClientConfigDefaults.class.getMethod(methodName);
134-
Assert.assertEquals(method.invoke(null), Integer.parseInt(value));
156+
assertEquals(method.invoke(null), Integer.parseInt(value));
135157
} catch (Exception e) {
136-
Assert.fail("Couldn't find or execute method : " + methodName, e);
158+
fail("Couldn't find or execute method : " + methodName, e);
137159
}
138-
if (previous != null)
160+
if (previous != null) {
139161
System.setProperty(ASYNC_CLIENT_CONFIG_ROOT + propertyName, previous);
140-
else
162+
} else {
141163
System.clearProperty(ASYNC_CLIENT_CONFIG_ROOT + propertyName);
164+
}
142165
}
143166

144-
private void testBooleanSystemProperty(String propertyName, String methodName, String value) {
167+
private static void testBooleanSystemProperty(String propertyName, String methodName, String value) {
145168
String previous = System.getProperty(ASYNC_CLIENT_CONFIG_ROOT + propertyName);
146169
System.setProperty(ASYNC_CLIENT_CONFIG_ROOT + propertyName, value);
147170
AsyncHttpClientConfigHelper.reloadProperties();
148171
try {
149172
Method method = AsyncHttpClientConfigDefaults.class.getMethod(methodName);
150-
Assert.assertEquals(method.invoke(null), Boolean.parseBoolean(value));
173+
assertEquals(method.invoke(null), Boolean.parseBoolean(value));
151174
} catch (Exception e) {
152-
Assert.fail("Couldn't find or execute method : " + methodName, e);
175+
fail("Couldn't find or execute method : " + methodName, e);
153176
}
154-
if (previous != null)
177+
if (previous != null) {
155178
System.setProperty(ASYNC_CLIENT_CONFIG_ROOT + propertyName, previous);
156-
else
179+
} else {
157180
System.clearProperty(ASYNC_CLIENT_CONFIG_ROOT + propertyName);
181+
}
158182
}
159183

160-
private void testStringSystemProperty(String propertyName, String methodName, String value) {
184+
private static void testStringSystemProperty(String propertyName, String methodName, String value) {
161185
String previous = System.getProperty(ASYNC_CLIENT_CONFIG_ROOT + propertyName);
162186
System.setProperty(ASYNC_CLIENT_CONFIG_ROOT + propertyName, value);
163187
AsyncHttpClientConfigHelper.reloadProperties();
164188
try {
165189
Method method = AsyncHttpClientConfigDefaults.class.getMethod(methodName);
166-
Assert.assertEquals(method.invoke(null), value);
190+
assertEquals(method.invoke(null), value);
167191
} catch (Exception e) {
168-
Assert.fail("Couldn't find or execute method : " + methodName, e);
192+
fail("Couldn't find or execute method : " + methodName, e);
169193
}
170-
if (previous != null)
194+
if (previous != null) {
171195
System.setProperty(ASYNC_CLIENT_CONFIG_ROOT + propertyName, previous);
172-
else
196+
} else {
173197
System.clearProperty(ASYNC_CLIENT_CONFIG_ROOT + propertyName);
198+
}
174199
}
175200
}

0 commit comments

Comments
 (0)