@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "HTTP request failed with: 404") public void testCheckResponseMismatch() { RestClient restClient = new RestClient(target, username, password, HttpAsyncClients.createDefault()); HttpResponse httpResponse = mock(HttpResponse.class); StatusLine statusLine = mock(StatusLine.class); when(httpResponse.getStatusLine()).thenReturn(statusLine); when(statusLine.getStatusCode()).thenReturn(404); restClient.check(httpResponse, 200); }
public void check(HttpResponse httpResponse, int expectedResponseCode) { int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != expectedResponseCode) { StringBuilder msg = new StringBuilder(); msg.append("HTTP request failed with: "); msg.append(statusCode); if (httpResponse.getEntity() != null) { try { msg.append(", "); msg.append(EntityUtils.toString(httpResponse.getEntity())); } catch (IOException e) { } } throw new RuntimeException(msg.toString()); } }
RestClient { public void check(HttpResponse httpResponse, int expectedResponseCode) { int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != expectedResponseCode) { StringBuilder msg = new StringBuilder(); msg.append("HTTP request failed with: "); msg.append(statusCode); if (httpResponse.getEntity() != null) { try { msg.append(", "); msg.append(EntityUtils.toString(httpResponse.getEntity())); } catch (IOException e) { } } throw new RuntimeException(msg.toString()); } } }
RestClient { public void check(HttpResponse httpResponse, int expectedResponseCode) { int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != expectedResponseCode) { StringBuilder msg = new StringBuilder(); msg.append("HTTP request failed with: "); msg.append(statusCode); if (httpResponse.getEntity() != null) { try { msg.append(", "); msg.append(EntityUtils.toString(httpResponse.getEntity())); } catch (IOException e) { } } throw new RuntimeException(msg.toString()); } } RestClient(String target, String username, String password);  RestClient(String target, String username, String password, CloseableHttpAsyncClient asyncClient); }
RestClient { public void check(HttpResponse httpResponse, int expectedResponseCode) { int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != expectedResponseCode) { StringBuilder msg = new StringBuilder(); msg.append("HTTP request failed with: "); msg.append(statusCode); if (httpResponse.getEntity() != null) { try { msg.append(", "); msg.append(EntityUtils.toString(httpResponse.getEntity())); } catch (IOException e) { } } throw new RuntimeException(msg.toString()); } } RestClient(String target, String username, String password);  RestClient(String target, String username, String password, CloseableHttpAsyncClient asyncClient); HttpResponse send(final Method method, final String path, final HttpEntity payload); Future<HttpResponse> sendAsync(final Method method, final String path, final HttpEntity payload,
                                           final FutureCallback<HttpResponse> responseHandler); void check(HttpResponse httpResponse, int expectedResponseCode); }
RestClient { public void check(HttpResponse httpResponse, int expectedResponseCode) { int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != expectedResponseCode) { StringBuilder msg = new StringBuilder(); msg.append("HTTP request failed with: "); msg.append(statusCode); if (httpResponse.getEntity() != null) { try { msg.append(", "); msg.append(EntityUtils.toString(httpResponse.getEntity())); } catch (IOException e) { } } throw new RuntimeException(msg.toString()); } } RestClient(String target, String username, String password);  RestClient(String target, String username, String password, CloseableHttpAsyncClient asyncClient); HttpResponse send(final Method method, final String path, final HttpEntity payload); Future<HttpResponse> sendAsync(final Method method, final String path, final HttpEntity payload,
                                           final FutureCallback<HttpResponse> responseHandler); void check(HttpResponse httpResponse, int expectedResponseCode);  }