@Test
public void testBuildOrder() throws Exception {

  Cluster cluster = createNiceMock(Cluster.class);
  EasyMock.expect(cluster.getCurrentStackVersion()).andReturn(HDP_21).atLeastOnce();
  EasyMock.expect(cluster.getDesiredStackVersion()).andReturn(HDP_21).anyTimes();
  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();
  replayAll();
  UpgradeContext upgradeContext = new UpgradeContext(cluster, UpgradeType.ROLLING,
      Direction.UPGRADE, HDP_21.toString(), new HashMap<String, Object>(), repoVersionDAO);
  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();
}