### Question:
RequestStageContainer { public State getProjectedState(String host, String component) { RoleCommand lastCommand = null; ListIterator<Stage> iterator = stages.listIterator(stages.size()); while (lastCommand == null && iterator.hasPrevious()) { Stage stage = iterator.previous(); Map<String, Map<String, HostRoleCommand>> stageCommands = stage.getHostRoleCommands(); if (stageCommands != null) { Map<String, HostRoleCommand> hostCommands = stageCommands.get(host); if (hostCommands != null) { HostRoleCommand roleCommand = hostCommands.get(component); if (roleCommand != null && roleCommand.getRoleCommand() != RoleCommand.SERVICE_CHECK) { lastCommand = roleCommand.getRoleCommand(); } } } } State resultingState = null; if (lastCommand != null) { switch(lastCommand) { case INSTALL: case STOP: resultingState = State.INSTALLED; break; case START: resultingState = State.STARTED; break; case UNINSTALL: resultingState = State.INIT; break; default: resultingState = State.UNKNOWN; } } return resultingState; } RequestStageContainer(Long id, List<Stage> stages, RequestFactory factory, ActionManager manager);  RequestStageContainer(Long id, List<Stage> stages, RequestFactory factory, ActionManager manager,
                               ExecuteActionRequest actionRequest); Long getId(); void setClusterHostInfo(String clusterHostInfo); void addStages(List<Stage> stages); List<Stage> getStages(); long getLastStageId(); void setRequestContext(String context); State getProjectedState(String host, String component); void persist(); RequestStatusResponse getRequestStatusResponse();  }### Answer:
@Test public void testGetProjectedState() { String hostname = "host"; String componentName = "component"; Stage stage1 = createNiceMock(Stage.class); Stage stage2 = createNiceMock(Stage.class); Stage stage3 = createNiceMock(Stage.class); Stage stage4 = createNiceMock(Stage.class); HostRoleCommand command1 = createNiceMock(HostRoleCommand.class); HostRoleCommand command2 = createNiceMock(HostRoleCommand.class); HostRoleCommand command3 = createNiceMock(HostRoleCommand.class); List<Stage> stages = new ArrayList<>(); stages.add(stage1); stages.add(stage2); stages.add(stage3); stages.add(stage4); expect(stage1.getHostRoleCommands()).andReturn(Collections.singletonMap(hostname, Collections.singletonMap(componentName, command1))).anyTimes(); expect(stage2.getHostRoleCommands()).andReturn(Collections.singletonMap(hostname, Collections.singletonMap(componentName, command2))).anyTimes(); expect(stage3.getHostRoleCommands()).andReturn(Collections.singletonMap(hostname, Collections.singletonMap(componentName, command3))).anyTimes(); expect(stage4.getHostRoleCommands()).andReturn(Collections.emptyMap()).anyTimes(); expect(command3.getRoleCommand()).andReturn(RoleCommand.SERVICE_CHECK).anyTimes(); expect(command2.getRoleCommand()).andReturn(RoleCommand.INSTALL).anyTimes(); replay(stage1, stage2, stage3, stage4, command1, command2, command3); RequestStageContainer requestStages = new RequestStageContainer(1L, stages, null, null); assertEquals(State.INSTALLED, requestStages.getProjectedState(hostname, componentName)); verify(stage1, stage2, stage3, stage4, command1, command2, command3); }