SocketIoSocket extends Emitter { public void disconnect(boolean close) { if (mConnected) { if (close) { mClient.disconnect(); } else { final Packet packet = new Packet(); packet.type = Parser.DISCONNECT; sendPacket(packet); onClose("server namespace disconnect"); } } } SocketIoSocket(SocketIoNamespaceImpl namespace, SocketIoClient client); @Override int hashCode(); @Override boolean equals(Object obj); String getId(); SocketIoNamespace getNamespace(); void disconnect(boolean close); void broadcast(String room, String event, Object... args); void broadcast(String[] rooms, String event, Object[] args); void send(String event, Object... args); void send(String event, Object[] args, ReceivedByRemoteAcknowledgementCallback acknowledgementCallback); synchronized void joinRoom(String... rooms); synchronized void leaveRoom(String... rooms); synchronized void leaveAllRooms(); void registerAllEventListener(AllEventListener listener); void unregisterAllEventListener(AllEventListener listener);  }
@Test public void test_disconnect_with_close() { final EngineIoServer engineIoServer = new EngineIoServer(); final SocketIoServer server = new SocketIoServer(engineIoServer); final SocketIoNamespaceImpl namespace = (SocketIoNamespaceImpl)server.namespace("/"); final EngineIoWebSocket webSocket = Mockito.spy(new EngineIoWebSocketImpl()); final Emitter.Listener connectionListener = Mockito.mock(Emitter.Listener.class); Mockito.doAnswer(invocation -> { final Object[] args = invocation.getArguments(); final SocketIoClient client = Mockito.spy(new SocketIoClient(server, (EngineIoSocket) args[0])); final SocketIoSocket socket = new SocketIoSocket(namespace, client); socket.disconnect(true); Mockito.verify(client, Mockito.times(1)) .disconnect(); return null; }).when(connectionListener).call(Mockito.any()); engineIoServer.on("connection", connectionListener); engineIoServer.handleWebSocket(webSocket); Mockito.verify(connectionListener, Mockito.times(1)) .call(Mockito.any(EngineIoSocket.class)); }