Skip to content

Commit b23a699

Browse files
authored
Document strictness implication of RemoveInitMocksIfRunnersSpecified (#990)
Removing an explicit `openMocks(this)` call shifts `@Mock` fields onto the extension/runner's strict mocking session, which may surface `UnnecessaryStubbingException` for tests that previously benefited from the lenient mocks created by `openMocks`. Mention the opt-out via `@MockitoSettings(strictness = Strictness.LENIENT)`. Refs #987
1 parent b06f6a4 commit b23a699

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/main/java/org/openrewrite/java/testing/mockito/RemoveInitMocksIfRunnersSpecified.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public class RemoveInitMocksIfRunnersSpecified extends Recipe {
4444
@Getter
4545
final String description = "Remove `MockitoAnnotations.initMocks(this)` and `MockitoAnnotations.openMocks(this)` if class-level " +
4646
"JUnit runners `@RunWith(MockitoJUnitRunner.class)` or `@ExtendWith(MockitoExtension.class)` are specified. " +
47-
"These manual initialization calls are redundant when using Mockito's JUnit integration.";
47+
"These manual initialization calls are redundant when using Mockito's JUnit integration. " +
48+
"Note that the `@Mock` fields will then be initialized by the strict mocking session of the extension or runner; " +
49+
"tests that relied on the lenient mocks created by an explicit `openMocks(this)` call inside `@BeforeEach` " +
50+
"may surface `UnnecessaryStubbingException`. Add `@MockitoSettings(strictness = Strictness.LENIENT)` to opt out.";
4851

4952
private static final String MOCKITO_EXTENSION = "org.mockito.junit.jupiter.MockitoExtension";
5053
private static final String MOCKITO_JUNIT_RUNNER = "org.mockito.junit.MockitoJUnitRunner";

0 commit comments

Comments
 (0)