Source:
<code>private static <K, V, T> List<T> waitUntilFinalKeyValueRecordsReceived(final Properties consumerConfig, final String topic, final List<T> expectedRecords, final long waitTime, final boolean withTimestamp) throws InterruptedException { final List<T> accumData = new ArrayList<>(); try (final Consumer<K, V> consumer = createConsumer(consumerConfig)) { final TestCondition valuesRead = () -> { final List<T> readData; if (withTimestamp) { readData = (List<T>) readKeyValuesWithTimestamp(topic, consumer, waitTime, expectedRecords.size()); } else { readData = (List<T>) readKeyValues(topic, consumer, waitTime, expectedRecords.size()); } accumData.addAll(readData); final List<T> accumulatedActual = accumData.stream().filter(expectedRecords::contains).collect(Collectors.toList()); final Map<K, List<T>> finalAccumData = new HashMap<>(); for (final T kv : accumulatedActual) { finalAccumData.computeIfAbsent( (K) (withTimestamp ? ((KeyValueTimestamp) kv).key() : ((KeyValue) kv).key), key -> new ArrayList<>()).add(kv); } final Map<K, List<T>> finalExpected = new HashMap<>(); for (final T kv : expectedRecords) { finalExpected.computeIfAbsent( (K) (withTimestamp ? ((KeyValueTimestamp) kv).key() : ((KeyValue) kv).key), key -> new ArrayList<>()).add(kv); } System.err.println(finalAccumData); <START> System.err.println(finalExpected); <END> return finalAccumData.equals(finalExpected); }; final String conditionDetails = "Did not receive all " + expectedRecords + " records from topic " + topic; TestUtils.waitForCondition(valuesRead, waitTime, conditionDetails); } return accumData; }</code><technical_language>checking... this for debugging, do want print stdout tests</technical_language>

Target:
private static <K, V, T> List<T> waitUntilFinalKeyValueRecordsReceived(final Properties consumerConfig, final String topic, final List<T> expectedRecords, final long waitTime, final boolean withTimestamp) throws InterruptedException { final List<T> accumData = new ArrayList<>(); try (final Consumer<K, V> consumer = createConsumer(consumerConfig)) { final TestCondition valuesRead = () -> { final List<T> readData; if (withTimestamp) { readData = (List<T>) readKeyValuesWithTimestamp(topic, consumer, waitTime, expectedRecords.size()); } else { readData = (List<T>) readKeyValues(topic, consumer, waitTime, expectedRecords.size()); } accumData.addAll(readData); final List<T> accumulatedActual = accumData.stream().filter(expectedRecords::contains).collect(Collectors.toList()); final Map<K, List<T>> finalAccumData = new HashMap<>(); for (final T kv : accumulatedActual) { finalAccumData.computeIfAbsent( (K) (withTimestamp ? ((KeyValueTimestamp) kv).key() : ((KeyValue) kv).key), key -> new ArrayList<>()).add(kv); } final Map<K, List<T>> finalExpected = new HashMap<>(); for (final T kv : expectedRecords) { finalExpected.computeIfAbsent( (K) (withTimestamp ? ((KeyValueTimestamp) kv).key() : ((KeyValue) kv).key), key -> new ArrayList<>()).add(kv); } return finalAccumData.equals(finalExpected); }; final String conditionDetails = "Did not receive all " + expectedRecords + " records from topic " + topic; TestUtils.waitForCondition(valuesRead, waitTime, conditionDetails); } return accumData; }