### Question:
HttpRequest implements Request { @Override public Response<GraphModel> execute(GraphModelRequest request) { if (request.getStatement().length() == 0) { return new EmptyResponse(); } else { String cypher = cypherRequest(request); return new GraphModelResponse(executeRequest(cypher)); } } HttpRequest(CloseableHttpClient httpClient, String url, Credentials credentials);  HttpRequest(CloseableHttpClient httpClient, String url, Credentials credentials, boolean readOnly); @Override Response<GraphModel> execute(GraphModelRequest request); @Override Response<RowModel> execute(RowModelRequest request); @Override Response<RowModel> execute(DefaultRequest query); @Override Response<GraphRowListModel> execute(GraphRowListModelRequest request); @Override Response<RestModel> execute(RestModelRequest request); static CloseableHttpResponse execute(CloseableHttpClient httpClient, HttpRequestBase request,
        Credentials credentials);  }### Answer:
@Test public void shouldHandleErrorJsonResponseGracefully() { final String failWithJsonUrl = "http: final String validJsonResponse = "" + "{\"errors\":[" + " {\"message\":\"This is an error\"}" + ",{\"message\":\"This is another error\"}" + "]}"; final HttpClientMock httpClientMock = new HttpClientMock(); httpClientMock.onGet(failWithJsonUrl) .doReturn(validJsonResponse) .withStatus(HttpStatus.SC_BAD_GATEWAY) .withHeader(CONTENT_TYPE, APPLICATION_JSON.getMimeType()); assertThatExceptionOfType(ConnectionException.class) .isThrownBy(() -> HttpRequest.execute(httpClientMock, new HttpGet(failWithJsonUrl), null)) .withRootCauseInstanceOf(HttpResponseException.class) .withStackTraceContaining("This is an error"); }
@Test public void shouldHandleErrorNonJsonResponseGracefully() { final String failWithHtmlUrl = "http: final String htmlResponse = "" + "<!DOCTYPE html>" + "<html lang=\"en\">" + "<head>" + "<meta charset=\"utf-8\">" + "<title>Error</title>" + "</head>" + "<body>" + "<pre>Cannot POST /db/data/transaction/commit</pre>" + "</body>" + "</html> "; final HttpClientMock httpClientMock = new HttpClientMock(); httpClientMock.onGet(failWithHtmlUrl) .doReturn(htmlResponse) .withStatus(HttpStatus.SC_BAD_GATEWAY) .withHeader(CONTENT_TYPE, TEXT_HTML.getMimeType()); assertThatExceptionOfType(ConnectionException.class) .isThrownBy(() -> HttpRequest.execute(httpClientMock, new HttpGet(failWithHtmlUrl), null)) .withRootCauseInstanceOf(HttpResponseException.class) .withStackTraceContaining("Could not parse the servers response as JSON"); }