### Question:
VertxWebSocketClient implements WebSocketClient { @Override public Mono<Void> execute(URI uri, WebSocketHandler handler) { return execute(uri, new HttpHeaders(), handler); } VertxWebSocketClient(Vertx vertx);  VertxWebSocketClient(Vertx vertx, HttpClientOptions options); @Override Mono<Void> execute(URI uri, WebSocketHandler handler); @Override Mono<Void> execute(URI uri, HttpHeaders headers, WebSocketHandler handler);  }### Answer:
@Test @SuppressWarnings("unchecked") public void shouldUseCorrectUri() { webSocketClient.execute(TEST_URI, session -> Mono.empty()) .subscribe(); ArgumentCaptor<WebSocketConnectOptions> optionsCaptor = ArgumentCaptor.forClass(WebSocketConnectOptions.class); verify(mockHttpClient).webSocket(optionsCaptor.capture(), any(Handler.class)); assertThat(optionsCaptor.getValue().getPort()).isEqualTo(TEST_URI.getPort()); assertThat(optionsCaptor.getValue().getHost()).isEqualTo(TEST_URI.getHost()); assertThat(optionsCaptor.getValue().getURI()).isEqualTo(TEST_URI.getPath()); }
@Test @SuppressWarnings("unchecked") public void shouldInitializeEmptyHeaders() { webSocketClient.execute(TEST_URI, session -> Mono.empty()) .subscribe(); ArgumentCaptor<WebSocketConnectOptions> optionsCaptor = ArgumentCaptor.forClass(WebSocketConnectOptions.class); verify(mockHttpClient).webSocket(optionsCaptor.capture(), any(Handler.class)); assertThat(optionsCaptor.getValue().getPort()).isEqualTo(TEST_URI.getPort()); assertThat(optionsCaptor.getValue().getHost()).isEqualTo(TEST_URI.getHost()); assertThat(optionsCaptor.getValue().getURI()).isEqualTo(TEST_URI.getPath()); assertThat(optionsCaptor.getValue().getHeaders()).isEmpty(); }
@Test @SuppressWarnings("unchecked") public void shouldAdaptHeaders() { HttpHeaders headers = new HttpHeaders(); headers.put("key1", Arrays.asList("value1", "value2")); headers.add("key2", "value3"); webSocketClient.execute(TEST_URI, headers, session -> Mono.empty()) .subscribe(); ArgumentCaptor<WebSocketConnectOptions> optionsCaptor = ArgumentCaptor.forClass(WebSocketConnectOptions.class); verify(mockHttpClient).webSocket(optionsCaptor.capture(), any(Handler.class)); assertThat(optionsCaptor.getValue().getPort()).isEqualTo(TEST_URI.getPort()); assertThat(optionsCaptor.getValue().getHost()).isEqualTo(TEST_URI.getHost()); assertThat(optionsCaptor.getValue().getURI()).isEqualTo(TEST_URI.getPath()); assertThat(optionsCaptor.getValue().getHeaders().getAll("key1")).isEqualTo(headers.get("key1")); assertThat(optionsCaptor.getValue().getHeaders().getAll("key2")).isEqualTo(headers.get("key2")); }
@Test public void shouldInitSession() { webSocketClient.execute(TEST_URI, session -> session instanceof VertxWebSocketSession ? Mono.empty() : Mono.error(new AssertionError("Wrong session type: " + session.getClass())) ).block(Duration.ofSeconds(2)); }
@Test public void shouldCompleteSuccessfully() { webSocketClient.execute(TEST_URI, session -> Mono.empty()) .block(Duration.ofSeconds(2)); }
@Test(expected = RuntimeException.class) public void shouldCompleteWithError() { webSocketClient.execute(TEST_URI, session -> Mono.error(RuntimeException::new)) .block(Duration.ofSeconds(2)); }