### Question:
RequestStageContainer { public void persist() throws AmbariException { if (!stages.isEmpty()) { Request request = (null == actionRequest) ? requestFactory.createNewFromStages(stages, clusterHostInfo) : requestFactory.createNewFromStages(stages, clusterHostInfo, actionRequest); if (null != requestContext) { request.setRequestContext(requestContext); } if (request != null) { request.setUserName(AuthorizationHelper.getAuthenticatedName()); } if (request != null && request.getStages()!= null && !request.getStages().isEmpty()) { if (LOG.isDebugEnabled()) { LOG.debug("Triggering Action Manager, request={}", request); } actionManager.sendActions(request, actionRequest); } } } 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 testPersist() throws AmbariException { ActionManager actionManager = createStrictMock(ActionManager.class); RequestFactory requestFactory = createStrictMock(RequestFactory.class); Request request = createStrictMock(Request.class); Stage stage1 = createNiceMock(Stage.class); Stage stage2 = createNiceMock(Stage.class); List<Stage> stages = new ArrayList<>(); stages.add(stage1); stages.add(stage2); expect(requestFactory.createNewFromStages(stages, "{}")).andReturn(request); request.setUserName(null); expectLastCall().once(); expect(request.getStages()).andReturn(stages).anyTimes(); actionManager.sendActions(request, null); replay(actionManager, requestFactory, request, stage1, stage2); RequestStageContainer requestStages = new RequestStageContainer(1L, stages, requestFactory, actionManager); requestStages.persist(); verify(actionManager, requestFactory, request, stage1, stage2); }
@Test public void testPersist_noStages() throws AmbariException { ActionManager actionManager = createStrictMock(ActionManager.class); RequestFactory requestFactory = createStrictMock(RequestFactory.class); replay(actionManager, requestFactory); RequestStageContainer requestStages = new RequestStageContainer(1L, null, requestFactory, actionManager); requestStages.persist(); verify(actionManager, requestFactory); }