@Test
    public void testStructBuild() {
        for (short version : ApiKeys.OFFSET_FETCH.allVersions()) {
            if (version < 8) {
                partitionDataMap.put(new TopicPartition(topicTwo, partitionTwo), new PartitionData(
                    offset,
                    leaderEpochTwo,
                    metadata,
                    Errors.GROUP_AUTHORIZATION_FAILED
                ));

                OffsetFetchResponse latestResponse = new OffsetFetchResponse(throttleTimeMs, Errors.NONE, partitionDataMap);
                OffsetFetchResponseData data = new OffsetFetchResponseData(
                    new ByteBufferAccessor(latestResponse.serialize(version)), version);

                OffsetFetchResponse oldResponse = new OffsetFetchResponse(data, version);

                if (version <= 1) {
                    assertEquals(Errors.NONE.code(), data.errorCode());

                    // Partition level error populated in older versions.
                    assertEquals(Errors.GROUP_AUTHORIZATION_FAILED, oldResponse.error());
                    assertEquals(Utils.mkMap(Utils.mkEntry(Errors.GROUP_AUTHORIZATION_FAILED, 2),
                        Utils.mkEntry(Errors.TOPIC_AUTHORIZATION_FAILED, 1)),
                        oldResponse.errorCounts());
                } else {
                    assertEquals(Errors.NONE.code(), data.errorCode());

                    assertEquals(Errors.NONE, oldResponse.error());
                    assertEquals(Utils.mkMap(
                        Utils.mkEntry(Errors.NONE, 1),
                        Utils.mkEntry(Errors.GROUP_AUTHORIZATION_FAILED, 1),
                        Utils.mkEntry(Errors.TOPIC_AUTHORIZATION_FAILED, 1)),
                        oldResponse.errorCounts());
                }

                if (version <= 2) {
                    assertEquals(DEFAULT_THROTTLE_TIME, oldResponse.throttleTimeMs());
                } else {
                    assertEquals(throttleTimeMs, oldResponse.throttleTimeMs());
                }

                Map<TopicPartition, PartitionData> expectedDataMap = new HashMap<>();
                for (Map.Entry<TopicPartition, PartitionData> entry : partitionDataMap.entrySet()) {
                    PartitionData partitionData = entry.getValue();
                    expectedDataMap.put(entry.getKey(), new PartitionData(
                        partitionData.offset,
                        version <= 4 ? Optional.empty() : partitionData.leaderEpoch,
                        partitionData.metadata,
                        partitionData.error
                    ));
                }

                Map<TopicPartition, PartitionData> responseData = oldResponse.responseDataV0ToV7();
                assertEquals(expectedDataMap, responseData);

                responseData.forEach((tp, rdata) -> assertTrue(rdata.hasError()));
            } else {
                partitionDataMap.put(new TopicPartition(topicTwo, partitionTwo), new PartitionData(
                    offset,
                    leaderEpochTwo,
                    metadata,
                    Errors.GROUP_AUTHORIZATION_FAILED));
                OffsetFetchResponse latestResponse = new OffsetFetchResponse(
                    throttleTimeMs,
                    Collections.singletonMap(groupOne, Errors.NONE),
                    Collections.singletonMap(groupOne, partitionDataMap));
                OffsetFetchResponseData data = new OffsetFetchResponseData(
                    new ByteBufferAccessor(latestResponse.serialize(version)), version);
                OffsetFetchResponse oldResponse = new OffsetFetchResponse(data, version);
                assertEquals(Errors.NONE.code(), data.groups().get(0).errorCode());

                assertEquals(Errors.NONE, oldResponse.groupLevelError(groupOne));
                assertEquals(Utils.mkMap(
                    Utils.mkEntry(Errors.NONE, 1),
                    Utils.mkEntry(Errors.GROUP_AUTHORIZATION_FAILED, 1),
                    Utils.mkEntry(Errors.TOPIC_AUTHORIZATION_FAILED, 1)),
                    oldResponse.errorCounts());
                assertEquals(throttleTimeMs, oldResponse.throttleTimeMs());

                Map<TopicPartition, PartitionData> expectedDataMap = new HashMap<>();
                for (Map.Entry<TopicPartition, PartitionData> entry : partitionDataMap.entrySet()) {
                    PartitionData partitionData = entry.getValue();
                    expectedDataMap.put(entry.getKey(), new PartitionData(
                        partitionData.offset,
                        partitionData.leaderEpoch,
                        partitionData.metadata,
                        partitionData.error
                    ));
                }

                Map<TopicPartition, PartitionData> responseData = oldResponse.partitionDataMap(groupOne);
                assertEquals(expectedDataMap, responseData);

                responseData.forEach((tp, rdata) -> assertTrue(rdata.hasError()));
            }
        }
    }
Test behavior changes over the versions. Refer to resources.common.messages.OffsetFetchResponse.json
clients/src/test/java/org/apache/kafka/common/requests/OffsetFetchResponseTest.java