Make STRICT nulls default behaviour for Mockito

XMLWordPrintableJSON

    • 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:

      1. Enable strict unstubbed method behavior by default (via similar approach as done in mongo-hibernate). Consider using ThrowsException or InsufficientStubbingDetector as an Answer.
      2. 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:

      The ticket has been created after discussion with valentin.kovalenko@mongodb.com

            Assignee:
            Unassigned
            Reporter:
            Slav Babanin
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: