cadonna commented on code in PR #12492:
URL: https://github.com/apache/kafka/pull/12492#discussion_r946894212


##########
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:
   I did not write the original test, but from the test it seems that verifying 
the admin client is important since only that mock is verified. I can imagine 
the original author wanted to make sure that the StreamsException is caused by 
the call to the admin client. I think in this case it might not be needed, 
since AFAIK we would run into a NPE if `adminClient.listOffsets` is not called.



-- 
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]

Reply via email to