@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));

    // nothing happened, so this should be empty
    Assert.assertTrue(stageWrappers.isEmpty());

    verifyAll();
  }
Tests that the various build methods of a builder are invoked in the
correct order.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/state/stack/upgrade/StageWrapperBuilderTest.java