Feat: automatically detect class to mock in mockStatic and mockConstruction#3731
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3731 +/- ##
============================================
+ Coverage 86.39% 86.44% +0.05%
- Complexity 2970 2984 +14
============================================
Files 341 341
Lines 9016 9030 +14
Branches 1111 1111
============================================
+ Hits 7789 7806 +17
+ Misses 946 943 -3
Partials 281 281 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
65ee9e9 to
de99f73
Compare
|
|
||
| @Test | ||
| public void ensure_reified_mocked_static_can_be_called_without_parameters() { | ||
| Assume.assumeThat(System.getenv("MOCK_MAKER"), not(equalTo("mock-maker-subclass"))); |
There was a problem hiding this comment.
Added this assumption in every test to skip them in ci jobs that use SubclassByteBuddyMockMaker, which does not support the creation of static/construction mocks
There was a problem hiding this comment.
Please use the same assumption as previously in this test suite, but then remove the not:
There was a problem hiding this comment.
We also only need 1 assumption for this.
Yep that double assumption was mistakenly left since the first thing I made was:
Assume.assumeThat(Plugins.getMockMaker(), not(instanceOf(SubclassByteBuddyMockMaker.class)));This was to follow the same logic already in place:
Assume.assumeThat(Plugins.getMockMaker(), not(instanceOf(InlineMockMaker.class)));but somehow that didn't work in ci actions that failed regardless of that assumption:
The used MockMaker SubclassByteBuddyMockMaker does not support the creation of static mocks
So I made that tricky inspection on env vars, now replaced as suggested (much better).
TimvdLippe
left a comment
There was a problem hiding this comment.
Looks good, thanks for taking care of that! We do need to update the assumptions to be consistent with the other assumptions
|
|
||
| @Test | ||
| public void ensure_reified_mocked_static_can_be_called_without_parameters() { | ||
| Assume.assumeThat(System.getenv("MOCK_MAKER"), not(equalTo("mock-maker-subclass"))); |
There was a problem hiding this comment.
Please use the same assumption as previously in this test suite, but then remove the not:
353768d to
b44052a
Compare
…uction As PR mockito#2779 introduced the ability to automatically detect the class to mock for mocks and spies, this commit allows doing the same with mockStatic and mockConstruction. Added overloaded reified methods to match all the counterparts that consume an explicit Class literal parameter. For instance, users can now leverage these: * MockedStatic<SomeClass> mock = mockStatic(); * MockedConstruction<SomeClass> mock = mockConstruction(); instead of: * MockedStatic<SomeClass> mock = mockStatic(SomeClass.class); * MockedConstruction<SomeClass> mock = mockConstruction(SomeClass.class); The following methods have been added: * mockStatic(T...) * mockStatic(Answer, T...) * mockStatic(String, T...) * mockStatic(MockSettings, T...) * mockConstruction(T...) * mockConstruction(MockInitializer, T...) * mockConstruction(MockSettings, T...) * mockConstruction(Function<Context, MockSettings>, T...) * mockConstruction(MockSettings, MockInitializer, T...) * mockConstruction(Function<Context, MockSettings>, MockInitializer, T...)
b44052a to
0268b32
Compare
### What changes were proposed in this pull request? This PR aims to upgrade `mockito` to 5.21.0 for Apache Spark K8s Operator `v0.7`. ### Why are the changes needed? To bring the latest features and bug fixes. - https://github.com/mockito/mockito/releases/tag/v5.21.0 - mockito/mockito#3758 - mockito/mockito#3752 - mockito/mockito#3753 - mockito/mockito#3759 - mockito/mockito#3731 ### Does this PR introduce _any_ user-facing change? No behavior change. ### How was this patch tested? Pass the CIs. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #425 from dongjoon-hyun/SPARK-54672. Authored-by: Dongjoon Hyun <dongjoon@apache.org> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
As PR #2779 introduced the ability to automatically detect the class to mock for mocks and spies, this commit allows doing the same with
mockStaticandmockConstruction.Added overloaded reified methods to match all the counterparts that consume an explicit Class literal parameter.
For instance, users can now leverage these:
instead of:
The following methods have been added:
mockStatic(T...)mockStatic(Answer, T...)mockStatic(String, T...)mockStatic(MockSettings, T...)mockConstruction(T...)mockConstruction(MockInitializer, T...)mockConstruction(MockSettings, T...)mockConstruction(Function<Context, MockSettings>, T...)mockConstruction(MockSettings, MockInitializer, T...)mockConstruction(Function<Context, MockSettings>, MockInitializer, T...)Unit tests to cover all the new lines/branches have been added.
The Javadoc of each newly added method is copied from its counterpart that consume an explicit Class literal parameter,
of course documenting the
reifiedparameter instead of the class literal one.As part of the Javadoc,
@since 5.21.0have been added since5.20.0is the current version.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
./gradlew spotlessApplyfor auto-formatting)Fixes #<issue number>in the description if relevantFixes #<issue number>if relevant