5151import org .junit .BeforeClass ;
5252import org .junit .Test ;
5353
54- public class ProtoclHandshakeRejectionTest {
54+ public class ProtocolHandshakeRejectionTest {
5555
5656 private static final String additionalHandshake = "HTTP/1.1 101 Websocket Connection Upgrade\r \n Upgrade: websocket\r \n Connection: Upgrade\r \n " ;
5757 private static Thread thread ;
@@ -355,31 +355,31 @@ public void testHandshakeRejectionTestCase13() throws Exception {
355355
356356 @ Test (timeout = 5000 )
357357 public void testHandshakeRejectionTestCase14 () throws Exception {
358- ArrayList <IProtocol > protocols = new ArrayList <IProtocol >();
358+ ArrayList <IProtocol > protocols = new ArrayList <>();
359359 protocols .add (new Protocol ("chat" ));
360360 protocols .add (new Protocol ("chat2" ));
361361 testProtocolRejection (14 , new Draft_6455 (Collections .<IExtension >emptyList (), protocols ));
362362 }
363363
364364 @ Test (timeout = 5000 )
365365 public void testHandshakeRejectionTestCase15 () throws Exception {
366- ArrayList <IProtocol > protocols = new ArrayList <IProtocol >();
366+ ArrayList <IProtocol > protocols = new ArrayList <>();
367367 protocols .add (new Protocol ("chat" ));
368368 protocols .add (new Protocol ("chat2" ));
369369 testProtocolRejection (15 , new Draft_6455 (Collections .<IExtension >emptyList (), protocols ));
370370 }
371371
372372 @ Test (timeout = 5000 )
373373 public void testHandshakeRejectionTestCase16 () throws Exception {
374- ArrayList <IProtocol > protocols = new ArrayList <IProtocol >();
374+ ArrayList <IProtocol > protocols = new ArrayList <>();
375375 protocols .add (new Protocol ("chat" ));
376376 protocols .add (new Protocol ("chat2" ));
377377 testProtocolRejection (16 , new Draft_6455 (Collections .<IExtension >emptyList (), protocols ));
378378 }
379379
380380 @ Test (timeout = 5000 )
381381 public void testHandshakeRejectionTestCase17 () throws Exception {
382- ArrayList <IProtocol > protocols = new ArrayList <IProtocol >();
382+ ArrayList <IProtocol > protocols = new ArrayList <>();
383383 protocols .add (new Protocol ("chat" ));
384384 protocols .add (new Protocol ("" ));
385385 testProtocolRejection (17 , new Draft_6455 (Collections .<IExtension >emptyList (), protocols ));
@@ -402,7 +402,7 @@ public void testHandshakeRejectionTestCase20() throws Exception {
402402
403403 @ Test (timeout = 5000 )
404404 public void testHandshakeRejectionTestCase21 () throws Exception {
405- ArrayList <IProtocol > protocols = new ArrayList <IProtocol >();
405+ ArrayList <IProtocol > protocols = new ArrayList <>();
406406 protocols .add (new Protocol ("chat1" ));
407407 protocols .add (new Protocol ("chat2" ));
408408 protocols .add (new Protocol ("chat3" ));
@@ -411,7 +411,7 @@ public void testHandshakeRejectionTestCase21() throws Exception {
411411
412412 @ Test (timeout = 5000 )
413413 public void testHandshakeRejectionTestCase22 () throws Exception {
414- ArrayList <IProtocol > protocols = new ArrayList <IProtocol >();
414+ ArrayList <IProtocol > protocols = new ArrayList <>();
415415 protocols .add (new Protocol ("chat2" ));
416416 protocols .add (new Protocol ("chat3" ));
417417 protocols .add (new Protocol ("chat1" ));
@@ -420,7 +420,7 @@ public void testHandshakeRejectionTestCase22() throws Exception {
420420
421421 @ Test (timeout = 5000 )
422422 public void testHandshakeRejectionTestCase23 () throws Exception {
423- ArrayList <IProtocol > protocols = new ArrayList <IProtocol >();
423+ ArrayList <IProtocol > protocols = new ArrayList <>();
424424 protocols .add (new Protocol ("chat3" ));
425425 protocols .add (new Protocol ("chat2" ));
426426 protocols .add (new Protocol ("chat1" ));
@@ -463,7 +463,7 @@ public void testHandshakeRejectionTestCase29() throws Exception {
463463 private void testProtocolRejection (int i , Draft_6455 draft ) throws Exception {
464464 final int finalI = i ;
465465 final boolean [] threadReturned = {false };
466- WebSocketClient webSocketClient = new WebSocketClient (
466+ final WebSocketClient webSocketClient = new WebSocketClient (
467467 new URI ("ws://localhost:" + port + "/" + finalI ), draft ) {
468468 @ Override
469469 public void onOpen (ServerHandshake handshakedata ) {
@@ -509,6 +509,7 @@ public void onClose(int code, String reason, boolean remote) {
509509 case 2 :
510510 case 3 :
511511 case 4 :
512+ case 17 :
512513 case 20 :
513514 case 24 :
514515 case 25 :
@@ -533,10 +534,9 @@ public void onClose(int code, String reason, boolean remote) {
533534 case 6 :
534535 case 7 :
535536 case 8 :
536- case 17 :
537+ case 14 :
537538 assertEquals ("chat" , getProtocol ().getProvidedProtocol ());
538539 break ;
539- case 14 :
540540 case 22 :
541541 assertEquals ("chat2" , getProtocol ().getProvidedProtocol ());
542542 break ;
@@ -588,9 +588,24 @@ public void onError(Exception ex) {
588588 fail ("There should not be an exception" );
589589 }
590590 };
591- Thread finalThread = new Thread (webSocketClient );
591+ final AssertionError [] exc = new AssertionError [1 ];
592+ exc [0 ] = null ;
593+ Thread finalThread = new Thread (new Runnable () {
594+ @ Override
595+ public void run () {
596+ try {
597+ webSocketClient .run ();
598+ }catch (AssertionError e ){
599+ exc [0 ] = e ;
600+ }
601+ }
602+
603+ });
592604 finalThread .start ();
593605 finalThread .join ();
606+ if (exc [0 ] != null ) {
607+ throw exc [0 ];
608+ }
594609
595610 if (!threadReturned [0 ]) {
596611 fail ("Error" );
0 commit comments