### Question:
UpgradePack { public List<Grouping> getGroups(Direction direction) { List<Grouping> list = new ArrayList<>(); if (direction.isUpgrade()) { list = groups; } else { switch (type) { case NON_ROLLING: list = getDowngradeGroupsForNonrolling(); break; case HOST_ORDERED: case ROLLING: default: list = getDowngradeGroupsForRolling(); break; } } List<Grouping> checked = new ArrayList<>(); for (Grouping group : list) { if (null == group.intendedDirection || direction == group.intendedDirection) { checked.add(group); } } return checked; }  String getName(); void setName(String name); String getTarget(); UpgradeType getType(); List<String> getPrerequisiteChecks(); PrerequisiteCheckConfig getPrerequisiteCheckConfig(); void mergePrerequisiteChecks(UpgradePack pack); void mergeProcessing(UpgradePack pack); List<IntermediateStack> getIntermediateStacks(); String getTargetStack(); boolean isComponentFailureAutoSkipped(); boolean isServiceCheckFailureAutoSkipped(); List<Grouping> getAllGroups(); List<Grouping> getGroups(Direction direction); boolean isDowngradeAllowed(); boolean canBeApplied(String targetVersion); Map<String, Map<String, ProcessingComponent>> getTasks(); Map<String, AddComponentTask> getAddComponentTasks(); boolean isAllTarget(); boolean anyGroupTaskMatch(Predicate<Task> taskPredicate);  }### Answer:
@Test public void testGroupOrdersForNonRolling() { Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1"); assertTrue(upgrades.size() > 0); assertTrue(upgrades.containsKey("upgrade_test_nonrolling")); UpgradePack upgrade = upgrades.get("upgrade_test_nonrolling"); List<String> expected_up = Arrays.asList( "PRE_CLUSTER", "Stop High-Level Daemons", "Backups", "Stop Low-Level Daemons", "UPDATE_DESIRED_REPOSITORY_ID", "ALL_HOST_OPS", "ZOOKEEPER", "HDFS", "MR and YARN", "POST_CLUSTER"); List<String> expected_down = Arrays.asList( "Restore Backups", "UPDATE_DESIRED_REPOSITORY_ID", "ALL_HOST_OPS", "ZOOKEEPER", "HDFS", "MR and YARN", "POST_CLUSTER"); Iterator<String> itr_up = expected_up.iterator(); List<Grouping> upgrade_groups = upgrade.getGroups(Direction.UPGRADE); for (Grouping g : upgrade_groups) { assertEquals(true, itr_up.hasNext()); assertEquals(itr_up.next(), g.name); } Iterator<String> itr_down = expected_down.iterator(); List<Grouping> downgrade_groups = upgrade.getGroups(Direction.DOWNGRADE); for (Grouping g : downgrade_groups) { assertEquals(true, itr_down.hasNext()); assertEquals(itr_down.next(), g.name); } }
@Test public void testNoAutoSkipFailure() throws Exception { Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.2.0"); UpgradePack upgradePack = upgrades.get("upgrade_test_skip_failures"); List<Grouping> groups = upgradePack.getGroups(Direction.UPGRADE); for (Grouping grouping : groups) { if (grouping.name.equals("SKIPPABLE_BUT_NOT_AUTO_SKIPPABLE")) { Assert.assertFalse(grouping.supportsAutoSkipOnFailure); } else { Assert.assertTrue(grouping.supportsAutoSkipOnFailure); } } }