Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add support for @javax.inject.Named and Spring's @Qualifier #214
Occasionaly, a tested class may have dependencies of different types which, in turn, have some other dependency of a type X, which need to be resolved to different instances of type X.
When using CDI or Spring DI, these X dependencies are usually qualified so they can be properly resolved. CDI's @nAmed, and Spring's @qualifier annotations are then used on fields of type X to specify the name of the desired instance.
So, when an injected field is annotated with @nAmed("name") or @qualifier("name"), JMockit should look for an @Injectable or @tested instance of the same type and "name", instead of using the regular searching rules (just the type, or type + injected field name).
When I mock it using
I have the following error:
If I remove the
I was working with a colleague recently and we encountered a side effect of this implementation.
The application under test has beans with qualifiers containing dashes. Since this code expects the injectable variable to match the beanId we were in a bit of a pickle.
We worked around it by changing the
My question is: why not add an attribute to the
I haven't dug into the code yet, but if you'll accept a PR to remedy this issue I'd be willing to try and make the contribution myself.