divijvaidya commented on code in PR #12735:
URL: https://github.com/apache/kafka/pull/12735#discussion_r1009324268


##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/ErrorHandlingTaskTest.java:
##########
@@ -374,30 +350,40 @@ public void testErrorHandlingInSourceTasks() throws 
Exception {
         Struct struct2 = new Struct(valSchema).put("val", 6789);
         SourceRecord record2 = new SourceRecord(emptyMap(), emptyMap(), TOPIC, 
PARTITION1, valSchema, struct2);
 
-        EasyMock.expect(workerSourceTask.isStopping()).andReturn(false);
-        EasyMock.expect(workerSourceTask.isStopping()).andReturn(false);
-        EasyMock.expect(workerSourceTask.isStopping()).andReturn(true);
+        when(workerSourceTask.isStopping())
+                .thenReturn(false)
+                .thenReturn(false)
+                .thenReturn(true);
 
-        EasyMock.expect(workerSourceTask.commitOffsets()).andReturn(true);
+        doReturn(true).when(workerSourceTask).commitOffsets();
 
-        offsetStore.start();
-        EasyMock.expectLastCall();
-        sourceTask.initialize(EasyMock.anyObject());
-        EasyMock.expectLastCall();
-        sourceTask.start(EasyMock.anyObject());
-        EasyMock.expectLastCall();
+        when(sourceTask.poll())
+                .thenReturn(singletonList(record1))
+                .thenReturn(singletonList(record2));
 
-        EasyMock.expect(sourceTask.poll()).andReturn(singletonList(record1));
-        EasyMock.expect(sourceTask.poll()).andReturn(singletonList(record2));
         expectTopicCreation(TOPIC);

Review Comment:
   @C0urante please correct me if I am wrong but when we run Mockito with 
strict subs (`Strictness.STRICT_STUBS`), we do not need to verify that the 
stubs have been invoked. This is because Mockito will throw an "unused stub 
exception" if we define a stub but never ends up getting invoked. Hence, we 
don't need to call `verify`. 
   
   Reference: https://www.baeldung.com/mockito-unnecessary-stubbing-exception 
and from the `STRICT_STUBS` javadocs:
   ```
       /**
        * Ensures clean tests, reduces test code duplication, improves 
debuggability.
        * Offers best combination of flexibility and productivity.
        * Highly recommended.
        * Planned as default for Mockito v4.
        * Enable it via our JUnit support ({@link MockitoJUnit}) or {@link 
MockitoSession}.
        * <p>
        * Adds following behavior:
        *  <ul>
        *      <li>Improved productivity: the test fails early when code under 
test invokes
        *          stubbed method with different arguments (see {@link 
PotentialStubbingProblem}).</li>
        *      <li>Cleaner tests without unnecessary stubbings:
        *          the test fails when unused stubs are present (see {@link 
UnnecessaryStubbingException}).</li>
        *      <li>Cleaner, more DRY tests ("Don't Repeat Yourself"):
        *          If you use {@link 
org.mockito.Mockito#verifyNoMoreInteractions(Object...)}
        *          you no longer need to explicitly verify stubbed invocations.
        *          They are automatically verified for you.</li>
        *  </ul>
        *
        * For more information see {@link Strictness}.
        *
        * @since 2.3.0
        */
       STRICT_STUBS;
   ```



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