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 2022/07/29 18:07:21 UTC

[GitHub] [kafka] dplavcic opened a new pull request, #12460: MINOR: Upgrade mockito test dependencies

dplavcic opened a new pull request, #12460:
URL: https://github.com/apache/kafka/pull/12460

   ## Changes
   - **mockito: 4.4.0 -> 4.6.1** (https://github.com/mockito/mockito/releases)
     - Regression? Strictness set in @MockitoSettings ignored after upgrade from 4.5.1 to 4.6.0 https://github.com/mockito/mockito/issues/2656
     - Fixes https://github.com/mockito/mockito/issues/2648 : Add support for customising strictness via @mock annotation and MockSettings https://github.com/mockito/mockito/pull/2650
   
   
   ## Why is this change needed?
   According to the [Mockito documentation](https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#when(T)) :
   > Although it is possible to verify a stubbed invocation, usually it's just redundant. Let's say you've stubbed foo.bar(). If your code cares what foo.bar() returns then something else breaks(often before even verify() gets executed). If your code doesn't care what get(0) returns then it should not be stubbed. 
   
   While working on the [Replace EasyMock and PowerMock with Mockito for StreamsMetricsImplTest ](https://issues.apache.org/jira/browse/KAFKA-12947) I noticed that described behavior wasn't applied when you create a new `mock` like this.
   
   ```java
           final Metrics metrics = mock(Metrics.class);
           when(metrics.metric(metricName)).thenReturn(null);
   
           ... invoke SUT
   
           verify(metrics).metric(metricName); // this should be redundant (according to docs)
   
   ```
   
   After further investigation I figured out that described behaviour wasn't implemented until`v4.6.1`.
   
   With this change we are now able to mock objects like this:
   
   ```java
      Foo explicitStrictMock = mock(Foo.class, withSettings().strictness(Strictness.STRICT_STUBS));
   ```
   - link to docs: [MockSettings.html#strictness](https://javadoc.io/static/org.mockito/mockito-core/4.6.1/org/mockito/MockSettings.html#strictness(org.mockito.quality.Strictness))
   
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


-- 
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: jira-unsubscribe@kafka.apache.org

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