### Question:
JdkHttpClient { String fetchString( String httpMethod, String urlStr, Map<String, String> requestPropertyMap, String certPath) { final HttpURLConnection connection; try { if (urlStr.startsWith("https")) { connection = (HttpURLConnection) new URL(urlStr).openConnection(); KeyStore keyStore = getKeystoreForTrustedCert(certPath); if (keyStore != null) { ((HttpsURLConnection) connection).setSSLSocketFactory(buildSslSocketFactory(keyStore)); } } else { connection = (HttpURLConnection) new URL(urlStr).openConnection(); } connection.setRequestMethod(httpMethod); connection.setConnectTimeout(TIMEOUT_MILLIS); connection.setReadTimeout(TIMEOUT_MILLIS); for (Map.Entry<String, String> requestProperty : requestPropertyMap.entrySet()) { connection.setRequestProperty(requestProperty.getKey(), requestProperty.getValue()); } int responseCode = connection.getResponseCode(); if (responseCode != 200) { logger.log( Level.FINE, "Error reponse from " + urlStr + " code (" + responseCode + ") text " + readResponseString(connection)); return ""; } return readResponseString(connection).trim(); } catch (IOException e) { logger.log(Level.FINE, "JdkHttpClient fetch string failed.", e); } return ""; }    }### Answer:
@Test public void testFetchString() throws IOException { stubFor(any(urlPathEqualTo("/path")).willReturn(ok("expected result"))); Map<String, String> requestPropertyMap = ImmutableMap.of("key1", "value1", "key2", "value2"); String urlStr = String.format("http: JdkHttpClient jdkHttpClient = new JdkHttpClient(); String result = jdkHttpClient.fetchString("GET", urlStr, requestPropertyMap, null); assertThat(result).isEqualTo("expected result"); verify(getRequestedFor(urlEqualTo("/path")).withHeader("key1", equalTo("value1"))); verify(getRequestedFor(urlEqualTo("/path")).withHeader("key2", equalTo("value2"))); }
@Test public void testFailedFetchString() { Map<String, String> requestPropertyMap = ImmutableMap.of("key1", "value1", "key2", "value2"); String urlStr = String.format("http: JdkHttpClient jdkHttpClient = new JdkHttpClient(); String result = jdkHttpClient.fetchString("GET", urlStr, requestPropertyMap, null); assertThat(result).isEmpty(); }