-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for Issue2656 #2659
Fix for Issue2656 #2659
Conversation
Example failing test for mockito#2656
fixes: mockito#2656
3c15da8
to
d0bf836
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor changes, but overall looking good!
src/main/java/org/mockito/internal/configuration/MockAnnotationProcessor.java
Outdated
Show resolved
Hide resolved
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2659 +/- ##
============================================
+ Coverage 86.22% 86.27% +0.04%
- Complexity 2763 2766 +3
============================================
Files 314 315 +1
Lines 8290 8296 +6
Branches 1031 1031
============================================
+ Hits 7148 7157 +9
+ Misses 873 872 -1
+ Partials 269 267 -2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!
fix: #2656
Release 4.6.0 introduced a new feature #2650 to allow strictness to be set via the
@Mock
annotation. Unfortunately, the feature has a bug that results in any test-level strictness setting being ignored, e.g.In the above code the
lenientMock
would actually be strict, as the@Mock
'sstrictness
defaults toSTRICT_STUBS
. This default was overriding the test levelLENIENT
.To fix the issue the default of the
Mock.strictness
method needs to be something meaningnot set
, allowing the mock's strictness to be ignored and the test level strictness to be used.Unfortunately, no
no set
value exists in theStrictness
enum and it is illegal to default tonull
. Fixing this in a backwards compatible way would have meant polluting the public API, (e.g. adding aDEFAULT
value to the existingStrictness
enum, which doesn't make sense in a lot of other places the enum is used). As this feature has only just been released, and is essentially broken, a breaking change is being introduced to fix the issue.BREAKING CHANGE: This PR changes the return value of
Mock.strictness()
to a localStrictness
enum value. This will require users to change any code written against 4.6.0 that sets thestrictness
via the@Mock
annotation to change their code.Example code migration:
To:
Checklist
including project members to get a better picture of the change
commit is meaningful and help the people that will explore a change in 2 years
Fixes #<issue number>
in the description if relevantFixes #<issue number>
if relevant