public Cluster buildCluster() {
        Set<String> internalTopics = new HashSet<>();
        List<PartitionInfo> partitions = new ArrayList<>();
        Map<String, Uuid> topicIds = new HashMap<>();

        for (TopicMetadata metadata : topicMetadata()) {
            if (metadata.error == Errors.NONE) {
                if (metadata.isInternal)
                    internalTopics.add(metadata.topic);
                if (metadata.topicId() != null && !Uuid.ZERO_UUID.equals(metadata.topicId())) {
                    topicIds.put(metadata.topic, metadata.topicId());
                }
                for (PartitionMetadata partitionMetadata : metadata.partitionMetadata) {
                    partitions.add(toPartitionInfo(partitionMetadata, holder().brokers));
                }
            }
        }
        return new Cluster(data.clusterId(), brokers(), partitions, topicsByError(Errors.TOPIC_AUTHORIZATION_FAILED),
                topicsByError(Errors.INVALID_TOPIC_EXCEPTION), internalTopics, controller(), topicIds);
    }
@Test
    void buildClusterTest() {
        Uuid zeroUuid = new Uuid(0L, 0L);
        Uuid randomUuid = Uuid.randomUuid();
        MetadataResponseData.MetadataResponseTopic topicMetadata1 = new MetadataResponseData.MetadataResponseTopic()
                .setName("topic1")
                .setErrorCode(Errors.NONE.code())
                .setPartitions(emptyList())
                .setIsInternal(false);
        MetadataResponseData.MetadataResponseTopic topicMetadata2 = new MetadataResponseData.MetadataResponseTopic()
                .setName("topic2")
                .setErrorCode(Errors.NONE.code())
                .setTopicId(zeroUuid)
                .setPartitions(emptyList())
                .setIsInternal(false);
        MetadataResponseData.MetadataResponseTopic topicMetadata3 = new MetadataResponseData.MetadataResponseTopic()
                .setName("topic3")
                .setErrorCode(Errors.NONE.code())
                .setTopicId(randomUuid)
                .setPartitions(emptyList())
                .setIsInternal(false);

        MetadataResponseData.MetadataResponseTopicCollection topics =
                new MetadataResponseData.MetadataResponseTopicCollection();
        topics.add(topicMetadata1);
        topics.add(topicMetadata2);
        topics.add(topicMetadata3);
        MetadataResponse metadataResponse = new MetadataResponse(new MetadataResponseData().setTopics(topics),
                ApiKeys.METADATA.latestVersion());
        Cluster cluster = metadataResponse.buildCluster();
        assertNull(cluster.topicName(Uuid.ZERO_UUID));
        assertNull(cluster.topicName(zeroUuid));
        assertEquals("topic3", cluster.topicName(randomUuid));
    }