SocketIoSocket extends Emitter { void onEvent(final Packet packet) { Object[] args = (packet.data != null)? unpackEventData((JSONArray)packet.data) : EMPTY_ARGS; if (packet.id >= 0) { final Object[] emitArgs = new Object[args.length + 1]; System.arraycopy(args, 0, emitArgs, 0, args.length); emitArgs[args.length] = (ReceivedByLocalAcknowledgementCallback) args1 -> { final Packet ackPacket = PacketUtils.createDataPacket(Parser.ACK, null, args1); ackPacket.id = packet.id; sendPacket(ackPacket); }; args = emitArgs; } final String event = args[0].toString(); final Object[] eventArgs = new Object[args.length - 1]; System.arraycopy(args, 1, eventArgs, 0, eventArgs.length); emit(event, eventArgs); for (AllEventListener listener : mAllEventListeners) { listener.event(event, eventArgs); } } 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_onEvent_without_ack() { final EngineIoServer engineIoServer = new EngineIoServer(); final SocketIoServer server = Mockito.spy(new SocketIoServer(engineIoServer)); final SocketIoNamespace namespace = server.namespace("/"); final Emitter.Listener connectionListener = Mockito.mock(Emitter.Listener.class); Mockito.doAnswer(invocation -> { final Object[] args = invocation.getArguments(); final SocketIoSocket socket = (SocketIoSocket) args[0]; final JSONArray data = new JSONArray(); data.put("foo"); data.put("bar"); final Packet<JSONArray> eventPacket = new Packet<>(Parser.EVENT, data); final Emitter.Listener messageListener = Mockito.mock(Emitter.Listener.class); socket.on("foo", messageListener); socket.onEvent(eventPacket); Mockito.verify(messageListener, Mockito.times(1)) .call(Mockito.eq("bar")); return null; }).when(connectionListener).call(Mockito.any()); namespace.on("connection", connectionListener); final EngineIoWebSocketImpl webSocket = new EngineIoWebSocketImpl(); engineIoServer.handleWebSocket(webSocket); Mockito.verify(connectionListener, Mockito.times(1)) .call(Mockito.any(SocketIoSocket.class)); }