clolov commented on code in PR #12492:
URL: https://github.com/apache/kafka/pull/12492#discussion_r946937305
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/ClientUtilsTest.java:
##########
@@ -108,75 +110,73 @@ public class ClientUtilsTest {
@Test
public void
fetchCommittedOffsetsShouldRethrowKafkaExceptionAsStreamsException() {
- final Consumer<byte[], byte[]> consumer =
EasyMock.createMock(Consumer.class);
- expect(consumer.committed(PARTITIONS)).andThrow(new KafkaException());
- replay(consumer);
+ @SuppressWarnings("unchecked")
+ final Consumer<byte[], byte[]> consumer = mock(Consumer.class);
+ when(consumer.committed(PARTITIONS)).thenThrow(new KafkaException());
assertThrows(StreamsException.class, () ->
fetchCommittedOffsets(PARTITIONS, consumer));
}
@Test
public void fetchCommittedOffsetsShouldRethrowTimeoutException() {
- final Consumer<byte[], byte[]> consumer =
EasyMock.createMock(Consumer.class);
- expect(consumer.committed(PARTITIONS)).andThrow(new
TimeoutException());
- replay(consumer);
+ @SuppressWarnings("unchecked")
+ final Consumer<byte[], byte[]> consumer = mock(Consumer.class);
+ when(consumer.committed(PARTITIONS)).thenThrow(new TimeoutException());
assertThrows(TimeoutException.class, () ->
fetchCommittedOffsets(PARTITIONS, consumer));
}
@Test
public void
fetchCommittedOffsetsShouldReturnEmptyMapIfPartitionsAreEmpty() {
- final Consumer<byte[], byte[]> consumer =
EasyMock.createMock(Consumer.class);
+ @SuppressWarnings("unchecked")
+ final Consumer<byte[], byte[]> consumer = mock(Consumer.class);
assertTrue(fetchCommittedOffsets(emptySet(), consumer).isEmpty());
}
@Test
public void fetchEndOffsetsShouldReturnEmptyMapIfPartitionsAreEmpty() {
- final Admin adminClient = EasyMock.createMock(AdminClient.class);
+ final Admin adminClient = mock(AdminClient.class);
assertTrue(fetchEndOffsets(emptySet(), adminClient).isEmpty());
}
@Test
public void
fetchEndOffsetsShouldRethrowRuntimeExceptionAsStreamsException() throws
Exception {
- final Admin adminClient = EasyMock.createMock(AdminClient.class);
- final ListOffsetsResult result =
EasyMock.createNiceMock(ListOffsetsResult.class);
- final KafkaFuture<Map<TopicPartition, ListOffsetsResultInfo>>
allFuture = EasyMock.createMock(KafkaFuture.class);
+ final Admin adminClient = mock(AdminClient.class);
+ final ListOffsetsResult result = mock(ListOffsetsResult.class);
+ @SuppressWarnings("unchecked")
+ final KafkaFuture<Map<TopicPartition, ListOffsetsResultInfo>>
allFuture = mock(KafkaFuture.class);
-
EasyMock.expect(adminClient.listOffsets(EasyMock.anyObject())).andStubReturn(result);
- EasyMock.expect(result.all()).andStubReturn(allFuture);
- EasyMock.expect(allFuture.get()).andThrow(new RuntimeException());
- replay(adminClient, result, allFuture);
+ when(adminClient.listOffsets(any())).thenReturn(result);
+ when(result.all()).thenReturn(allFuture);
+ when(allFuture.get()).thenThrow(new RuntimeException());
assertThrows(StreamsException.class, () -> fetchEndOffsets(PARTITIONS,
adminClient));
- verify(adminClient);
Review Comment:
Okay, I will leave the verification on the admin client out for all three
tests (this one and the other two below with a similar comment). We are using
strict mocks which would complain that we have unnecessary stubbings if we
start going down a different codepath.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]