### Question:
RemoteAmbariCluster implements Cluster { @Override public List<String> getHostsForServiceComponent(String serviceName, String componentName) { String url = String.format("%s/services/%s/components/%s?" + "fields=host_components/HostRoles/host_name", this.clusterPath, serviceName, componentName); List<String> hosts = new ArrayList<>(); try { JsonElement response = configurationCache.get(url); if (response == null || !response.isJsonObject()) return hosts; JsonElement hostComponents = response.getAsJsonObject().get("host_components"); if (hostComponents == null || !hostComponents.isJsonArray()) return hosts; for (JsonElement element : hostComponents.getAsJsonArray()) { JsonElement hostRoles = element.getAsJsonObject().get("HostRoles"); String hostName = hostRoles.getAsJsonObject().get("host_name").getAsString(); hosts.add(hostName); } } catch (ExecutionException e) { throw new RemoteAmbariConfigurationReadException("Can't retrieve host information from Remote Ambari", e); } return hosts; } RemoteAmbariCluster(RemoteAmbariClusterEntity remoteAmbariClusterEntity, Configuration config);  RemoteAmbariCluster(String name, String clusterPath, AmbariStreamProvider streamProvider); @Override String getName(); @Override String getConfigurationValue(String type, String key); @Override Map<String, String> getConfigByType(String type); @Override List<String> getHostsForServiceComponent(String serviceName, String componentName); Set<String> getServices(); boolean isAmbariOrClusterAdmin(); static final String AMBARI_OR_CLUSTER_ADMIN; }### Answer:
@Test public void testGetHostsForServiceComponent() throws IOException, AmbariHttpException { final String componentHostsString = "{\"host_components\": [{" + "\"HostRoles\": {" + "\"cluster_name\": \"Ambari\"," + "\"host_name\": \"host1\"}}, {" + "\"HostRoles\": {" + "\"cluster_name\": \"Ambari\"," + "\"host_name\": \"host2\"}}]}"; AmbariStreamProvider clusterStreamProvider = createNiceMock(AmbariStreamProvider.class); String service = "SERVICE"; String component = "COMPONENT"; final String clusterPath = "/api/v1/clusters/Test"; expect(clusterStreamProvider.readFrom(eq(String.format("%s/services/%s/components/%s?" + "fields=host_components/HostRoles/host_name", clusterPath, service, component)), eq("GET"), (String) isNull(), EasyMock.anyObject())) .andReturn(new ByteArrayInputStream(componentHostsString.getBytes())); RemoteAmbariClusterEntity entity = createNiceMock(RemoteAmbariClusterEntity.class); replay(clusterStreamProvider,entity); RemoteAmbariCluster cluster = new RemoteAmbariCluster("Test", clusterPath, clusterStreamProvider); List<String> hosts = cluster.getHostsForServiceComponent(service,component); Assert.assertEquals(2, hosts.size()); Assert.assertEquals("host1",hosts.get(0)); Assert.assertEquals("host2",hosts.get(1)); verify(clusterStreamProvider, entity); }