-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Java Drivers
-
None
-
None
-
None
-
None
-
None
-
None
We currently have two approaches for handling unstubbed Mockito calls:
- MongoMockito
- RETURNS_SMART_NULLS
With RETURNS_SMART_NULLS, primitive return types still use their default values (e.g. an unstubbed getInt() returns 0). That can make a test "succeed" even when the dependency wasn’t stubbed according to the actual requirement, hiding a potential bug. For example, the correct behavior should be triggered when getInt() == 1, but the test passes because it silently uses 0 and the production code incorrectly checks getInt() == 0. Having unstubbed methods fail instead forces us to double-check and think about the test’s requirements.
Acceptance criteria:
- Enable strict unstubbed method behavior by default (via similar approach as done in mongo-hibernate). Consider using ThrowsException or InsufficientStubbingDetector as an Answer.
- Evaluate test migration effort:
- If minimal, migrate the tests by explicitly mocking methods that cause failures after enabling the aforementioned behaviour.
- If significant, introduce an annotation or configuration flag to mark classes as opted-out of default behaviour.
References:
- Discussion on related PR: mongo-java-driver#1835
The ticket has been created after discussion with valentin.kovalenko@mongodb.com.