@Override
    public synchronized ConsumerRecords<K, V> poll(Duration timeout) {
        ensureNotClosed();

        final Map<TopicPartition, List<ConsumerRecord<K, V>>> results = new HashMap<>();
        for (Map.Entry<TopicPartition, List<ConsumerRecord<K, V>>> entry : records.entrySet()) {
            final List<ConsumerRecord<K, V>> recs = entry.getValue();
            for (final ConsumerRecord<K, V> rec : recs) {
                results.computeIfAbsent(entry.getKey(), partition -> new ArrayList<>()).add(rec);
            }
        }

        records.clear();
        return new ConsumerRecords<>(results);
    }
A mock of the {@link ShareConsumer} interface you can use for testing code that uses Kafka. This class is <i> not
thread-safe </i>.
clients/src/main/java/org/apache/kafka/clients/consumer/MockShareConsumer.java