Source:
<code>public void readWriteOffsets() { KafkaConsumer<String, ChangeEvent> consumer = <START> mock(KafkaConsumer.class); <END> Uris uris = mock(Uris.class); when(uris.isEntityNamespace(0)).thenReturn(true); when(uris.getHost()).thenReturn("acme.test"); URIBuilder b = new URIBuilder(); b.setScheme("https"); b.setHost("acme.test"); when(uris.builder()).thenReturn(b); Instant startTime = Instant.ofEpochMilli(BEGIN_DATE); Collection<String> topics = ImmutableList.of("topictest", "othertopic"); when(consumer.partitionsFor(any())).thenAnswer(inv -> { String pName = inv.getArgumentAt(0, String.class); PartitionInfo pi = mock(PartitionInfo.class); when(pi.partition()).thenReturn(0); when(pi.topic()).thenReturn(pName); return ImmutableList.of(pi); }); RdfRepositoryForTesting rdfRepository = new RdfRepositoryForTesting("wdq"); KafkaPoller poller = new KafkaPoller(consumer, uris, startTime, 5, topics, rdfRepository); poller.setUpTopicPartitions(); when(consumer.position(any())).thenReturn(1L, 2L, 3L, 4L); poller.writeOffsetsToStorage(); Map<TopicPartition, OffsetAndTimestamp> offsets = poller.getOffsetsFromStorage(); assertThat(offsets.get(new TopicPartition("topictest", 0)).offset(), is(1L)); assertThat(offsets.get(new TopicPartition("othertopic", 0)).offset(), is(2L)); poller.writeOffsetsToStorage(); offsets = poller.getOffsetsFromStorage(); assertThat(offsets.get(new TopicPartition("topictest", 0)).offset(), is(3L)); assertThat(offsets.get(new TopicPartition("othertopic", 0)).offset(), is(4L)); }</code><technical_language>this is KafkaPollerIntegrationTest, strange mock KafkaConsumer. unit tests for kafka RdfRepository side of this logic integration test exercises both. this integration tests smell coupling kafka blazegraph side of test independently. This a design smell fixed. Honestly, I read code closely enough, speculating</technical_language>

Target:
public void readWriteOffsets() throws Exception { KafkaConsumer<String, ChangeEvent> consumer = mock(KafkaConsumer.class); Uris uris = new Uris("https", "acme.test", 443, new long[]{0}); Instant startTime = Instant.ofEpochMilli(BEGIN_DATE); Collection<String> topics = ImmutableList.of("topictest", "othertopic"); when(consumer.partitionsFor(any())).thenAnswer(inv -> { String pName = inv.getArgumentAt(0, String.class); PartitionInfo pi = new PartitionInfo(pName, 0, null, null, null); return ImmutableList.of(pi); }); try (RdfRepositoryForTesting rdfRepository = new RdfRepositoryForTesting("wdq")) { try { rdfRepository.before(); KafkaPoller poller = new KafkaPoller(consumer, uris, startTime, 5, topics, rdfRepository); poller.setUpTopicPartitions(); when(consumer.position(any())).thenReturn(1L, 2L, 3L, 4L); poller.writeOffsetsToStorage(); Map<TopicPartition, OffsetAndTimestamp> offsets = poller.fetchOffsetsFromStorage(); assertThat(offsets.get(new TopicPartition("topictest", 0)).offset(), is(1L)); assertThat(offsets.get(new TopicPartition("othertopic", 0)).offset(), is(2L)); poller.writeOffsetsToStorage(); offsets = poller.fetchOffsetsFromStorage(); assertThat(offsets.get(new TopicPartition("topictest", 0)).offset(), is(3L)); assertThat(offsets.get(new TopicPartition("othertopic", 0)).offset(), is(4L)); } finally { rdfRepository.after(); } } }