### Question:
WebSocketService implements Web3jService { public void connect() throws ConnectException { try { setWebSocketListener(); connectToWebSocket(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); log.warn("Interrupted while connecting via WebSocket protocol"); } } WebSocketService(String serverUrl, boolean includeRawResponses);  WebSocketService(WebSocketClient webSocketClient,
                     boolean includeRawResponses);   WebSocketService(WebSocketClient webSocketClient,
                     ScheduledExecutorService executor,
                     boolean includeRawResponses); void connect(); @Override T send(Request request, Class<T> responseType); @Override CompletableFuture<T> sendAsync(
            Request request,
            Class<T> responseType); @Override Observable<T> subscribe(
            Request request,
            String unsubscribeMethod,
            Class<T> responseType); @Override void close();  }### Answer:
@Test public void testConnectViaWebSocketClient() throws Exception { service.connect(); verify(webSocketClient).connectBlocking(); }
@Test public void testInterruptCurrentThreadIfConnectionIsInterrupted() throws Exception { when(webSocketClient.connectBlocking()).thenThrow(new InterruptedException()); service.connect(); assertTrue("Interrupted flag was not set properly", Thread.currentThread().isInterrupted()); }
@Test public void testThrowExceptionIfConnectionFailed() throws Exception { thrown.expect(ConnectException.class); thrown.expectMessage("Failed to connect to WebSocket"); when(webSocketClient.connectBlocking()).thenReturn(false); service.connect(); }