Mockito
Composite Recipes
Recipes that include further recipes, often including the individual recipes below.
- Mockito 3.x migration from 1.x
- Mockito 4 to 5.x upgrade only
- Mockito 4.x upgrade
- Mockito 5.x upgrade
- Mockito best practices
- Replace PowerMock with raw Mockito
Recipes
- Call to Mockito method "verify", "when" or "given" should be simplified
- Cleanup Mockito imports
- JUnit 4 MockitoJUnitRunner.Silent to JUnit Jupiter MockitoExtension with LENIENT settings
- Remove
Mockito.times(0)
andMockito.times(1)
- Remove initialization when using
@InjectMocks
- Replace Mockito 1.x
anyString()
withnullable(String.class)
- Replace Mockito 1.x
anyString()
/any()
withnullable(Class)
- Replace
Mockito.when
on static (non mock) with try-with-resource with MockedStatic - Replace
PowerMock.mockStatic()
withMockito.mockStatic()
- Replace
verifyZeroInteractions() to
verifyNoMoreInteractions() - Use static form of Mockito
MockUtil