@Test public void test_sendPacket() { 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); Mockito.doAnswer(invocationOnMock -> { final Packet packet = invocationOnMock.getArgument(0); assertNotNull(packet); assertEquals("/", packet.nsp); return null; }).when(client).sendPacket(Mockito.any(Packet.class)); socket.sendPacket(new Packet(Parser.CONNECT)); Mockito.verify(client, Mockito.times(1)) .sendPacket(Mockito.any(Packet.class)); 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)); }
void sendPacket(Packet packet) { packet.nsp = mNamespace.getName(); mClient.sendPacket(packet); }
SocketIoSocket extends Emitter { void sendPacket(Packet packet) { packet.nsp = mNamespace.getName(); mClient.sendPacket(packet); } }
SocketIoSocket extends Emitter { void sendPacket(Packet packet) { packet.nsp = mNamespace.getName(); mClient.sendPacket(packet); } SocketIoSocket(SocketIoNamespaceImpl namespace, SocketIoClient client); }
SocketIoSocket extends Emitter { void sendPacket(Packet packet) { packet.nsp = mNamespace.getName(); mClient.sendPacket(packet); } 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); }
SocketIoSocket extends Emitter { void sendPacket(Packet packet) { packet.nsp = mNamespace.getName(); mClient.sendPacket(packet); } 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);  }