SocketIoServer { public synchronized SocketIoNamespace namespace(String namespace) { if (namespace.charAt(0) != '/') { namespace = "/" + namespace; } SocketIoNamespaceImpl nsp = mNamespaces.get(namespace); if (nsp == null) { nsp = new SocketIoNamespaceImpl(this, namespace); mNamespaces.put(namespace, nsp); } return nsp; } SocketIoServer(EngineIoServer server);  SocketIoServer(EngineIoServer server, SocketIoServerOptions options); boolean hasNamespace(String namespace); synchronized SocketIoNamespace namespace(String namespace); synchronized SocketIoNamespace namespace(SocketIoNamespaceProvider namespaceProvider); synchronized SocketIoNamespace namespace(final Pattern namespaceRegex);  }
@Test public void test_connection() { final EngineIoServer engineIoServer = new EngineIoServer(); final SocketIoServer server = new SocketIoServer(engineIoServer); final SocketIoNamespace namespace = server.namespace("/"); assertNotNull(namespace); final Emitter.Listener connectionListener = Mockito.mock(Emitter.Listener.class); namespace.on("connect", connectionListener); namespace.on("connection", connectionListener); engineIoServer.handleWebSocket(new EngineIoWebSocket() { @Override public Map<String, String> getQuery() { return new HashMap<>(); } @Override public void write(String message) { } @Override public void write(byte[] message) { } @Override public void close() { } }); Mockito.verify(connectionListener, Mockito.times(2)) .call(Mockito.any(SocketIoSocket.class)); }
@Test public void test_disconnect() { final EngineIoServer engineIoServer = new EngineIoServer(); final SocketIoServer server = new SocketIoServer(engineIoServer); final SocketIoNamespace namespace = server.namespace("/"); assertNotNull(namespace); final Emitter.Listener disconnectListener = Mockito.mock(Emitter.Listener.class); final Emitter.Listener connectionListener = Mockito.mock(Emitter.Listener.class); Mockito.doAnswer(invocation -> { final Object[] args = invocation.getArguments(); final SocketIoSocket socket = (SocketIoSocket) args[0]; socket.on("disconnect", disconnectListener); return null; }).when(connectionListener).call(Mockito.any()); namespace.on("connect", connectionListener); final EngineIoWebSocket webSocket = new EngineIoWebSocket() { @Override public Map<String, String> getQuery() { return new HashMap<>(); } @Override public void write(String message) { } @Override public void write(byte[] message) { } @Override public void close() { } }; engineIoServer.handleWebSocket(webSocket); Mockito.verify(connectionListener, Mockito.times(1)) .call(Mockito.any(SocketIoSocket.class)); webSocket.emit("close", "client close", null); Mockito.verify(disconnectListener, Mockito.times(1)) .call(Mockito.anyString()); }