WebSocket implements AutoCloseable { @Override public void close() throws Exception { disposable.dispose(); if (isConnected()) { try { session.close(); log.info("Disconnected session: {}", session.getId()); session = null; } catch (IOException e) { throw new UncheckedIOException(e); } } } 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 close() throws Exception { underTest.connect(); doReturn(true).when(underTest).isConnected(); underTest.close(); verify(session).close(); }