Skip to content

Commit a4053e8

Browse files
test: cleanup URISyntaxException exceptions
Note: we cannot update the `IO.socket(uri: string)` method without doing a breaking change.
1 parent 67fd5f3 commit a4053e8

File tree

5 files changed

+71
-76
lines changed

5 files changed

+71
-76
lines changed

src/test/java/io/socket/client/Connection.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.io.BufferedReader;
77
import java.io.IOException;
88
import java.io.InputStreamReader;
9-
import java.net.URISyntaxException;
9+
import java.net.URI;
1010
import java.util.HashMap;
1111
import java.util.Map;
1212
import java.util.concurrent.*;
@@ -77,24 +77,24 @@ public void stopServer() throws InterruptedException {
7777
serverService.awaitTermination(3000, TimeUnit.MILLISECONDS);
7878
}
7979

80-
Socket client() throws URISyntaxException {
80+
Socket client() {
8181
return client(createOptions());
8282
}
8383

84-
Socket client(String path) throws URISyntaxException {
84+
Socket client(String path) {
8585
return client(path, createOptions());
8686
}
8787

88-
Socket client(IO.Options opts) throws URISyntaxException {
88+
Socket client(IO.Options opts) {
8989
return client(nsp(), opts);
9090
}
9191

92-
Socket client(String path, IO.Options opts) throws URISyntaxException {
93-
return IO.socket(uri() + path, opts);
92+
Socket client(String path, IO.Options opts) {
93+
return IO.socket(URI.create(uri() + path), opts);
9494
}
9595

96-
String uri() {
97-
return "http://localhost:" + PORT;
96+
URI uri() {
97+
return URI.create("http://localhost:" + PORT);
9898
}
9999

100100
String nsp() {

src/test/java/io/socket/client/ConnectionTest.java

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class ConnectionTest extends Connection {
2929
private Socket socket;
3030

3131
@Test(timeout = TIMEOUT)
32-
public void connectToLocalhost() throws URISyntaxException, InterruptedException {
32+
public void connectToLocalhost() throws InterruptedException {
3333
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
3434
socket = client();
3535
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -50,7 +50,7 @@ public void call(Object... args) {
5050
}
5151

5252
@Test(timeout = TIMEOUT)
53-
public void startTwoConnectionsWithSamePath() throws URISyntaxException, InterruptedException {
53+
public void startTwoConnectionsWithSamePath() throws InterruptedException {
5454
Socket s1 = client("/");
5555
Socket s2 = client("/");
5656

@@ -60,7 +60,7 @@ public void startTwoConnectionsWithSamePath() throws URISyntaxException, Interru
6060
}
6161

6262
@Test(timeout = TIMEOUT)
63-
public void startTwoConnectionsWithSamePathAndDifferentQuerystrings() throws URISyntaxException, InterruptedException {
63+
public void startTwoConnectionsWithSamePathAndDifferentQuerystrings() throws InterruptedException {
6464
Socket s1 = client("/?woot");
6565
Socket s2 = client("/");
6666

@@ -70,7 +70,7 @@ public void startTwoConnectionsWithSamePathAndDifferentQuerystrings() throws URI
7070
}
7171

7272
@Test(timeout = TIMEOUT)
73-
public void workWithAcks() throws URISyntaxException, InterruptedException {
73+
public void workWithAcks() throws InterruptedException {
7474
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
7575
socket = client();
7676
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -111,7 +111,7 @@ public void call(Object... args) {
111111
}
112112

113113
@Test(timeout = TIMEOUT)
114-
public void receiveDateWithAck() throws URISyntaxException, InterruptedException {
114+
public void receiveDateWithAck() throws InterruptedException {
115115
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
116116

117117
socket = client();
@@ -136,7 +136,7 @@ public void call(Object... args) {
136136
}
137137

138138
@Test(timeout = TIMEOUT)
139-
public void sendBinaryAck() throws URISyntaxException, InterruptedException {
139+
public void sendBinaryAck() throws InterruptedException {
140140
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
141141
final byte[] buf = "huehue".getBytes(Charset.forName("UTF-8"));
142142

@@ -168,7 +168,7 @@ public void call(Object... args) {
168168
}
169169

170170
@Test(timeout = TIMEOUT)
171-
public void receiveBinaryDataWithAck() throws URISyntaxException, InterruptedException {
171+
public void receiveBinaryDataWithAck() throws InterruptedException {
172172
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
173173
final byte[] buf = "huehue".getBytes(Charset.forName("UTF-8"));
174174

@@ -191,7 +191,7 @@ public void call(Object... args) {
191191
}
192192

193193
@Test(timeout = TIMEOUT)
194-
public void workWithFalse() throws URISyntaxException, InterruptedException {
194+
public void workWithFalse() throws InterruptedException {
195195
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
196196
socket = client();
197197
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -212,7 +212,7 @@ public void call(Object... args) {
212212
}
213213

214214
@Test(timeout = TIMEOUT)
215-
public void receiveUTF8MultibyteCharacters() throws URISyntaxException, InterruptedException {
215+
public void receiveUTF8MultibyteCharacters() throws InterruptedException {
216216
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
217217
final String[] correct = new String[] {
218218
"てすと",
@@ -245,9 +245,9 @@ public void call(Object... args) {
245245
}
246246

247247
@Test(timeout = TIMEOUT)
248-
public void connectToNamespaceAfterConnectionEstablished() throws URISyntaxException, InterruptedException {
248+
public void connectToNamespaceAfterConnectionEstablished() throws InterruptedException {
249249
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
250-
final Manager manager = new Manager(new URI(uri()));
250+
final Manager manager = new Manager(uri());
251251
socket = manager.socket("/");
252252
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
253253
@Override
@@ -270,9 +270,9 @@ public void call(Object... args) {
270270
}
271271

272272
@Test(timeout = TIMEOUT)
273-
public void connectToNamespaceAfterConnectionGetsClosed() throws URISyntaxException, InterruptedException {
273+
public void connectToNamespaceAfterConnectionGetsClosed() throws InterruptedException {
274274
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
275-
final Manager manager = new Manager(new URI(uri()));
275+
final Manager manager = new Manager(uri());
276276
socket = manager.socket("/");
277277
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
278278
@Override
@@ -299,7 +299,7 @@ public void call(Object... args) {
299299
}
300300

301301
@Test(timeout = TIMEOUT)
302-
public void reconnectByDefault() throws URISyntaxException, InterruptedException {
302+
public void reconnectByDefault() throws InterruptedException {
303303
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
304304
socket = client();
305305
socket.io().on(Manager.EVENT_RECONNECT, new Emitter.Listener() {
@@ -320,7 +320,7 @@ public void run() {
320320
}
321321

322322
@Test(timeout = TIMEOUT)
323-
public void reconnectManually() throws URISyntaxException, InterruptedException {
323+
public void reconnectManually() throws InterruptedException {
324324
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
325325
socket = client();
326326
socket.once(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -346,7 +346,7 @@ public void call(Object... args) {
346346
}
347347

348348
@Test(timeout = TIMEOUT)
349-
public void reconnectAutomaticallyAfterReconnectingManually() throws URISyntaxException, InterruptedException {
349+
public void reconnectAutomaticallyAfterReconnectingManually() throws InterruptedException {
350350
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
351351
socket = client();
352352
socket.once(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -378,14 +378,14 @@ public void run() {
378378
}
379379

380380
@Test(timeout = 14000)
381-
public void attemptReconnectsAfterAFailedReconnect() throws URISyntaxException, InterruptedException {
381+
public void attemptReconnectsAfterAFailedReconnect() throws InterruptedException {
382382
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
383383
IO.Options opts = createOptions();
384384
opts.reconnection = true;
385385
opts.timeout = 0;
386386
opts.reconnectionAttempts = 2;
387387
opts.reconnectionDelay = 10;
388-
final Manager manager = new Manager(new URI(uri()), opts);
388+
final Manager manager = new Manager(uri(), opts);
389389
socket = manager.socket("/timeout");
390390
manager.once(Manager.EVENT_RECONNECT_FAILED, new Emitter.Listener() {
391391
@Override
@@ -415,15 +415,15 @@ public void call(Object... args) {
415415
}
416416

417417
@Test(timeout = TIMEOUT)
418-
public void reconnectDelayShouldIncreaseEveryTime() throws URISyntaxException, InterruptedException {
418+
public void reconnectDelayShouldIncreaseEveryTime() throws InterruptedException {
419419
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
420420
IO.Options opts = createOptions();
421421
opts.reconnection = true;
422422
opts.timeout = 0;
423423
opts.reconnectionAttempts = 3;
424424
opts.reconnectionDelay = 100;
425425
opts.randomizationFactor = 0.2;
426-
final Manager manager = new Manager(new URI(uri()), opts);
426+
final Manager manager = new Manager(uri(), opts);
427427
socket = manager.socket("/timeout");
428428

429429
final int[] reconnects = new int[] {0};
@@ -524,7 +524,7 @@ public void run() {
524524
}
525525

526526
@Test(timeout = TIMEOUT)
527-
public void reconnectAfterStoppingReconnection() throws URISyntaxException, InterruptedException {
527+
public void reconnectAfterStoppingReconnection() throws InterruptedException {
528528
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
529529
IO.Options opts = createOptions();
530530
opts.forceNew = true;
@@ -550,9 +550,9 @@ public void call(Object... args) {
550550
}
551551

552552
@Test(timeout = TIMEOUT)
553-
public void stopReconnectingOnASocketAndKeepToReconnectOnAnother() throws URISyntaxException, InterruptedException {
553+
public void stopReconnectingOnASocketAndKeepToReconnectOnAnother() throws InterruptedException {
554554
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
555-
final Manager manager = new Manager(new URI(uri()));
555+
final Manager manager = new Manager(uri());
556556
final Socket socket1 = manager.socket("/");
557557
final Socket socket2 = manager.socket("/asd");
558558

@@ -596,10 +596,10 @@ public void run() {
596596
}
597597

598598
@Test(timeout = TIMEOUT)
599-
public void connectWhileDisconnectingAnotherSocket() throws URISyntaxException, InterruptedException {
599+
public void connectWhileDisconnectingAnotherSocket() throws InterruptedException {
600600
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
601601

602-
final Manager manager = new Manager(new URI(uri()));
602+
final Manager manager = new Manager(uri());
603603
final Socket socket1 = manager.socket("/foo");
604604
socket1.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
605605
@Override
@@ -623,13 +623,13 @@ public void call(Object... args) {
623623
}
624624

625625
@Test(timeout = TIMEOUT)
626-
public void tryToReconnectTwiceAndFailWithIncorrectAddress() throws URISyntaxException, InterruptedException {
626+
public void tryToReconnectTwiceAndFailWithIncorrectAddress() throws InterruptedException {
627627
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
628628
IO.Options opts = new IO.Options();
629629
opts.reconnection = true;
630630
opts.reconnectionAttempts = 2;
631631
opts.reconnectionDelay = 10;
632-
final Manager manager = new Manager(new URI("http://localhost:3940"), opts);
632+
final Manager manager = new Manager(URI.create("http://localhost:3940"), opts);
633633
socket = manager.socket("/asd");
634634
final int[] reconnects = new int[] {0};
635635
Emitter.Listener cb = new Emitter.Listener() {
@@ -655,14 +655,14 @@ public void call(Object... objects) {
655655
}
656656

657657
@Test(timeout = TIMEOUT)
658-
public void tryToReconnectTwiceAndFailWithImmediateTimeout() throws URISyntaxException, InterruptedException {
658+
public void tryToReconnectTwiceAndFailWithImmediateTimeout() throws InterruptedException {
659659
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
660660
IO.Options opts = new IO.Options();
661661
opts.reconnection = true;
662662
opts.timeout = 0;
663663
opts.reconnectionAttempts = 2;
664664
opts.reconnectionDelay = 10;
665-
final Manager manager = new Manager(new URI(uri()), opts);
665+
final Manager manager = new Manager(uri(), opts);
666666

667667
final int[] reconnects = new int[] {0};
668668
Emitter.Listener reconnectCb = new Emitter.Listener() {
@@ -688,11 +688,11 @@ public void call(Object... objects) {
688688
}
689689

690690
@Test(timeout = TIMEOUT)
691-
public void notTryToReconnectWithIncorrectPortWhenReconnectionDisabled() throws URISyntaxException, InterruptedException {
691+
public void notTryToReconnectWithIncorrectPortWhenReconnectionDisabled() throws InterruptedException {
692692
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
693693
IO.Options opts = new IO.Options();
694694
opts.reconnection = false;
695-
final Manager manager = new Manager(new URI("http://localhost:9823"), opts);
695+
final Manager manager = new Manager(URI.create("http://localhost:9823"), opts);
696696
Emitter.Listener cb = new Emitter.Listener() {
697697
@Override
698698
public void call(Object... objects) {
@@ -722,15 +722,15 @@ public void run() {
722722
}
723723

724724
@Test(timeout = TIMEOUT)
725-
public void fireReconnectEventsOnSocket() throws URISyntaxException, InterruptedException {
725+
public void fireReconnectEventsOnSocket() throws InterruptedException {
726726
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
727727

728728
Manager.Options opts = new Manager.Options();
729729
opts.reconnection = true;
730730
opts.timeout = 0;
731731
opts.reconnectionAttempts = 2;
732732
opts.reconnectionDelay = 10;
733-
final Manager manager = new Manager(new URI(uri()), opts);
733+
final Manager manager = new Manager(uri(), opts);
734734
socket = manager.socket("/timeout_socket");
735735

736736
final int[] reconnects = new int[] {0};
@@ -757,15 +757,15 @@ public void call(Object... objects) {
757757
}
758758

759759
@Test(timeout = TIMEOUT)
760-
public void fireReconnectingWithAttemptsNumberWhenReconnectingTwice() throws URISyntaxException, InterruptedException {
760+
public void fireReconnectingWithAttemptsNumberWhenReconnectingTwice() throws InterruptedException {
761761
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
762762

763763
Manager.Options opts = new Manager.Options();
764764
opts.reconnection = true;
765765
opts.timeout = 0;
766766
opts.reconnectionAttempts = 2;
767767
opts.reconnectionDelay = 10;
768-
final Manager manager = new Manager(new URI(uri()), opts);
768+
final Manager manager = new Manager(uri(), opts);
769769
socket = manager.socket("/timeout_socket");
770770

771771
final int[] reconnects = new int[] {0};
@@ -792,7 +792,7 @@ public void call(Object... objects) {
792792
}
793793

794794
@Test(timeout = TIMEOUT)
795-
public void emitDateAsString() throws URISyntaxException, InterruptedException {
795+
public void emitDateAsString() throws InterruptedException {
796796
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
797797
socket = client();
798798
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -813,7 +813,7 @@ public void call(Object... args) {
813813
}
814814

815815
@Test(timeout = TIMEOUT)
816-
public void emitDateInObject() throws URISyntaxException, InterruptedException, JSONException {
816+
public void emitDateInObject() throws InterruptedException, JSONException {
817817
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
818818
socket = client();
819819
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@@ -843,7 +843,7 @@ public void call(Object... args) {
843843

844844

845845
@Test(timeout = TIMEOUT)
846-
public void sendAndGetBinaryData() throws URISyntaxException, InterruptedException {
846+
public void sendAndGetBinaryData() throws InterruptedException {
847847
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
848848
final byte[] buf = "asdfasdf".getBytes(Charset.forName("UTF-8"));
849849
socket = client();
@@ -865,7 +865,7 @@ public void call(Object... args) {
865865
}
866866

867867
@Test(timeout = TIMEOUT)
868-
public void sendBinaryDataMixedWithJson() throws URISyntaxException, InterruptedException, JSONException {
868+
public void sendBinaryDataMixedWithJson() throws InterruptedException, JSONException {
869869
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
870870
final byte[] buf = "howdy".getBytes(Charset.forName("UTF-8"));
871871
socket = client();

src/test/java/io/socket/client/SSLConnectionTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.io.File;
1717
import java.io.FileInputStream;
1818
import java.io.IOException;
19+
import java.net.URI;
1920
import java.security.GeneralSecurityException;
2021
import java.security.KeyStore;
2122
import java.util.concurrent.BlockingQueue;
@@ -39,8 +40,8 @@ public class SSLConnectionTest extends Connection {
3940
}
4041

4142
@Override
42-
String uri() {
43-
return "https://localhost:" + PORT;
43+
URI uri() {
44+
return URI.create("https://localhost:" + PORT);
4445
}
4546

4647
@Override

0 commit comments

Comments
 (0)