@Test
public void test_joinRoom() {

    final LocalAdapterFactory adapterFactory = new LocalAdapterFactory();
    final EngineIoServer engineIoServer = new EngineIoServer();
    final SocketIoServer server = Mockito.spy(new SocketIoServer(
            engineIoServer,
            SocketIoServerOptions.newFromDefault().setAdapterFactory(adapterFactory)));
    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 SocketIoAdapter adapter = adapterFactory.adapter;
        // Join foo
        Mockito.reset(adapter);
        socket.joinRoom("foo");
        Mockito.verify(adapter, Mockito.times(1))
                .add(Mockito.eq("foo"), Mockito.eq(socket));
        // Join bar
        Mockito.reset(adapter);
        socket.joinRoom("bar");
        Mockito.verify(adapter, Mockito.times(1))
                .add(Mockito.eq("bar"), Mockito.eq(socket));
        // Duplicate join foo
        Mockito.reset(adapter);
        socket.joinRoom("foo");
        Mockito.verify(adapter, Mockito.times(0))
                .add(Mockito.eq("foo"), Mockito.eq(socket));
        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));
}