WebSocket implements AutoCloseable { void connect() { if (!isConnected()) { session = connect(uri); disposable.update(startKeepAlives()); } } WebSocket(
      String username,
      String password,
      URI uri,
      ObjectMapper mapper,
      TLSConfig.Factory tlsConfigFactory,
      long keepAliveSeconds,
      EventHandler eventHandler,
      ErrorHandler errorHandler,
      CloseHandler closeHandler); @Override void close();  }
@Test public void start() throws Exception { underTest.connect(); verify(underTest).connect(uri); }
@Test public void keepAlives() throws Exception { underTest.connect(); RemoteEndpoint.Basic basicRemote = mock(RemoteEndpoint.Basic.class); doReturn(basicRemote).when(session).getBasicRemote(); doReturn(true).when(session).isOpen(); Awaitility.await().atMost(2, SECONDS).pollInterval(200, MILLISECONDS).until(() -> { try { verify(basicRemote).sendPong(any()); } catch (Exception e) { fail(); } }); }