Source:
<code>public void spoutMustIgnoreFailsForTuplesItIsNotAssignedAfterRebalance() throws Exception { ArgumentCaptor<ConsumerRebalanceListener> rebalanceListenerCapture = ArgumentCaptor.forClass(ConsumerRebalanceListener.class); Subscription subscriptionMock = mock(Subscription.class); doNothing() .when(subscriptionMock) .subscribe(any(KafkaConsumer.class), rebalanceListenerCapture.capture(), any(TopologyContext.class)); KafkaSpoutRetryService retryServiceMock = mock(KafkaSpoutRetryService.class); KafkaSpout<String, String> spout = new KafkaSpout<>(createKafkaSpoutConfigBuilder(subscriptionMock, -1) .setOffsetCommitPeriodMs(10) .setRetry(retryServiceMock) .build(), consumerFactoryMock); String topic = SingleTopicKafkaSpoutConfiguration.TOPIC; TopicPartition partitionThatWillBeRevoked = new TopicPartition(topic, 1); TopicPartition assignedPartition = new TopicPartition(topic, 2); when(retryServiceMock.getMessageId(Mockito.any(ConsumerRecord.class), contextMock)) .thenReturn(new KafkaSpoutMessageId(partitionThatWillBeRevoked, 0, contextMock)) .thenReturn(new KafkaSpoutMessageId(assignedPartition, 0, contextMock)); List<KafkaSpoutMessageId> emittedMessageIds = emitOneMessagePerPartitionThenRevokeOnePartition( spout, partitionThatWillBeRevoked, assignedPartition, rebalanceListenerCapture); <START> verify(retryServiceMock, times(2)).getMessageId(Mockito.any(ConsumerRecord.class), contextMock); <END> spout.fail(emittedMessageIds.get(0)); spout.fail(emittedMessageIds.get(1)); verify(retryServiceMock, never()).schedule(emittedMessageIds.get(0)); verify(retryServiceMock).schedule(emittedMessageIds.get(1)); }</code><technical_language>need put eq contextmock get error. stubbing verifying methods Mockito, matchers arguments need a matcher</technical_language>

Target:
public void spoutMustIgnoreFailsForTuplesItIsNotAssignedAfterRebalance() throws Exception { ArgumentCaptor<ConsumerRebalanceListener> rebalanceListenerCapture = ArgumentCaptor.forClass(ConsumerRebalanceListener.class); Subscription subscriptionMock = mock(Subscription.class); doNothing() .when(subscriptionMock) .subscribe(any(KafkaConsumer.class), rebalanceListenerCapture.capture(), any(TopologyContext.class)); KafkaSpoutRetryService retryServiceMock = mock(KafkaSpoutRetryService.class); KafkaSpout<String, String> spout = new KafkaSpout<>(createKafkaSpoutConfigBuilder(subscriptionMock, -1) .setOffsetCommitPeriodMs(10) .setRetry(retryServiceMock) .build(), consumerFactoryMock); String topic = SingleTopicKafkaSpoutConfiguration.TOPIC; TopicPartition partitionThatWillBeRevoked = new TopicPartition(topic, 1); TopicPartition assignedPartition = new TopicPartition(topic, 2); when(retryServiceMock.getMessageId(Mockito.any(ConsumerRecord.class))) .thenReturn(new KafkaSpoutMessageId(partitionThatWillBeRevoked, 0)) .thenReturn(new KafkaSpoutMessageId(assignedPartition, 0)); List<KafkaSpoutMessageId> emittedMessageIds = emitOneMessagePerPartitionThenRevokeOnePartition( spout, partitionThatWillBeRevoked, assignedPartition, rebalanceListenerCapture); verify(retryServiceMock, times(2)).getMessageId(Mockito.any(ConsumerRecord.class)); spout.fail(emittedMessageIds.get(0)); spout.fail(emittedMessageIds.get(1)); verify(retryServiceMock, never()).schedule(emittedMessageIds.get(0)); verify(retryServiceMock).schedule(emittedMessageIds.get(1)); }