2626package org .java_websocket .issues ;
2727
2828import org .java_websocket .WebSocket ;
29- import org .java_websocket .WebSocketImpl ;
3029import org .java_websocket .client .WebSocketClient ;
3130import org .java_websocket .handshake .ClientHandshake ;
3231import org .java_websocket .handshake .ServerHandshake ;
3332import org .java_websocket .server .WebSocketServer ;
3433import org .java_websocket .util .SocketUtil ;
3534import org .java_websocket .util .ThreadCheck ;
36- import org .junit .*;
35+ import org .junit .AfterClass ;
36+ import org .junit .BeforeClass ;
37+ import org .junit .Rule ;
38+ import org .junit .Test ;
3739import org .junit .runner .RunWith ;
3840import org .junit .runners .Parameterized ;
3941
4042import java .io .IOException ;
4143import java .net .InetSocketAddress ;
4244import java .net .URI ;
45+ import java .net .URISyntaxException ;
4346import java .util .ArrayList ;
4447import java .util .Collection ;
4548import java .util .List ;
@@ -63,8 +66,12 @@ public class Issue256Test {
6366 public int count ;
6467
6568 @ BeforeClass
66- public static void startServer () throws Exception {
67- port = SocketUtil .getAvailablePort ();
69+ public static void startServer () {
70+ try {
71+ port = SocketUtil .getAvailablePort ();
72+ } catch (IOException e ) {
73+ //
74+ }
6875 ws = new WebSocketServer ( new InetSocketAddress ( port ) , 16 ) {
6976 @ Override
7077 public void onOpen ( WebSocket conn , ClientHandshake handshake ) {
@@ -98,7 +105,7 @@ public void onStart() {
98105 ws .start ();
99106 }
100107
101- private void runTestScenarioReconnect ( boolean closeBlocking ) throws Exception {
108+ private void runTestScenarioReconnect ( boolean closeBlocking ) throws URISyntaxException {
102109 final CountDownLatch countDownLatch0 = new CountDownLatch ( 1 );
103110 final CountDownLatch countDownLatch1 = new CountDownLatch ( 2 );
104111 WebSocketClient clt = new WebSocketClient ( new URI ( "ws://localhost:" + port ) ) {
@@ -124,20 +131,33 @@ public void onError( Exception ex ) {
124131 System .out .println ("There should be no exception!" );
125132 }
126133 };
127- clt .connectBlocking ();
128- if ( closeBlocking ) {
134+ try {
135+ clt .connectBlocking ();
136+
137+ if ( closeBlocking ) {
138+ clt .closeBlocking ();
139+ } else {
140+ clt .getSocket ().close ();
141+ }
142+ countDownLatch0 .await ();
143+ clt .reconnectBlocking ();
129144 clt .closeBlocking ();
130- } else {
131- clt .getSocket ().close ();
145+ } catch (InterruptedException e ) {
146+ //
147+ } catch (IOException e ) {
148+ //
132149 }
133- countDownLatch0 .await ();
134- clt .reconnectBlocking ();
135- clt .closeBlocking ();
136150 }
137151
138152 @ AfterClass
139- public static void successTests () throws InterruptedException , IOException {
140- ws .stop ();
153+ public static void successTests () {
154+ try {
155+ ws .stop ();
156+ } catch (IOException e ) {
157+ //
158+ } catch (InterruptedException e ) {
159+ //
160+ }
141161 }
142162
143163 @ Parameterized .Parameters
@@ -148,13 +168,21 @@ public static Collection<Integer[]> data() {
148168 }
149169
150170 @ Test (timeout = 5000 )
151- public void runReconnectSocketClose () throws Exception {
152- runTestScenarioReconnect ( false );
171+ public void runReconnectSocketClose () {
172+ try {
173+ runTestScenarioReconnect ( false );
174+ } catch (URISyntaxException e ) {
175+ //
176+ }
153177 }
154178
155179 @ Test (timeout = 5000 )
156- public void runReconnectCloseBlocking () throws Exception {
157- runTestScenarioReconnect ( true );
180+ public void runReconnectCloseBlocking () {
181+ try {
182+ runTestScenarioReconnect ( true );
183+ } catch (URISyntaxException e ) {
184+ //
185+ }
158186 }
159187
160188}
0 commit comments