@Test
  public void testHostInfoCachingSingleHost() 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));

    // in second handling case NPE will be fired during result processing
    doReturn(Response.status(200).entity(String.format(SINGLE_HOST_RESPONSE, "hostName1")).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);

    String secondResponse = command.getHostsInformation(request);
    assertEquals(String.format(SINGLE_HOST_RESPONSE, "hostName1"), secondResponse);
  }
Try to retrieve host info twice. The inner cache should be populated with first usage (with handleRequest method calling).
And for next info retrieving for the same host the saved value should be used.
ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommandTest.java