wx930910 commented on a change in pull request #11529:
URL: https://github.com/apache/druid/pull/11529#discussion_r682233883



##########
File path: 
core/src/test/java/org/apache/druid/data/input/HandlingInputRowIteratorTest.java
##########
@@ -81,58 +87,81 @@ public void throwsExceptionWhenYieldingNext()
 
   public static class PresentRowTest
   {
+    // Create variables for tracking behaviors of mock object
+
+    boolean unsuccessfulHandlerSuccessful;
+
+    // Create variables for tracking behaviors of mock object
+
+    boolean successfulHandlerSuccessful;
+
     private static final InputRow INPUT_ROW1 = EasyMock.mock(InputRow.class);
     private static final InputRow INPUT_ROW2 = EasyMock.mock(InputRow.class);
     private static final List<InputRow> INPUT_ROWS = Arrays.asList(INPUT_ROW1, 
INPUT_ROW2);
 
-    private TestInputRowHandler successfulHandler;
-    private TestInputRowHandler unsuccessfulHandler;
+    private InputRowHandler successfulHandler;
+    private InputRowHandler unsuccessfulHandler;
 
     @Before
     public void setup()
     {
-      successfulHandler = new TestInputRowHandler(true);
-      unsuccessfulHandler = new TestInputRowHandler(false);
+      // Construct mock object
+      successfulHandler = mock(HandlingInputRowIterator.InputRowHandler.class);
+      // Constructing variables that used for tracking behavior of the mocking
+      // object.
+      successfulHandlerSuccessful = true;
+      // Method Stubs
+      
when(successfulHandler.handle(any(InputRow.class))).thenAnswer((stubInvo) -> {
+        return successfulHandlerSuccessful;
+      });
+      // Construct mock object
+      unsuccessfulHandler = 
mock(HandlingInputRowIterator.InputRowHandler.class);
+      // Constructing variables that used for tracking behavior of the mocking
+      // object.
+      unsuccessfulHandlerSuccessful = false;
+      // Method Stubs
+      
when(unsuccessfulHandler.handle(any(InputRow.class))).thenAnswer((stubInvo) -> {
+        return unsuccessfulHandlerSuccessful;
+      });
     }
 
     @Test
     public void hasNext()
     {
       HandlingInputRowIterator target = 
createInputRowIterator(unsuccessfulHandler, unsuccessfulHandler);
       Assert.assertTrue(target.hasNext());
-      Assert.assertFalse(unsuccessfulHandler.invoked);
+      Mockito.verify(unsuccessfulHandler, 
Mockito.never()).handle(any(InputRow.class));
     }
 
     @Test
     public void yieldsNextIfUnhandled()
     {
       HandlingInputRowIterator target = 
createInputRowIterator(unsuccessfulHandler, unsuccessfulHandler);
       Assert.assertEquals(INPUT_ROW1, target.next());
-      Assert.assertTrue(unsuccessfulHandler.invoked);
+      Mockito.verify(unsuccessfulHandler, 
Mockito.atLeastOnce()).handle(any(InputRow.class));

Review comment:
       I agree with you, by changing `atLeastOnce()` to `times(int)` can make 
test more powerful. I use `atLeastOnce()` instead of `times(1)` here is because 
the original test is using boolean to verify the method behavior. Boolean can 
only be used to check whether the method is been executed or not instead of 
tracking the exact execution times. Also, in 
[yieldsNextIfUnhandled()](https://github.com/apache/druid/pull/11529/files/8dd713e6e547381ae24928f672d1561b6a670335#diff-c861ad661bc346cc59e01172af11c513b2092026fb1892fcf04d102a1394ef47R139),
 `handle()` executed twice since we passed two `unsuccessfulHandler` to 
`HandlingInputRowIterator`.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to