### Question:
ProviderHostInfo extends RestAbstract { @GET public Response getHostInfo(@PathParam("id") int id) throws UnirestException { logger.info("GET /" + id + "/hostinfo"); Provider provider = providerDAO.getById(id); if(provider != null) { HttpResponse<String> response = Unirest.get(provider.getVmmUrl() + "/nodes").header("accept", "application/json").asString(); String payload = response.getBody(); return buildResponse(Status.OK, payload); } else { logger.debug("RESPONSE: 404"); return buildResponse(Status.NOT_FOUND, "No provider by that id found in the databae."); } }  @GET Response getHostInfo(@PathParam("id") int id);  }### Answer:
@Test public void getHostInfo404Test() throws Exception { ProviderDAO providerDAO = mock(ProviderDAO.class); when(providerDAO.getById(1)).thenReturn(null); ProviderHostInfo providerHostInfo = new ProviderHostInfo(); providerHostInfo.providerDAO = providerDAO; Response response = providerHostInfo.getHostInfo(1); assertEquals(404, response.getStatus()); String providerXML = (String) response.getEntity(); assertEquals("No provider by that id found in the databae.", providerXML); }
@Test public void getHostInfoTest() throws Exception { String payload = "{\"nodes\":[{\"hostname\":\"wally152\",\"totalCpus\":8,\"totalMemoryMb\":16022.0,\"totalDiskGb\":1805.0,\"assignedCpus\":3.0,\"assignedMemoryMb\":4096.0,\"assignedDiskGb\":41.0,\"currentPower\":0.0,\"turnedOff\":{\"value\":1}},{\"hostname\":\"wally153\",\"totalCpus\":8,\"totalMemoryMb\":16022.0,\"totalDiskGb\":1805.0,\"assignedCpus\":2.0,\"assignedMemoryMb\":3072.0,\"assignedDiskGb\":4.0,\"currentPower\":0.0,\"turnedOff\":{\"value\":1}},{\"hostname\":\"wally154\",\"totalCpus\":8,\"totalMemoryMb\":16022.0,\"totalDiskGb\":1805.0,\"assignedCpus\":8.0,\"assignedMemoryMb\":16896.0,\"assignedDiskGb\":120.0,\"currentPower\":0.0,\"turnedOff\":{\"value\":1}}]}"; mServer.addPath("/nodes", payload); Provider provider = new Provider(); provider.setVmmUrl(mBaseURL); ProviderDAO providerDAO = mock(ProviderDAO.class); when(providerDAO.getById(1)).thenReturn(provider); ProviderHostInfo providerHostInfo = new ProviderHostInfo(); providerHostInfo.providerDAO = providerDAO; Response response = providerHostInfo.getHostInfo(1); assertEquals(200, response.getStatus()); String nodesJson = (String) response.getEntity(); assertEquals(payload, nodesJson); }