private void verifyWritablePartitionsReturned(ClusterMapUtils.PartitionSelectionHelper psh,
      Set<MockPartitionId> allPartitionIds, String classBeingTested, MockPartitionId testedPart1,
      MockPartitionId testedPart2, String classNotBeingTested,
      Set<MockPartitionId> expectedReturnForClassNotBeingTested, String localDc) {
    Set<MockPartitionId> expectedReturnForClassBeingTested = new HashSet<>(Arrays.asList(testedPart1, testedPart2));
    // no problematic scenarios
    verifyGetWritablePartition(psh, allPartitionIds, classBeingTested, expectedReturnForClassBeingTested, localDc);
    verifyGetRandomWritablePartition(psh, allPartitionIds, classBeingTested, expectedReturnForClassBeingTested,
        localDc);

    //verify excluded partitions behavior in getRandomPartition
    assertNull(psh.getRandomWritablePartition(null, new ArrayList<>(allPartitionIds)));

    if (localDc != null && !localDc.isEmpty()) {
      checkCaseInsensitivityForPartitionSelectionHelper(psh, false, classBeingTested,
          expectedReturnForClassBeingTested);
    }

    // one replica of one partition of "classBeingTested" down
    ((MockReplicaId) testedPart1.getReplicaIds().get(0)).markReplicaDownStatus(true);
    allPartitionIds.remove(testedPart1);
    expectedReturnForClassBeingTested.remove(testedPart1);
    verifyGetWritablePartition(psh, allPartitionIds, classBeingTested, expectedReturnForClassBeingTested, localDc);
    //for getRandomWritablePartition one replica being down doesnt change anything unless its a local replica
    expectedReturnForClassBeingTested.add(testedPart1);
    verifyGetRandomWritablePartition(psh, allPartitionIds, classBeingTested, expectedReturnForClassBeingTested,
        localDc);

    // one replica of other partition of "classBeingTested" down too
    ((MockReplicaId) testedPart2.getReplicaIds().get(0)).markReplicaDownStatus(true);
    allPartitionIds.remove(testedPart2);
    // if both have a replica down, then even though both are unhealthy, they are both returned.
    expectedReturnForClassBeingTested.add(testedPart1);
    verifyGetWritablePartition(psh, allPartitionIds, classBeingTested, expectedReturnForClassBeingTested, localDc);
    verifyGetRandomWritablePartition(psh, allPartitionIds, classBeingTested, expectedReturnForClassBeingTested,
        localDc);

    if (expectedReturnForClassNotBeingTested != null) {
      assertCollectionEquals("Partitions returned not as expected", expectedReturnForClassNotBeingTested,
          psh.getWritablePartitions(classNotBeingTested));
    }

    ((MockReplicaId) testedPart1.getReplicaIds().get(0)).markReplicaDownStatus(false);
    ((MockReplicaId) testedPart2.getReplicaIds().get(0)).markReplicaDownStatus(false);
    allPartitionIds.add(testedPart1);
    allPartitionIds.add(testedPart2);

    // one partition of "classBeingTested" is READ_ONLY
    ((MockReplicaId) testedPart1.getReplicaIds().get(0)).setReplicaSealStatus(ReplicaSealStatus.SEALED);
    allPartitionIds.remove(testedPart1);
    expectedReturnForClassBeingTested.remove(testedPart1);
    verifyGetWritablePartition(psh, allPartitionIds, classBeingTested, expectedReturnForClassBeingTested, localDc);
    verifyGetRandomWritablePartition(psh, allPartitionIds, classBeingTested, expectedReturnForClassBeingTested,
        localDc);

    // all READ_ONLY
    ((MockReplicaId) testedPart2.getReplicaIds().get(0)).setReplicaSealStatus(ReplicaSealStatus.SEALED);
    allPartitionIds.remove(testedPart2);
    expectedReturnForClassBeingTested.remove(testedPart2);
    verifyGetWritablePartition(psh, allPartitionIds, classBeingTested, expectedReturnForClassBeingTested, localDc);
    verifyGetRandomWritablePartition(psh, allPartitionIds, classBeingTested, null, localDc);

    if (expectedReturnForClassNotBeingTested != null) {
      assertCollectionEquals("Partitions returned not as expected", expectedReturnForClassNotBeingTested,
          psh.getWritablePartitions(classNotBeingTested));
    }

    //cleanup the cluster map
    ((MockReplicaId) testedPart1.getReplicaIds().get(0)).setReplicaSealStatus(ReplicaSealStatus.NOT_SEALED);
    ((MockReplicaId) testedPart2.getReplicaIds().get(0)).setReplicaSealStatus(ReplicaSealStatus.NOT_SEALED);
    allPartitionIds.add(testedPart1);
    allPartitionIds.add(testedPart2);
    expectedReturnForClassBeingTested.add(testedPart1);
    expectedReturnForClassBeingTested.remove(testedPart2);
  }
Verifies that the values returned {@link ClusterMapUtils.PartitionSelectionHelper#getWritablePartitions(String)} and
 {@link ClusterMapUtils.PartitionSelectionHelper#getRandomWritablePartition(String, List)}  is correct.
@param psh the {@link ClusterMapUtils.PartitionSelectionHelper} instance to use.
@param allPartitionIds all the partitions that are in clustermap
@param classBeingTested the partition class being tested
@param testedPart1 a partition in {@code classBeingTested}
@param testedPart2 another partition in {@code classBeingTested}
@param classNotBeingTested a partition class is not being tested (to check that changes to partitions in
{@code classBeingTested} aren't affected).
@param expectedReturnForClassNotBeingTested the list of partitions that can expected to be returned for
                                            {@code classNotBeingTested}.
@param localDc the local dc name.
ambry-clustermap/src/test/java/com/github/ambry/clustermap/ClusterMapUtilsTest.java