You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mock created with Mockito.withSettings().strictness(Strictness.STRICT_STUBS) does not behave in the same way as @Mock(strictness = Mock.Strictness.STRICT_STUBS)
FooRepository.java
public interface FooRepository {
boolean isFooPresent(int fooId);
}
FooService.java
public class FooService {
private final FooRepository fooRepository;
public FooService(FooRepository fooRepository) {
this.fooRepository = fooRepository;
}
String getSomething(int fooId) {
var found = fooRepository.isFooPresent(fooId);
return String.valueOf(found);
}
}
Mock created with
Mockito.withSettings().strictness(Strictness.STRICT_STUBS)
does not behave in the same way as@Mock(strictness = Mock.Strictness.STRICT_STUBS)
FooRepository.java
FooService.java
FooServiceTest.java
Observed behaviour:
testLenUsingAnnotationBasedMock
testPotentialStubbingProblem
is throwntestLenUsingRegularMock
passesExpected behaviour:
PotentialStubbingProblem
Quick inspection of code shows:
Mockito.mock
versionCreationSettings.stubbingLookupListeners
are empty@Mock
versionCreationSettings.stubbingLookupListeners
contain DefaultStubbingLookupListenerSoftware versions
See also
https://stackoverflow.com/questions/77940311/potentialstubbingproblem-solved-by-moving-a-class-how-does-it-work
Note that some configuration are impossible to mock via Mockito
(same as any question on stackoverflow.com)
The text was updated successfully, but these errors were encountered: