### Question:
ClientHandler extends GenericHeapObject implements Handler { @Override public Promise<Response, NeverThrowsException> handle(final Context context, final Request request) { return delegate.handle(context, request) .thenOnResult(new ResultHandler<Response>() { @Override public void handleResult(final Response response) { if (response.getCause() != null) { logger.warning(response.getCause()); } } }); } ClientHandler(final Handler delegate); @Override Promise<Response, NeverThrowsException> handle(final Context context, final Request request);  }### Answer:
@Test(description = "test for OPENIG-315") public void checkRequestIsForwardedUnaltered() throws Exception { final int port = server.getPort(); whenHttp(server).match(alwaysTrue()).then(status(HttpStatus.OK_200)); try (HttpClientHandler clientHandler = new HttpClientHandler(defaultOptions())) { Request request = new Request(); request.setMethod("POST"); request.setUri("http: final Map<String, Object> json = new LinkedHashMap<>(); json.put("k1", "v1"); json.put("k2", "v2"); request.setEntity(json); ClientHandler handler = new ClientHandler(clientHandler); Response response = handler.handle(null, request).get(); assertThat(response.getStatus()).isEqualTo(Status.OK); verifyHttp(server).once(method(Method.POST), uri("/example"), withPostBodyContaining("{\"k1\":\"v1\",\"k2\":\"v2\"}")); } }
@Test public void shouldSendPostHttpMessageWithEntityContent() throws Exception { whenHttp(server).match(post("/test"), withPostBodyContaining("Hello")) .then(status(HttpStatus.OK_200)); try (HttpClientHandler clientHandler = new HttpClientHandler(defaultOptions())) { ClientHandler handler = new ClientHandler(clientHandler); Request request = new Request(); request.setMethod("POST"); request.setUri(format("http: request.getEntity().setString("Hello"); assertThat(handler.handle(new RootContext(), request).get().getStatus()) .isEqualTo(Status.OK); } }
@Test public void shouldSendPostHttpMessageWithEmptyEntity() throws Exception { whenHttp(server).match(post("/test"), not(withPostBody())) .then(status(HttpStatus.OK_200)); try (HttpClientHandler clientHandler = new HttpClientHandler(defaultOptions())) { ClientHandler handler = new ClientHandler(clientHandler); Request request = new Request(); request.setMethod("POST"); request.setUri(format("http: assertThat(handler.handle(new RootContext(), request).get() .getStatus()).isEqualTo(Status.OK); } }
@Test public void shouldLogException() throws Exception { Exception cause = new Exception("Boom"); Response response = new Response(Status.INTERNAL_SERVER_ERROR).setCause(cause); when(delegate.handle(any(Context.class), any(Request.class))) .thenReturn(Response.newResponsePromise(response)); ClientHandler handler = new ClientHandler(delegate); Logger logger = mock(Logger.class); handler.setLogger(logger); handler.handle(new RootContext(), new Request()); verify(logger).warning(cause); }