-
-
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 #3005 (and #3006) draft #3022
Conversation
4cc29ae
to
8906dd6
Compare
would fix just posted #3019, too |
Thanks a lot for this PR and your contribution! At the moment, I am still unsure what we should do with these kind of changes. Before, I advocated for deprecating Therefore, with a PR that adds more than 1 thousand lines to address 3 different regressions with a single feature, I am unsure if that trade-off is worth it. I know people love @mockito/developers we need to figure out what to do here. In my opinion, the intention of |
@TimvdLippe Thank you for your quick reply! I totally agree what you say. Have you also seen my alternative suggestion here?: #3011 that one could be implemented with really a few lines of codes, would address the most use cases of |
I think that this might live in a project outside of Mockito, and we can offer the API for it with a very basic implementation as a default? Any more complex version could then be loaded via a service loader like other plugins. |
Hi, Removing InjectMocks would introduce a breaking change in Mockito. Such a change may be done in a major version (6.0 ?). For now the version 5.3.1 is broken regarding InjectMocks and it needs a fix. For me, whatever you choose to do in version 6.0 or higher, version 5.X must be fixed. |
I would not want to take the API out, I would however make it injectable in its implementation. Is there a more simple fix than the huge income of new code? |
I heard the call for simplification and will present a new version with roughly half the code in the next days. |
fixes mockito#3005 and others
Signed-off-by: Harald Fassler <harald.fassler+9974@gmail.com>
8906dd6
to
b59d960
Compare
This pull request seems to have been approved last week (Github removed the warning notice) and only need to be merged. |
@nineninesevenfour : you maybe need to remove the draft attribute on this PR to make it reviewed and merged. |
replaced by #3123 |
Hello @TimvdLippe ,
this is an early preview of an attempt to fix several issues that occur currently with
@InjectMocks
in combination with generic types. It is not ready to merge yet, but I provide it in order to possibly receive early feedback and also to signal that I am working on a solution.It contains a (partly) reimplementation of the logic in
TypeBasedCandidateFilter
. TheisCompatibleTypes
method in this class evolved from a simple use case with matching generic parameters of collections and starts with the assumption that the field to be injected has the same number of generic parameters as generic arguments present on the mocked field. This is not necessarily the case and I found it to be the main cause for the issues around.Instead in the code provided with this PR, I attempt to fill in generic arguments into generic parameters from the declaration of
@InjectMocks
down to the candidate injection field by using the type hierarchy. The main logic for it is inGenericTypeUse.findExactAncestor()
.Additionally I make a (hopefully clear) distinction of collecting generic type information - and the actual comparison of that information. The collection happens in the classes
GenericTypeUse
andGenericTypeResolver
- emitting the typeMappedType
while the comparison happens in classAssignmentMatcher
and then reads as follows:I admit there are similarities with the already present class
GenericMetadataSupport
(both carry a map of type parameters to actual arguments), but I could not reuse it as is right now, because it has been crafted for return types for the case of mocking, while here we have to handle fields.I hope that this PR goes in the right direction and if not, please let me know. Thank you!
Todos
MappedTypeSimple
andMappedTypeWildcard
againTypeBasedCandidateFilter
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