-
-
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
Feature 2921 generic types #2923
Feature 2921 generic types #2923
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2923 +/- ##
============================================
+ Coverage 85.65% 85.66% +0.01%
- Complexity 2847 2861 +14
============================================
Files 325 325
Lines 8623 8678 +55
Branches 1060 1070 +10
============================================
+ Hits 7386 7434 +48
- Misses 964 967 +3
- Partials 273 277 +4
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
src/main/java/org/mockito/internal/configuration/injection/filter/TypeBasedCandidateFilter.java
Outdated
Show resolved
Hide resolved
WildcardType wildcardTypeToMock = (WildcardType) typeToMock; | ||
Type[] upperBounds = wildcardTypeToMock.getUpperBounds(); | ||
return Arrays.stream(upperBounds).anyMatch(t -> isCompatibleTypes(t, mockType)); | ||
} else if (typeToMock instanceof GenericArrayType && mockType instanceof GenericArrayType) { |
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.
CodeCov reports this branch is not covered. Can you please expand the coverage here or remove this check?
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.
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.
Removed not covered code
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.
There is still some coverage missing, can you either remove the uncovered branches or add regression tests that cover the logic? https://app.codecov.io/gh/mockito/mockito/pull/2923/blob/src/main/java/org/mockito/internal/configuration/injection/filter/TypeBasedCandidateFilter.java Since this is intricate logic and a hot codepath, I would like to see full coverage here.
subprojects/junit-jupiter/src/test/java/org/mockitousage/GenericTypeMockTest.java
Outdated
Show resolved
Hide resolved
subprojects/junit-jupiter/src/test/java/org/mockitousage/GenericTypeMockTest.java
Outdated
Show resolved
Hide resolved
@TimvdLippe please review and resolve where appropriate |
https://github.com/mockito/mockito/actions/runs/4296719412/jobs/7488794171
I don't know what to make of this, maybe just re-run? |
@TimvdLippe thx for restarting the build. Did you have a chance to take a look at my comments on your review? Sorry for maybe being pushy, but I have some time on my hands for this at the moment, which might change soon. Also I don't know under what circumstances you are able to devote time to Mockito :) |
I am on vacation this week, but should be back next week to review. |
Alright, have a nice vacation! |
@jfrantzius Apart from the missing code coverage, this PR LGTM! |
@TimvdLippe I added more test coverage |
@jfrantzius please look at the code coverage report and see which branches are missing coverage. There are still some missing, for example one where the generic types don't match. |
I added support for generic injectee classes, e.g. public class UnderTestWithTypeParameters<T1, T2> {
List<T1> t1List;
Set<T2> t2Set;
} There is one line that cannot be covered in tests, please see the comment there: https://github.com/jfrantzius/mockito/blob/feature-2921-generic-type/src/main/java/org/mockito/internal/configuration/injection/filter/TypeBasedCandidateFilter.java#L70 |
Could you please approve the workflow @TimvdLippe ? |
@TimvdLippe I'm off for today, if you trigger the build then the last line missing in coverage should now be covered as well. |
I guess it's time to setup Spotless in my IDE ... |
I would love to be able to start builds, but unfortunately I have to always bug you about it @TimvdLippe :) |
@TimvdLippe build might need another nudge in https://github.com/mockito/mockito/actions/runs/4372977101/jobs/7658608894
|
WDYT @TimvdLippe , is it good to merge? |
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 all the work, this LGTM!
Fixes #2921 by preserving and using the generic Java type information that was previously lost to type erasure.
Contains a JUnit test with usage example, demonstrating that fields with generic types do not need to have matching names anymore.