Skip to content

RETURNS_SELF: Avoids returning mock when mock type is assignable to method return type, but method return type is Object.#2687

Merged
TimvdLippe merged 1 commit intomockito:mainfrom
mlichtblau:main
Jun 14, 2022
Merged

RETURNS_SELF: Avoids returning mock when mock type is assignable to method return type, but method return type is Object.#2687
TimvdLippe merged 1 commit intomockito:mainfrom
mlichtblau:main

Conversation

@mlichtblau
Copy link
Copy Markdown
Contributor

Fixes #2686
This PR adds a test which is expected to pass.
Without the change to TriesToReturnSelf it throws a java.lang.ClassCastException.

org.mockitousage.stubbing.StubbingReturnsSelfTest > should_not_fail_when_calling_method_with_generic_return_type FAILED
    java.lang.ClassCastException: class org.mockitousage.stubbing.StubbingReturnsSelfTest$Builder$MockitoMock$idXgt9U6 cannot be cast to class java.lang.String (org.mockitousage.stubbing.StubbingReturnsSelfTest$Builder$MockitoMock$idXgt9U6 is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
        at org.mockitousage.stubbing.StubbingReturnsSelfTest.should_not_fail_when_calling_method_with_generic_return_type(StubbingReturnsSelfTest.java:80)

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jun 14, 2022

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.26%. Comparing base (ec27830) to head (8a53c3e).
⚠️ Report is 556 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #2687   +/-   ##
=========================================
  Coverage     86.26%   86.26%           
- Complexity     2776     2780    +4     
=========================================
  Files           315      315           
  Lines          8334     8334           
  Branches       1037     1035    -2     
=========================================
  Hits           7189     7189           
  Misses          874      874           
  Partials        271      271           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@TimvdLippe TimvdLippe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes a lot of sense, nice fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RETURNS_SELF breaks methods with generic return type

3 participants