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
Cannot inject a generic mock in a superclass #3019
Comments
I believe logstash-logback-encoder is running into this same problem. Here's a small project (mockito-parameterized-type-injection.zip) with a unit tests that fails to inject a mock with mockito 5.3.1. The test works with mockito 5.1.1, so something regressed after 5.1.1 |
I'm pretty sure I'm running into the same issue. |
I also experienced the same issue today with mockito version 5.8.0. |
+1 |
Hello !
The context
I'm trying to update Mockito from version 1 to 5.3.1 (there's some work to do)
I'm facing an issue and I built a tiny project to illustrate it : mockito-upgrade.zip
The environment
I'm using OpenJDK 11.0.14.1, Maven 3.6.1, JUnit 4.11, on Windows 10.
The code
There's an EntryPoint extending AbstractGenericClass. This last one uses a ParameterizerInjectedObject. The class Something was only created to specify generics.
When I try to test EntryPoint, with EntryPointTest, I uses Mockito to inject a mock of ParameterizerInjectedObject in my EntryPoint instance.
The problem
The problem is that the mock isn't injected.
If I remove all generics it works but this is not an acceptable solution.
If you run my test you'll have a NPE because AbstractGenericClass.object isn't initialized : it is intended to demonstrate the problem.
If you initialize it by replacing
private ParameterizedInjectedObject<T> object;
with
private ParameterizedInjectedObject<T> object = new ParameterizedInjectedObject<>();
you'll see the following failure :
My analyzis
When I downgrade to version 5.2.0 I'm facing this issue : #2958
The fix for this one, introduced in version 5.3.0, doesn't seem to handle my case.
I tried to debug Mockito and I think there's a problem with TypeBasedCandidateFilter, starting at line 140 when AbstractGenericClass is analyzed to see if parameter Something is valid for the injection point.
Thanks for reading,
The text was updated successfully, but these errors were encountered: