Repository: apache/kafka
File: clients/src/test/java/org/apache/kafka/clients/consumer/internals/CommitRequestManagerTest.java (Java)

Code before:
                    ).collect(Collectors.toList()))
             ).collect(Collectors.toList()));
        return buildOffsetFetchClientResponse(request, group, false);
    }

    private ClientResponse buildOffsetFetchClientResponseDisconnected(
        final NetworkClientDelegate.UnsentRequest request) {
        return buildOffsetFetchClientResponse(request, new OffsetFetchResponseData.OffsetFetchResponseGroup(), true);
    }

    private ClientResponse buildOffsetCommitClientResponse(final OffsetCommitResponse commitResponse) {
        short apiVersion = 1;
        return new ClientResponse(
            new RequestHeader(ApiKeys.OFFSET_COMMIT, apiVersion, "", 1),
            null,
            "-1",
            time.milliseconds(),
            time.milliseconds(),
            false,
            null,
            null,
            commitResponse
        );
    }

    private ClientResponse mockOffsetCommitResponseWithTopicId(String topic,
                                                              Uuid topicId,
                                                              int partition,
                                                              short apiKeyVersion,
                                                              Errors error) {
        return mockOffsetCommitResponse(topic, topicId, partition, apiKeyVersion, time.milliseconds(), time.milliseconds(), error);
    }

    private ClientResponse mockOffsetCommitResponse(String topic,
                                                   int partition,
                                                   short apiKeyVersion,
                                                   Errors error) {
        return mockOffsetCommitResponse(topic, Uuid.ZERO_UUID, partition, apiKeyVersion, time.milliseconds(), time.milliseconds(), error);
    }

    private ClientResponse mockOffsetCommitResponse(String topic,
                                                   Uuid topicId,
                                                   int partition,
                                                   short apiKeyVersion,
                                                   long createdTimeMs,
                                                   long receivedTimeMs,
                                                   Errors error) {
        OffsetCommitResponseData responseData = new OffsetCommitResponseData()
            .setTopics(Collections.singletonList(
                new OffsetCommitResponseData.OffsetCommitResponseTopic()
                    .setName(topic)

Review comment (refactor):
commit responses with topic IDs will have empty topic name, so we should we remove this param and just pass empty on the call to `mockOffsetCommitResponse`? 

Code after:
            final Set<TopicPartition> topicPartitions,
            final Errors error) {
        OffsetFetchResponseData.OffsetFetchResponseGroup group = new OffsetFetchResponseData.OffsetFetchResponseGroup()
            .setGroupId(DEFAULT_GROUP_ID)
            .setErrorCode(error.code())
            .setTopics(topicPartitions.stream().collect(Collectors.groupingBy(TopicPartition::topic)).entrySet().stream().map(entry ->
                new OffsetFetchResponseData.OffsetFetchResponseTopics()
                    .setName(entry.getKey())
                    .setPartitions(entry.getValue().stream().map(partition ->
                        new OffsetFetchResponseData.OffsetFetchResponsePartitions()
                            .setPartitionIndex(partition.partition())
                            .setCommittedOffset(100L)
                            .setCommittedLeaderEpoch(1)
                            .setMetadata("metadata")
                    ).collect(Collectors.toList()))
             ).collect(Collectors.toList()));
        return buildOffsetFetchClientResponse(request, group, false);
    }

    private ClientResponse buildOffsetFetchClientResponseDisconnected(
        final NetworkClientDelegate.UnsentRequest request) {
        return buildOffsetFetchClientResponse(request, new OffsetFetchResponseData.OffsetFetchResponseGroup(), true);
    }

    private ClientResponse buildOffsetCommitClientResponse(final OffsetCommitResponse commitResponse) {
        short apiVersion = 1;
        return new ClientResponse(
            new RequestHeader(ApiKeys.OFFSET_COMMIT, apiVersion, "", 1),
            null,
            "-1",
            time.milliseconds(),
            time.milliseconds(),
            false,
            null,
            null,
            commitResponse
        );
    }

    private ClientResponse mockOffsetCommitResponseWithTopicId(Uuid topicId,
                                                              int partition,
                                                              short apiKeyVersion,
                                                              Errors error) {
        return mockOffsetCommitResponse("", topicId, partition, apiKeyVersion, time.milliseconds(), time.milliseconds(), error);
    }

    private ClientResponse mockOffsetCommitResponse(String topic,
                                                   int partition,
                                                   short apiKeyVersion,
                                                   Errors error) {
        return mockOffsetCommitResponse(topic, Uuid.ZERO_UUID, partition, apiKeyVersion, time.milliseconds(), time.milliseconds(), error);