Skip to content

Commit 9193048

Browse files
committed
Use BeforeEach instead of BeforeAll
1 parent c949bdd commit 9193048

File tree

2 files changed

+17
-31
lines changed

2 files changed

+17
-31
lines changed

src/test/java/org/java_websocket/misc/OpeningHandshakeRejectionTest.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,20 @@
3838
import org.java_websocket.handshake.ServerHandshake;
3939
import org.java_websocket.util.Charsetfunctions;
4040
import org.java_websocket.util.SocketUtil;
41-
import org.junit.jupiter.api.AfterAll;
42-
import org.junit.jupiter.api.BeforeAll;
43-
import org.junit.jupiter.api.Test;
44-
import org.junit.jupiter.api.Timeout;
41+
import org.junit.jupiter.api.*;
4542

4643
import static org.junit.jupiter.api.Assertions.fail;
4744

4845
public class OpeningHandshakeRejectionTest {
4946

50-
private static final String additionalHandshake = "Upgrade: websocket\r\nConnection: Upgrade\r\n\r\n";
51-
private static Thread thread;
52-
private static ServerSocket serverSocket;
53-
54-
private static boolean debugPrintouts = false;
47+
private int port;
48+
private Thread thread;
49+
private ServerSocket serverSocket;
5550

56-
private static int port;
51+
private static final String additionalHandshake = "Upgrade: websocket\r\nConnection: Upgrade\r\n\r\n";
5752

58-
@BeforeAll
59-
public static void startServer() throws Exception {
53+
@BeforeEach
54+
public void startServer() throws IOException {
6055
port = SocketUtil.getAvailablePort();
6156
thread = new Thread(
6257
new Runnable() {
@@ -144,8 +139,8 @@ public void run() {
144139
thread.start();
145140
}
146141

147-
@AfterAll
148-
public static void successTests() throws IOException {
142+
@AfterEach
143+
public void cleanUp() throws IOException {
149144
serverSocket.close();
150145
thread.interrupt();
151146
}
@@ -244,9 +239,6 @@ public void onClose(int code, String reason, boolean remote) {
244239
fail("There should be a protocol error!");
245240
} else if (reason.startsWith("Invalid status code received:") || reason
246241
.startsWith("Invalid status line received:")) {
247-
if (debugPrintouts) {
248-
System.out.println("Protocol error for test case: " + finalI);
249-
}
250242
countDownLatch.countDown();
251243
} else {
252244
fail("The reason should be included!");
@@ -256,9 +248,6 @@ public void onClose(int code, String reason, boolean remote) {
256248
if (!reason.endsWith("refuses handshake")) {
257249
fail("onClose should not be called!");
258250
} else {
259-
if (debugPrintouts) {
260-
System.out.println("Refuses handshake error for test case: " + finalI);
261-
}
262251
countDownLatch.countDown();
263252
}
264253
}

src/test/java/org/java_websocket/protocols/ProtocolHandshakeRejectionTest.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,20 @@
4545
import org.java_websocket.util.Base64;
4646
import org.java_websocket.util.Charsetfunctions;
4747
import org.java_websocket.util.SocketUtil;
48-
import org.junit.jupiter.api.AfterAll;
49-
import org.junit.jupiter.api.BeforeAll;
50-
import org.junit.jupiter.api.Test;
51-
import org.junit.jupiter.api.Timeout;
48+
import org.junit.jupiter.api.*;
5249

5350
import static org.junit.jupiter.api.Assertions.*;
5451

5552
public class ProtocolHandshakeRejectionTest {
5653

5754
private static final String additionalHandshake = "HTTP/1.1 101 Websocket Connection Upgrade\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n";
58-
private static Thread thread;
59-
private static ServerSocket serverSocket;
55+
private Thread thread;
56+
private ServerSocket serverSocket;
6057

61-
private static int port;
58+
private int port;
6259

63-
@BeforeAll
64-
public static void startServer() throws Exception {
60+
@BeforeEach
61+
public void startServer() throws Exception {
6562
port = SocketUtil.getAvailablePort();
6663
thread = new Thread(
6764
new Runnable() {
@@ -267,8 +264,8 @@ private static String getSecKey(String seckey) {
267264
return "Sec-WebSocket-Accept: " + generateFinalKey(seckey) + "\r\n";
268265
}
269266

270-
@AfterAll
271-
public static void successTests() throws IOException {
267+
@AfterEach
268+
public void successTests() throws IOException {
272269
serverSocket.close();
273270
thread.interrupt();
274271
}

0 commit comments

Comments
 (0)