private LeaderAndIsrResponse createLeaderAndIsrResponse(short version) {
        if (version < 5) {
            List<LeaderAndIsrResponseData.LeaderAndIsrPartitionError> partitions = new ArrayList<>();
            partitions.add(new LeaderAndIsrResponseData.LeaderAndIsrPartitionError()
                    .setTopicName("test")
                    .setPartitionIndex(0)
                    .setErrorCode(Errors.NONE.code()));
            return new LeaderAndIsrResponse(new LeaderAndIsrResponseData()
                    .setErrorCode(Errors.NONE.code())
                    .setPartitionErrors(partitions), version);
        } else {
            List<LeaderAndIsrResponseData.LeaderAndIsrPartitionError> partition = singletonList(
                    new LeaderAndIsrResponseData.LeaderAndIsrPartitionError()
                    .setPartitionIndex(0)
                    .setErrorCode(Errors.NONE.code()));
            LeaderAndIsrTopicErrorCollection topics = new LeaderAndIsrTopicErrorCollection();
            topics.add(new LeaderAndIsrResponseData.LeaderAndIsrTopicError()
                    .setTopicId(Uuid.randomUuid())
                    .setPartitionErrors(partition));
            return new LeaderAndIsrResponse(new LeaderAndIsrResponseData()
                    .setTopics(topics), version);
        }
    }
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