final String requestUrl = String.format("%s%s", STUBS_URL, "/maps/api/geocode/json?sensor=false&address=1600+Amphitheatre+Parkway,+Mountain+View,+CA");
final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
final int LIMIT = 5;
for (int idx = 1; idx <= LIMIT; idx++) {
final HttpResponse response = request.execute();
final String actualConsoleOutput = consoleCaptor.toString(StringUtils.UTF_8).trim();
if (idx == 1) {
if (actualConsoleOutput.contains("Exception")) {
System.setOut(oldPrintStream);
System.out.println(actualConsoleOutput);
// If we are here, it means we do not have active Internet connection (or something else has happened)
// and we could not hit Google in that case, there is no point to causing this test to fail if the user
// running this test without having the ability to access the Internet.
break;
}
}
final HttpHeaders headers = response.getHeaders();
assertThat(headers.getContentType().contains(HEADER_APPLICATION_JSON)).isTrue();
String responseContent = response.parseAsString().trim();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
assertThat(responseContent).contains("results");
assertThat(responseContent).contains("address_components");
assertThat(responseContent).contains("formatted_address");
// Make sure we only hitting recordabe source once