private FetchResponse createFetchResponse(short version) {
        FetchResponseData data = new FetchResponseData();
        if (version > 0) {
            data.setThrottleTimeMs(345);
        }
        if (version > 6) {
            data.setErrorCode(Errors.NONE.code())
                    .setSessionId(123);
        }
        MemoryRecords records = MemoryRecords.withRecords(Compression.NONE, new SimpleRecord("blah".getBytes()));
        FetchResponseData.PartitionData partition = new FetchResponseData.PartitionData()
                .setPartitionIndex(0)
                .setErrorCode(Errors.NONE.code())
                .setHighWatermark(123L)
                .setRecords(records);
        if (version > 3) {
            partition.setLastStableOffset(234L);
        }
        if (version > 4) {
            partition.setLogStartOffset(456L);
        }
        if (version > 10) {
            partition.setPreferredReadReplica(1);
        }
        if (version > 11) {
            partition.setDivergingEpoch(new FetchResponseData.EpochEndOffset().setEndOffset(1L).setEpoch(2))
                    .setSnapshotId(new FetchResponseData.SnapshotId().setEndOffset(1L).setEndOffset(2))
                    .setCurrentLeader(new FetchResponseData.LeaderIdAndEpoch().setLeaderEpoch(1).setLeaderId(2));
        }
        FetchResponseData.FetchableTopicResponse response = new FetchResponseData.FetchableTopicResponse()
                .setTopic("topic")
                .setPartitions(singletonList(partition));
        if (version > 12) {
            response.setTopicId(Uuid.randomUuid());
        }
        data.setResponses(singletonList(response));
        return new FetchResponse(data);
    }
Check that all error codes in the response get included in {@link AbstractResponse#errorCounts()}.
clients/src/test/java/org/apache/kafka/common/requests/RequestResponseTest.java