3838import org .java_websocket .handshake .ServerHandshake ;
3939import org .java_websocket .util .Charsetfunctions ;
4040import 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
4643import static org .junit .jupiter .api .Assertions .fail ;
4744
4845public class OpeningHandshakeRejectionTest {
4946
50- private static final String additionalHandshake = "Upgrade: websocket\r \n Connection: 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 \n Connection: 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 }
0 commit comments