MCPcopy
hub / github.com/socketio/socket.io-client-java / SocketTest

Class SocketTest

src/test/java/io/socket/client/SocketTest.java:21–453  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19import static org.junit.Assert.fail;
20
21@RunWith(JUnit4.class)
22public class SocketTest extends Connection {
23
24 private Socket socket;
25
26 @Test(timeout = TIMEOUT)
27 public void shouldHaveAnAccessibleSocketIdEqualToServerSideSocketId() throws InterruptedException {
28 final BlockingQueue<Optional> values = new LinkedBlockingQueue<>();
29 socket = client();
30 socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
31 @Override
32 public void call(Object... objects) {
33 values.offer(Optional.ofNullable(socket.id()));
34 }
35 });
36 socket.connect();
37
38 @SuppressWarnings("unchecked")
39 Optional<String> id = values.take();
40 assertThat(id.isPresent(), is(true));
41 assertThat(id.get(), not(socket.io().engine.id())); // distinct ID since Socket.IO v3
42 socket.disconnect();
43 }
44
45 @Test(timeout = TIMEOUT)
46 public void shouldHaveAnAccessibleSocketIdEqualToServerSideSocketIdOnCustomNamespace() throws InterruptedException {
47 final BlockingQueue<Optional> values = new LinkedBlockingQueue<>();
48 socket = client("/foo");
49 socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
50 @Override
51 public void call(Object... objects) {
52 values.offer(Optional.ofNullable(socket.id()));
53 }
54 });
55 socket.connect();
56
57 @SuppressWarnings("unchecked")
58 Optional<String> id = values.take();
59 assertThat(id.isPresent(), is(true));
60 assertThat(id.get(), is(not(socket.io().engine.id()))); // distinct ID since Socket.IO v3
61 socket.disconnect();
62 }
63
64 @Test(timeout = TIMEOUT)
65 public void clearsSocketIdUponDisconnection() throws InterruptedException {
66 final BlockingQueue<Optional> values = new LinkedBlockingQueue<>();
67 socket = client();
68 socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
69 @Override
70 public void call(Object... objects) {
71 socket.on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {
72 @Override
73 public void call(Object... args) {
74 values.offer(Optional.ofNullable(socket.id()));
75 }
76 });
77
78 socket.disconnect();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected