### Question:
WebSocketService implements Web3jService { @Override public <T extends Response> CompletableFuture<T> sendAsync( Request request, Class<T> responseType) { CompletableFuture<T> result = new CompletableFuture<>(); long requestId = request.getId(); requestForId.put(requestId, new WebSocketRequest<>(result, responseType)); try { sendRequest(request, requestId); } catch (IOException e) { closeRequest(requestId, e); } return result; } 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 testReceiveReply() throws Exception { CompletableFuture<Web3ClientVersion> reply = service.sendAsync( request, Web3ClientVersion.class); sendGethVersionReply(); assertTrue(reply.isDone()); assertEquals("geth-version", reply.get().getWeb3ClientVersion()); }
@Test public void testReceiveError() throws Exception { CompletableFuture<Web3ClientVersion> reply = service.sendAsync( request, Web3ClientVersion.class); sendErrorReply(); assertTrue(reply.isDone()); Web3ClientVersion version = reply.get(); assertTrue(version.hasError()); assertEquals( new Response.Error(-1, "Error message"), version.getError()); }
@Test(expected = ExecutionException.class) public void testCancelRequestAfterTimeout() throws Exception { when(executorService.schedule( any(Runnable.class), eq(WebSocketService.REQUEST_TIMEOUT), eq(TimeUnit.SECONDS))) .then(invocation -> { Runnable runnable = invocation.getArgumentAt(0, Runnable.class); runnable.run(); return null; }); CompletableFuture<Web3ClientVersion> reply = service.sendAsync( request, Web3ClientVersion.class); assertTrue(reply.isDone()); reply.get(); }