In the following example, the unnecessaryStub()
test method in NestedTests
should succeed since it should inherit the Strictness.LENIENT
configuration from its enclosing class; however, it currently fails with an UnnecessaryStubbingException
because the default Strictness.STRICT_STUBS
is used.
@SpringJUnitConfig
@MockitoBeanSettings(Strictness.LENIENT)
class InheritedStrictnessTests {
@Nested
class NestedTests {
@Test
void unnecessaryStub() {
List list = mock();
when(list.get(anyInt())).thenReturn(new Object());
}
}
@Configuration
static class Config {
// no beans
}
}