### Question:
StageWrapperBuilder { public final List<StageWrapper> build(UpgradeContext upgradeContext) { List<StageWrapper> stageWrappers = beforeBuild(upgradeContext); stageWrappers = build(upgradeContext, stageWrappers); stageWrappers = afterBuild(upgradeContext, stageWrappers); return stageWrappers; } protected  StageWrapperBuilder(Grouping grouping); abstract void add(UpgradeContext upgradeContext, HostsType hostsType, String service,
      boolean clientOnly, ProcessingComponent pc, Map<String, String> params); final List<StageWrapper> build(UpgradeContext upgradeContext); abstract List<StageWrapper> build(UpgradeContext upgradeContext,
      List<StageWrapper> stageWrappers);  }### Answer:
@Test public void testBuildOrder() throws Exception { Cluster cluster = createNiceMock(Cluster.class); RepositoryVersionEntity repoVersionEntity = createNiceMock(RepositoryVersionEntity.class); EasyMock.expect(repoVersionEntity.getStackId()).andReturn(HDP_21).anyTimes(); RepositoryVersionDAO repoVersionDAO = createNiceMock(RepositoryVersionDAO.class); EasyMock.expect(repoVersionDAO.findByStackNameAndVersion(EasyMock.anyString(), EasyMock.anyString())).andReturn(repoVersionEntity).anyTimes(); UpgradeContext upgradeContext = EasyMock.createNiceMock(UpgradeContext.class); EasyMock.expect(upgradeContext.getCluster()).andReturn(cluster).anyTimes(); EasyMock.expect(upgradeContext.getType()).andReturn(UpgradeType.ROLLING).anyTimes(); EasyMock.expect(upgradeContext.getDirection()).andReturn(Direction.UPGRADE).anyTimes(); EasyMock.expect(upgradeContext.getRepositoryVersion()).andReturn(repoVersionEntity).anyTimes(); EasyMock.expect(upgradeContext.isComponentFailureAutoSkipped()).andReturn(false).anyTimes(); EasyMock.expect(upgradeContext.isServiceCheckFailureAutoSkipped()).andReturn(false).anyTimes(); replayAll(); MockStageWrapperBuilder builder = new MockStageWrapperBuilder(null); List<StageWrapper> stageWrappers = builder.build(upgradeContext); List<Integer> invocationOrder = builder.getInvocationOrder(); Assert.assertEquals(Integer.valueOf(0), invocationOrder.get(0)); Assert.assertEquals(Integer.valueOf(1), invocationOrder.get(1)); Assert.assertEquals(Integer.valueOf(2), invocationOrder.get(2)); Assert.assertTrue(stageWrappers.isEmpty()); verifyAll(); }