void validateForUpdatePartitionLeadership(Metadata updatedMetadata,
                                              PartitionMetadata part1Metadata, PartitionMetadata part2Metadata, PartitionMetadata part12Metadata,
                                              PartitionMetadata internalPartMetadata,
                                              List<Node> expectedNodes,
                                              String expectedClusterId,
                                              Set<String> expectedUnauthorisedTopics, Set<String> expectedInvalidTopics, Set<String> expectedInternalTopics,
                                              Node expectedController,
                                              Map<String, Uuid> expectedTopicIds) {
        Cluster updatedCluster = updatedMetadata.fetch();
        assertEquals(updatedCluster.clusterResource().clusterId(), expectedClusterId);
        assertEquals(new HashSet<>(expectedNodes), new HashSet<>(updatedCluster.nodes()));
        assertEquals(3, updatedCluster.topics().size());
        assertEquals(expectedInternalTopics, updatedCluster.internalTopics());
        assertEquals(expectedInvalidTopics, updatedCluster.invalidTopics());
        assertEquals(expectedUnauthorisedTopics, updatedCluster.unauthorizedTopics());
        assertEquals(expectedController, updatedCluster.controller());
        assertEquals(expectedTopicIds, updatedMetadata.topicIds());

        Map<Integer, Node> nodeMap = expectedNodes.stream().collect(Collectors.toMap(Node::id, e -> e));
        for (PartitionMetadata partitionMetadata: Arrays.asList(part1Metadata, part2Metadata, part12Metadata, internalPartMetadata)) {
            TopicPartition tp = new TopicPartition(partitionMetadata.topic(), partitionMetadata.partition());

            Metadata.LeaderAndEpoch expectedLeaderInfo = new Metadata.LeaderAndEpoch(Optional.of(nodeMap.get(partitionMetadata.leaderId.get())), partitionMetadata.leaderEpoch);
            assertEquals(expectedLeaderInfo, updatedMetadata.currentLeader(tp));

            // Compare the partition-metadata.
            Optional<PartitionMetadata> optionalUpdatedMetadata = updatedMetadata.partitionMetadataIfCurrent(tp);
            assertTrue(optionalUpdatedMetadata.isPresent());
            PartitionMetadata updatedPartMetadata = optionalUpdatedMetadata.get();
            assertEquals(partitionMetadata.topicPartition, updatedPartMetadata.topicPartition);
            assertEquals(partitionMetadata.error, updatedPartMetadata.error);
            assertEquals(partitionMetadata.leaderId, updatedPartMetadata.leaderId);
            assertEquals(partitionMetadata.leaderEpoch, updatedPartMetadata.leaderEpoch);
            assertEquals(partitionMetadata.replicaIds, updatedPartMetadata.replicaIds);
            assertEquals(partitionMetadata.inSyncReplicaIds, updatedPartMetadata.inSyncReplicaIds);
            assertEquals(partitionMetadata.offlineReplicaIds, partitionMetadata.offlineReplicaIds);
        }
    }
For testUpdatePartially, validates that updatedMetadata is matching expected part1Metadata, part2Metadata, internalPartMetadata, nodes & more.
clients/src/test/java/org/apache/kafka/clients/MetadataTest.java