HttpUtils { public String executeHttpGetRequest(URL url) throws IOException { HttpURLConnection con = (HttpURLConnection)url.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); if (responseCode != 200) { return String.format("Error in HTTP GET : code [%d]", responseCode); } StringWriter output = new StringWriter(); IOUtils.copy(con.getInputStream(), output); return output.toString(); }  String wakeHaltedHostUsingHttpGet(String systemVmIp, String hostMac); String executeHttpGetRequest(URL url);  }
@Test @PrepareForTest({ HttpUtils.class, IOUtils.class }) public void executeHttpGetRequestTest() throws Exception { HttpURLConnection httpConn = configureExecuteHttpGetRequestTest(url, 200); spy.executeHttpGetRequest(url); verifyExecuteHttpGetRequestTest(httpConn, 1); }
@Test @PrepareForTest({ HttpUtils.class, IOUtils.class }) public void executeHttpGetRequestTestErrorCode() throws Exception { HttpURLConnection httpConn = configureExecuteHttpGetRequestTest(url, 400); String result = spy.executeHttpGetRequest(url); verifyExecuteHttpGetRequestTest(httpConn, 0); Assert.assertEquals(String.format("Error in HTTP GET : code [%d]", 400), result); }