Feat: add generic-inferred methods for constructing ArgumentCaptors#3144
Merged
TimvdLippe merged 3 commits intomockito:mainfrom Oct 12, 2023
Merged
Feat: add generic-inferred methods for constructing ArgumentCaptors#3144TimvdLippe merged 3 commits intomockito:mainfrom
TimvdLippe merged 3 commits intomockito:mainfrom
Conversation
5e85696 to
a09fa59
Compare
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3144 +/- ##
=========================================
Coverage 85.51% 85.52%
- Complexity 2908 2912 +4
=========================================
Files 333 333
Lines 8852 8856 +4
Branches 1095 1095
=========================================
+ Hits 7570 7574 +4
Misses 994 994
Partials 288 288
☔ View full report in Codecov by Sentry. |
Added a new method .captor(U...) on the ArgumentCaptor class that has the same interface as Mockito.mock(U...) with the goal of removing the need for unchecked-warning suppression when users make use of generic types in argument captors.
a09fa59 to
edc581d
Compare
TimvdLippe
reviewed
Oct 12, 2023
Contributor
TimvdLippe
left a comment
There was a problem hiding this comment.
Only 1 nit. The rest LGTM! Nice fix indeed.
c6511f7 to
4be5234
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added a new method .captor(U...) on the ArgumentCaptor class that has the same interface as Mockito.mock(U...) with the goal of removing the need for unchecked-warning suppression when users make use of generic types in argument captors.
This allows the following usage without raising compiler warnings:
...rather than the current solution, which is less elegant...
A side effect of wanting to write tests for this meant I needed to expose the class held within a captor, so an additional method named
.getCaptorType()has also been added. I have added this as public as it feels like a useful thing to expose anyway, given the user will know what is held internally. However, if this is unacceptable then I am happy to demote it to package-private or remove it and replace it with something likeassertThat(captor).hasPropertyOrFieldWithValue("clazz", expectedClass);, or anything else that is suggested.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