@Test public void testCheckResponseMatch() { RestClient restClient = new RestClient(endpoint, HttpAsyncClients.createDefault()); HttpResponse httpResponse = mock(HttpResponse.class); StatusLine statusLine = mock(StatusLine.class); when(httpResponse.getStatusLine()).thenReturn(statusLine); when(statusLine.getStatusCode()).thenReturn(404); restClient.checkResponse(httpResponse, 404); }
public void checkResponse(HttpResponse httpResponse, int expected) { int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != expected) { 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 checkResponse(HttpResponse httpResponse, int expected) { int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != expected) { 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 checkResponse(HttpResponse httpResponse, int expected) { int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != expected) { 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, CloseableHttpAsyncClient asyncClient);  RestClient(String target, CloseableHttpAsyncClient asyncClient, String sharedSecret);  RestClient(String target, CloseableHttpAsyncClient asyncClient, HttpClient mockHttpClient); }
RestClient { public void checkResponse(HttpResponse httpResponse, int expected) { int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != expected) { 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, CloseableHttpAsyncClient asyncClient);  RestClient(String target, CloseableHttpAsyncClient asyncClient, String sharedSecret);  RestClient(String target, CloseableHttpAsyncClient asyncClient, HttpClient mockHttpClient); HttpResponse perform(final Method method, final String path, final HttpEntity payload); Future<HttpResponse> performAsync(final Method method, final String path, final HttpEntity payload,
                                           final FutureCallback<HttpResponse> responseHandler); void checkResponse(HttpResponse httpResponse, int expected); T parseHttpResponse(HttpResponse response, TypeReference<T> classType); HttpResponse upload(String path, String inputFileName, Map<String, String> arguments); HttpResponse upload(String path, FileBody fileBody, Map<String, String> arguments); }
RestClient { public void checkResponse(HttpResponse httpResponse, int expected) { int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != expected) { 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, CloseableHttpAsyncClient asyncClient);  RestClient(String target, CloseableHttpAsyncClient asyncClient, String sharedSecret);  RestClient(String target, CloseableHttpAsyncClient asyncClient, HttpClient mockHttpClient); HttpResponse perform(final Method method, final String path, final HttpEntity payload); Future<HttpResponse> performAsync(final Method method, final String path, final HttpEntity payload,
                                           final FutureCallback<HttpResponse> responseHandler); void checkResponse(HttpResponse httpResponse, int expected); T parseHttpResponse(HttpResponse response, TypeReference<T> classType); HttpResponse upload(String path, String inputFileName, Map<String, String> arguments); HttpResponse upload(String path, FileBody fileBody, Map<String, String> arguments); static final String AUTHORIZATION_HEADER; static final String AUTHORIZATION_METHOD; }