WebSocketClient implements PersistentChannel { public void connect() { synchronized (lock) { switch (state.getValue()) { case DISCONNECTED: case FAILED: WebSocketClient.this.state.onNext(WebSocketStatus.CONNECTING); this.connectWebSocket(); return; case CONNECTING: case CONNECTED: case CLOSING: return; } } } WebSocketClient(Function<WebSocketListener, WebSocket> websocketFactory); void connect(); @Override Cancellable addListener(Consumer<String> messageListener); Observable<WebSocketStatus> getState(); boolean close(); @Override boolean sendMessage(String message);  }
@Test public void testConnect() { WebSocket webSocket = mock(WebSocket.class); WebSocketClient client = new WebSocketClient(listener -> webSocket); client.connect(); }