You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2021/06/14 08:06:36 UTC

[GitHub] [kafka] chia7712 commented on a change in pull request #10852: MINOR: Replace easymock with mockito in log4j-appender

chia7712 commented on a change in pull request #10852:
URL: https://github.com/apache/kafka/pull/10852#discussion_r650510053



##########
File path: log4j-appender/src/test/java/org/apache/kafka/log4jappender/KafkaLog4jAppenderTest.java
##########
@@ -159,17 +161,18 @@ public void testRealProducerConfigWithSyncSendAndNotIgnoringExceptionsShouldThro
     }
 
     private void replaceProducerWithMocked(MockKafkaLog4jAppender mockKafkaLog4jAppender, boolean success) {
-        MockProducer<byte[], byte[]> producer = EasyMock.niceMock(MockProducer.class);
-        Future<RecordMetadata> futureMock = EasyMock.niceMock(Future.class);
+        @SuppressWarnings("unchecked")
+        MockProducer<byte[], byte[]> producer = mock(MockProducer.class);
+        @SuppressWarnings("unchecked")
+        Future<RecordMetadata> futureMock = mock(Future.class);
         try {
             if (!success)
-                EasyMock.expect(futureMock.get())
-                    .andThrow(new ExecutionException("simulated timeout", new TimeoutException()));
+                when(futureMock.get())
+                        .thenThrow(new ExecutionException("simulated timeout", new TimeoutException()));
         } catch (InterruptedException | ExecutionException e) {

Review comment:
       This catch is a bit weird to me. Could you create a true `CompletableFuture` carrying the exception `new TimeoutException()` instead of mocking object? For example:
   
   ```java
           CompletableFuture<RecordMetadata> future = new CompletableFuture<>();
           if (success) future.complete(new RecordMetadata(new TopicPartition("tp", 0), 0, 0, 0, 0, 0));
           else future.completeExceptionally(new TimeoutException());
   ```




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org