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
- Cleanup PowerMock imports
- Close unclosed static mocks
- JUnit 4 MockitoJUnitRunner.Silent to JUnit Jupiter MockitoExtension with LENIENT settings
- Remove
Mockito.times(0)andMockito.times(1) - Remove
MockitoAnnotations.initMocks(this)if specified JUnit runners - Replace JUnit 4 MockitoJUnitRunner with junit-jupiter MockitoExtension
- Replace Mockito 1.x
anyString()withnullable(String.class) - Replace Mockito 1.x
anyString()/any()withnullable(Class) - Replace
Mockito.whenon static (non mock) with try-with-resource with MockedStatic - Replace
MockitoAnnotations.initMocks(this)toMockitoAnnotations.openMocks(this) - Replace
PowerMock.mockStatic()withMockito.mockStatic() - Replace
PowerMockito.whenNewwith Mockito counterpart - Replace
verifyZeroInteractions()withverifyNoMoreInteractions() - Use static form of Mockito
MockUtil