Source:
private static void verifyReceivedAllRecords(final Map<TopicPartition, List<ConsumerRecord<byte[], byte[]>>> expectedRecords, final Map<TopicPartition, List<ConsumerRecord<byte[], byte[]>>> receivedRecords) { if (expectedRecords.size() != receivedRecords.size()) { throw new RuntimeException("Result verification failed. Received " + receivedRecords.size() + " records but expected " + expectedRecords.size()); } final StringDeserializer stringDeserializer = new StringDeserializer(); final IntegerDeserializer integerDeserializer = new IntegerDeserializer(); for (final Map.Entry<TopicPartition, List<ConsumerRecord<byte[], byte[]>>> partitionRecords : receivedRecords.entrySet()) { final TopicPartition inputTopicPartition = new TopicPartition("data", partitionRecords.getKey().partition()); final Iterator<ConsumerRecord<byte[], byte[]>> expectedRecord = expectedRecords.get(inputTopicPartition).iterator(); for (final ConsumerRecord<byte[], byte[]> receivedRecord : partitionRecords.getValue().subList(0, partitionRecords.getValue().size() - 1)) { final ConsumerRecord<byte[], byte[]> expected = expectedRecord.next(); final String receivedKey = stringDeserializer.deserialize(receivedRecord.topic(), receivedRecord.key()); final int receivedValue = integerDeserializer.deserialize(receivedRecord.topic(), receivedRecord.value()); final String expectedKey = stringDeserializer.deserialize(expected.topic(), expected.key()); final int expectedValue = integerDeserializer.deserialize(expected.topic(), expected.value()); if (!receivedKey.equals(expectedKey) || receivedValue != expectedValue) { throw new RuntimeException("Result verification failed for " + receivedRecord + " expected <" + expectedKey + "," + expectedValue + "> but was <" + receivedKey + "," + receivedValue + ">"); } } } }

Target:
private static void verifyReceivedAllRecords(final Map<TopicPartition, List<ConsumerRecord<byte[], byte[]>>> expectedRecords, final Map<TopicPartition, List<ConsumerRecord<byte[], byte[]>>> receivedRecords) { if (expectedRecords.size() != receivedRecords.size()) { throw new RuntimeException("Result verification failed. Received " + receivedRecords.size() + " records but expected " + expectedRecords.size()); } final StringDeserializer stringDeserializer = new StringDeserializer(); final IntegerDeserializer integerDeserializer = new IntegerDeserializer(); for (final Map.Entry<TopicPartition, List<ConsumerRecord<byte[], byte[]>>> partitionRecords : receivedRecords.entrySet()) { final TopicPartition inputTopicPartition = new TopicPartition("data", partitionRecords.getKey().partition()); final Iterator<ConsumerRecord<byte[], byte[]>> expectedRecord = expectedRecords.get(inputTopicPartition).iterator(); for (final ConsumerRecord<byte[], byte[]> receivedRecord : partitionRecords.getValue()) { final ConsumerRecord<byte[], byte[]> expected = expectedRecord.next(); final String receivedKey = stringDeserializer.deserialize(receivedRecord.topic(), receivedRecord.key()); final int receivedValue = integerDeserializer.deserialize(receivedRecord.topic(), receivedRecord.value()); final String expectedKey = stringDeserializer.deserialize(expected.topic(), expected.key()); final int expectedValue = integerDeserializer.deserialize(expected.topic(), expected.value()); if (!receivedKey.equals(expectedKey) || receivedValue != expectedValue) { throw new RuntimeException("Result verification failed for " + receivedRecord + " expected <" + expectedKey + "," + expectedValue + "> but was <" + receivedKey + "," + receivedValue + ">"); } } } }