private void checkReplicaDistribution(Map<Integer, List<Integer>> assignment,
                                         Map<Integer, String> brokerRackMapping,
                                         Integer numBrokers,
                                         Integer numPartitions,
                                         Integer replicationFactor,
                                         Boolean verifyRackAware,
                                         Boolean verifyLeaderDistribution,
                                         Boolean verifyReplicasDistribution) {
        // always verify that no broker will be assigned for more than one replica
        assignment.entrySet().stream()
            .forEach(entry -> assertEquals(new HashSet<>(entry.getValue()).size(), entry.getValue().size(),
                "More than one replica is assigned to same broker for the same partition"));

        ReplicaDistributions distribution = getReplicaDistribution(assignment, brokerRackMapping);

        if (verifyRackAware) {
            Map<Integer, List<String>> partitionRackMap = distribution.partitionRacks;

            List<Integer> partitionRackMapValueSize = partitionRackMap.values().stream()
                .map(value -> (int) value.stream().distinct().count())
                .collect(Collectors.toList());

            List<Integer> expected = Collections.nCopies(numPartitions, replicationFactor);
            assertEquals(expected, partitionRackMapValueSize, "More than one replica of the same partition is assigned to the same rack");
        }

        if (verifyLeaderDistribution) {
            Map<Integer, Integer> leaderCount = distribution.brokerLeaderCount;
            int leaderCountPerBroker = numPartitions / numBrokers;
            List<Integer> expected = Collections.nCopies(numBrokers, leaderCountPerBroker);
            assertEquals(expected, new ArrayList<>(leaderCount.values()), "Preferred leader count is not even for brokers");
        }

        if (verifyReplicasDistribution) {
            Map<Integer, Integer> replicasCount = distribution.brokerReplicasCount;
            int numReplicasPerBroker = numPartitions * replicationFactor / numBrokers;
            List<Integer> expected = Collections.nCopies(numBrokers, numReplicasPerBroker);
            assertEquals(expected, new ArrayList<>(replicasCount.values()), "Replica count is not even for broker");
        }
    }
Test describe --under-min-isr-partitions option with four topics:
  (1) topic with partition under the configured min ISR count
  (2) topic with under-replicated partition (but not under min ISR count)
  (3) topic with offline partition
  (4) topic with fully replicated partition

Output should only display the (1) topic with partition under min ISR count and (3) topic with offline partition
tools/src/test/java/org/apache/kafka/tools/TopicCommandIntegrationTest.java