@Test
  public void testHostInfoCachingTwoHost() throws StackAdvisorException {
    File file = mock(File.class);
    String recommendationsArtifactsLifetime = "1w";
    StackAdvisorRunner stackAdvisorRunner = mock(StackAdvisorRunner.class);
    AmbariMetaInfo ambariMetaInfo = mock(AmbariMetaInfo.class);
    Map<String, JsonNode> hostInfoCache = new HashMap<>();
    TestStackAdvisorCommand command = spy(new TestStackAdvisorCommand(file, recommendationsArtifactsLifetime,
        ServiceInfo.ServiceAdvisorType.PYTHON, 1,
        stackAdvisorRunner, ambariMetaInfo, hostInfoCache));
    doReturn(Response.status(200).entity(String.format(SINGLE_HOST_RESPONSE, "hostName1")).build())
        .doReturn(Response.status(200).entity(String.format(SINGLE_HOST_RESPONSE, "hostName2")).build())
        .doReturn(null)
        .when(command).handleRequest(
                nullable(HttpHeaders.class),
                nullable(String.class),
                any(UriInfo.class),
                any(Request.Type.class),
                nullable(MediaType.class),
                any(ResourceInstance.class)
        );

    StackAdvisorRequest request = StackAdvisorRequestBuilder.
        forStack(null, null).ofType(StackAdvisorRequest.StackAdvisorRequestType.CONFIGURATIONS).
        forHosts(Arrays.asList(new String[]{"hostName1"})).
        build();
    String firstResponse = command.getHostsInformation(request);
    assertEquals(String.format(SINGLE_HOST_RESPONSE, "hostName1"), firstResponse);

    request = StackAdvisorRequestBuilder.
        forStack(null, null).ofType(StackAdvisorRequest.StackAdvisorRequestType.CONFIGURATIONS).
        forHosts(Arrays.asList(new String[]{"hostName1", "hostName2"})).
        build();
    String secondResponse = command.getHostsInformation(request);
    assertEquals(String.format(TWO_HOST_RESPONSE, "hostName1", "hostName2"), secondResponse);
  }
Try to retrieve multiple hosts info twice. The inner cache should be populated with first usage for first host (hostName1).
For the next usage with the both hosts handleRequest should be used for second host only.
ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommandTest.java