Mockito best practices

MSAL

Applies best practices for Mockito tests.

org.openrewrite.java.testing.mockito.MockitoBestPractices
mod run . --recipe=org.openrewrite.java.testing.mockito.MockitoBestPractices

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.

Recipe list

It runs these recipes, in this order.

  1. Upgrade to Mockito 5.x
  2. Remove annotation @org.mockito.junit.jupiter.MockitoSettings(strictness=org.mockito.quality.Strictness.WARN)
  3. Remove Mockito.times(0) and Mockito.times(1)
  4. Remove doNothing() for void methods on @Mock fields
  5. Remove eq() matchers from Mockito verify, when and given calls
  6. Wrap MockedConstruction in try-with-resources