Skip to content

Commit 93c5f7c

Browse files
antbobjerboaa
authored andcommittedFeb 26, 2024
8326503: [11u] java/net/HttpURLConnection/HttpURLConnectionExpectContinueTest.java fail because of package org.junit.jupiter.api does not exist
Reviewed-by: sgehwolf
1 parent 8dc2892 commit 93c5f7c

File tree

1 file changed

+48
-60
lines changed

1 file changed

+48
-60
lines changed
 

‎test/jdk/java/net/HttpURLConnection/HttpURLConnectionExpectContinueTest.java

+48-60
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@
2929
* @run junit/othervm HttpURLConnectionExpectContinueTest
3030
*/
3131

32-
import org.junit.jupiter.api.AfterAll;
33-
import org.junit.jupiter.api.BeforeAll;
34-
import org.junit.jupiter.api.Test;
35-
import org.junit.jupiter.api.TestInstance;
32+
import org.junit.AfterClass;
33+
import org.junit.BeforeClass;
34+
import org.junit.Test;
3635

3736
import java.io.IOException;
3837
import java.io.InputStream;
@@ -44,32 +43,31 @@
4443
import java.util.logging.Level;
4544
import java.util.logging.Logger;
4645

47-
import static org.junit.jupiter.api.Assertions.assertTrue;
46+
import static org.junit.Assert.assertTrue;
4847

49-
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
5048
public class HttpURLConnectionExpectContinueTest {
5149

52-
class Control {
50+
private static class Control {
5351
volatile ServerSocket serverSocket = null;
5452
volatile boolean stop = false;
5553
volatile boolean respondWith100Continue = false;
5654
volatile boolean write100ContinueTwice = false;
5755
volatile String response = null;
5856
}
5957

60-
private Thread serverThread = null;
61-
private volatile Control control;
58+
private static Thread serverThread = null;
59+
private static volatile Control control;
6260
static final Logger logger;
6361

6462
static {
63+
control = new Control();
6564
logger = Logger.getLogger("sun.net.www.protocol.http.HttpURLConnection");
6665
logger.setLevel(Level.ALL);
6766
Logger.getLogger("").getHandlers()[0].setLevel(Level.ALL);
6867
}
6968

70-
@BeforeAll
71-
public void startServerSocket() throws Exception {
72-
Control control = this.control = new Control();
69+
@BeforeClass
70+
public static void startServerSocket() throws Exception {
7371

7472
control.serverSocket = new ServerSocket();
7573
control.serverSocket.setReuseAddress(true);
@@ -170,9 +168,8 @@ public void startServerSocket() throws Exception {
170168
serverThread.start();
171169
}
172170

173-
@AfterAll
174-
public void stopServerSocket() throws Exception {
175-
Control control = this.control;
171+
@AfterClass
172+
public static void stopServerSocket() throws Exception {
176173
control.stop = true;
177174
control.serverSocket.close();
178175
serverThread.join();
@@ -181,7 +178,6 @@ public void stopServerSocket() throws Exception {
181178
@Test
182179
public void testNonChunkedRequestAndNoExpect100ContinueResponse() throws Exception {
183180
String body = "testNonChunkedRequestAndNoExpect100ContinueResponse";
184-
Control control = this.control;
185181
control.response = "HTTP/1.1 200 OK\r\n" +
186182
"Connection: close\r\n" +
187183
"Content-Length: " + body.length() + "\r\n" +
@@ -198,16 +194,15 @@ public void testNonChunkedRequestAndNoExpect100ContinueResponse() throws Excepti
198194
int responseCode = connection.getResponseCode();
199195
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
200196
System.err.println("response body: " + responseBody);
201-
assertTrue(responseCode == 200,
202-
String.format("Expected 200 response, instead received %s", responseCode));
203-
assertTrue(body.equals(responseBody),
204-
String.format("Expected response %s, instead received %s", body, responseBody));
197+
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
198+
responseCode == 200);
199+
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
200+
body.equals(responseBody));
205201
}
206202

207203
@Test
208204
public void testNonChunkedRequestWithExpect100ContinueResponse() throws Exception {
209205
String body = "testNonChunkedRequestWithExpect100ContinueResponse";
210-
Control control = this.control;
211206
control.response = "HTTP/1.1 200 OK\r\n" +
212207
"Connection: close\r\n" +
213208
"Content-Length: " + body.length() + "\r\n" +
@@ -224,16 +219,15 @@ public void testNonChunkedRequestWithExpect100ContinueResponse() throws Exceptio
224219
int responseCode = connection.getResponseCode();
225220
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
226221
System.err.println("response body: " + responseBody);
227-
assertTrue(responseCode == 200,
228-
String.format("Expected 200 response, instead received %s", responseCode));
229-
assertTrue(body.equals(responseBody),
230-
String.format("Expected response %s, instead received %s", body, responseBody));
222+
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
223+
responseCode == 200);
224+
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
225+
body.equals(responseBody));
231226
}
232227

233228
@Test
234229
public void testNonChunkedRequestWithDoubleExpect100ContinueResponse() throws Exception {
235230
String body = "testNonChunkedRequestWithDoubleExpect100ContinueResponse";
236-
Control control = this.control;
237231
control.response = "HTTP/1.1 200 OK\r\n" +
238232
"Connection: close\r\n" +
239233
"Content-Length: " + body.length() + "\r\n" +
@@ -250,16 +244,15 @@ public void testNonChunkedRequestWithDoubleExpect100ContinueResponse() throws Ex
250244
int responseCode = connection.getResponseCode();
251245
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
252246
System.err.println("response body: " + responseBody);
253-
assertTrue(responseCode == 200,
254-
String.format("Expected 200 response, instead received %s", responseCode));
255-
assertTrue(body.equals(responseBody),
256-
String.format("Expected response %s, instead received %s", body, responseBody));
247+
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
248+
responseCode == 200);
249+
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
250+
body.equals(responseBody));
257251
}
258252

259253
@Test
260254
public void testChunkedRequestAndNoExpect100ContinueResponse() throws Exception {
261255
String body = "testChunkedRequestAndNoExpect100ContinueResponse";
262-
Control control = this.control;
263256
control.response = "HTTP/1.1 200 OK\r\n" +
264257
"Connection: close\r\n" +
265258
"Content-Length: " + body.length() + "\r\n" +
@@ -277,16 +270,15 @@ public void testChunkedRequestAndNoExpect100ContinueResponse() throws Exception
277270
int responseCode = connection.getResponseCode();
278271
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
279272
System.err.println("response body: " + responseBody);
280-
assertTrue(responseCode == 200,
281-
String.format("Expected 200 response, instead received %s", responseCode));
282-
assertTrue(body.equals(responseBody),
283-
String.format("Expected response %s, instead received %s", body, responseBody));
273+
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
274+
responseCode == 200);
275+
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
276+
body.equals(responseBody));
284277
}
285278

286279
@Test
287280
public void testChunkedRequestWithExpect100ContinueResponse() throws Exception {
288281
String body = "testChunkedRequestWithExpect100ContinueResponse";
289-
Control control = this.control;
290282
control.response = "HTTP/1.1 200 OK\r\n" +
291283
"Connection: close\r\n" +
292284
"Content-Length: " + body.length() + "\r\n" +
@@ -304,16 +296,15 @@ public void testChunkedRequestWithExpect100ContinueResponse() throws Exception {
304296
int responseCode = connection.getResponseCode();
305297
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
306298
System.err.println("response body: " + responseBody);
307-
assertTrue(responseCode == 200,
308-
String.format("Expected 200 response, instead received %s", responseCode));
309-
assertTrue(body.equals(responseBody),
310-
String.format("Expected response %s, instead received %s", body, responseBody));
299+
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
300+
responseCode == 200);
301+
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
302+
body.equals(responseBody));
311303
}
312304

313305
@Test
314306
public void testChunkedRequestWithDoubleExpect100ContinueResponse() throws Exception {
315307
String body = "testChunkedRequestWithDoubleExpect100ContinueResponse";
316-
Control control = this.control;
317308
control.response = "HTTP/1.1 200 OK\r\n" +
318309
"Connection: close\r\n" +
319310
"Content-Length: " + body.length() + "\r\n" +
@@ -331,16 +322,15 @@ public void testChunkedRequestWithDoubleExpect100ContinueResponse() throws Excep
331322
int responseCode = connection.getResponseCode();
332323
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
333324
System.err.println("response body: " + responseBody);
334-
assertTrue(responseCode == 200,
335-
String.format("Expected 200 response, instead received %s", responseCode));
336-
assertTrue(body.equals(responseBody),
337-
String.format("Expected response %s, instead received %s", body, responseBody));
325+
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
326+
responseCode == 200);
327+
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
328+
body.equals(responseBody));
338329
}
339330

340331
@Test
341332
public void testFixedLengthRequestAndNoExpect100ContinueResponse() throws Exception {
342333
String body = "testFixedLengthRequestAndNoExpect100ContinueResponse";
343-
Control control = this.control;
344334
control.response = "HTTP/1.1 200 OK\r\n" +
345335
"Connection: close\r\n" +
346336
"Content-Length: " + body.length() + "\r\n" +
@@ -358,16 +348,15 @@ public void testFixedLengthRequestAndNoExpect100ContinueResponse() throws Except
358348
int responseCode = connection.getResponseCode();
359349
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
360350
System.err.println("response body: " + responseBody);
361-
assertTrue(responseCode == 200,
362-
String.format("Expected 200 response, instead received %s", responseCode));
363-
assertTrue(body.equals(responseBody),
364-
String.format("Expected response %s, instead received %s", body, responseBody));
351+
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
352+
responseCode == 200);
353+
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
354+
body.equals(responseBody));
365355
}
366356

367357
@Test
368358
public void testFixedLengthRequestWithExpect100ContinueResponse() throws Exception {
369359
String body = "testFixedLengthRequestWithExpect100ContinueResponse";
370-
Control control = this.control;
371360
control.response = "HTTP/1.1 200 OK\r\n" +
372361
"Connection: close\r\n" +
373362
"Content-Length: " + body.length() + "\r\n" +
@@ -385,16 +374,15 @@ public void testFixedLengthRequestWithExpect100ContinueResponse() throws Excepti
385374
int responseCode = connection.getResponseCode();
386375
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
387376
System.err.println("response body: " + responseBody);
388-
assertTrue(responseCode == 200,
389-
String.format("Expected 200 response, instead received %s", responseCode));
390-
assertTrue(body.equals(responseBody),
391-
String.format("Expected response %s, instead received %s", body, responseBody));
377+
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
378+
responseCode == 200);
379+
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
380+
body.equals(responseBody));
392381
}
393382

394383
@Test
395384
public void testFixedLengthRequestWithDoubleExpect100ContinueResponse() throws Exception {
396385
String body = "testFixedLengthRequestWithDoubleExpect100ContinueResponse";
397-
Control control = this.control;
398386
control.response = "HTTP/1.1 200 OK\r\n" +
399387
"Connection: close\r\n" +
400388
"Content-Length: " + body.length() + "\r\n" +
@@ -412,10 +400,10 @@ public void testFixedLengthRequestWithDoubleExpect100ContinueResponse() throws E
412400
int responseCode = connection.getResponseCode();
413401
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
414402
System.err.println("response body: " + responseBody);
415-
assertTrue(responseCode == 200,
416-
String.format("Expected 200 response, instead received %s", responseCode));
417-
assertTrue(body.equals(responseBody),
418-
String.format("Expected response %s, instead received %s", body, responseBody));
403+
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
404+
responseCode == 200);
405+
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
406+
body.equals(responseBody));
419407
}
420408

421409
// Creates a connection with all the common settings used in each test

0 commit comments

Comments
 (0)
Please sign in to comment.