snuyanzin commented on code in PR #19928:
URL: https://github.com/apache/flink/pull/19928#discussion_r967316371


##########
flink-connectors/flink-connector-gcp-pubsub/src/test/java/org/apache/flink/streaming/connectors/gcp/pubsub/PubSubSourceTest.java:
##########
@@ -66,13 +65,17 @@ public class PubSubSourceTest {
 
     private PubSubSource<String> pubSubSource;
 
-    @Before
-    public void setup() throws Exception {
-        
when(pubSubSubscriberFactory.getSubscriber(eq(credentials))).thenReturn(pubsubSubscriber);
-        
when(streamingRuntimeContext.isCheckpointingEnabled()).thenReturn(true);
-        when(streamingRuntimeContext.getMetricGroup()).thenReturn(metricGroup);
-        when(metricGroup.addGroup(any(String.class))).thenReturn(metricGroup);
-        
when(acknowledgeOnCheckpointFactory.create(any())).thenReturn(acknowledgeOnCheckpoint);
+    @BeforeEach
+    void setup() throws Exception {
+        lenient()
+                .when(pubSubSubscriberFactory.getSubscriber(eq(credentials)))
+                .thenReturn(pubsubSubscriber);
+        
lenient().when(streamingRuntimeContext.isCheckpointingEnabled()).thenReturn(true);
+        
lenient().when(streamingRuntimeContext.getMetricGroup()).thenReturn(metricGroup);
+        
lenient().when(metricGroup.addGroup(any(String.class))).thenReturn(metricGroup);
+        lenient()
+                .when(acknowledgeOnCheckpointFactory.create(any()))
+                .thenReturn(acknowledgeOnCheckpoint);

Review Comment:
   After some research it seems that in case of JUnit5 Mockito works a bit 
different in compare how it works for JUnit4.
   The reason is that for JUnit5 there 
`org.mockito.junit.jupiter.MockitoExtension` [1] is used
   and for JUnit4 `org.mockito.junit.MockitoJUnitRunner` [2].
   
   The way how validation of used stubs is working is also different.
   E.g. in case of JUnit5 it is handled at 
`org.mockito.MockitoSession#finishMocking(java.lang.Throwable)` [3] which is 
invoked after each test.
   At the same time in JUnit4 it is processed inside 
`org.mockito.internal.runners.StrictRunner#run` [4] and logic there is the next 
one: 
   first it works only for cases when all tests from class/testsuite are running
   second it does validation of used/not used stubs after all tests finished.
   
   
   Seems it is the reason why after movement to JUnit5 it starts failing
   [1] 
https://github.com/mockito/mockito/blob/v3.4.6/subprojects/junit-jupiter/src/main/java/org/mockito/junit/jupiter/MockitoExtension.java
   [2] 
https://github.com/mockito/mockito/blob/v3.4.6/src/main/java/org/mockito/junit/MockitoJUnitRunner.java
   [3] 
https://github.com/mockito/mockito/blob/v3.4.6/subprojects/junit-jupiter/src/main/java/org/mockito/junit/jupiter/MockitoExtension.java#L184-L186
   [4] 
https://github.com/mockito/mockito/blob/v3.4.6/src/main/java/org/mockito/internal/runners/StrictRunner.java#L45-L53



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