-
Notifications
You must be signed in to change notification settings - Fork 30
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
auto-detect @Inject method parameter types #172
Conversation
Yes, the README talks about what Weld tries to inject (mainly due to its greedy nature) and not really about what it scans in the
The two injections shouldn't be equal, at least not in case of junit - test instances used by junit are not beans provided by Weld meaning declaring an initializer in there makes little sense. |
Ok, I was fairly surprised why this works in the first place but now I see why. We treat the test instance as an |
@@ -101,7 +101,7 @@ static void scanForRequiredBeanClasses(List<Class<?>> testClasses, Weld weld, bo | |||
.forEach(cls -> addClassesToProcess(classesToProcess, cls)); | |||
|
|||
AnnotationSupport.findAnnotatedMethods(currClass, Inject.class, HierarchyTraversalMode.BOTTOM_UP).stream() | |||
.map(Method::getReturnType) |
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.
Honestly, I haven't understood the purpose of getReturnType
as it was there before. I also can't find initializer method return types mentioned in the specs (https://jakarta.ee/specifications/cdi/4.0/jakarta-cdi-spec-4.0#declaring_initializer). Could it possibly have been a bug, here, to evaluate the return type or shall that be kept and if so what for?
It may not hurt if it works now, regardless of how the test is instantiated.
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.
I didn't understand it either and did some digging too - I think it's a bug/oversight from when the annotation based approach was added.
In CDI, @Inject
usage on methods is basically either initializer or annotated constructor neither of which has interesting return type that we should process here.
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 the PR!
weld-testing/junit5/README.md
Line 5 in b2c1c6f
However, it looks like only the field type is detected and added to the container and not the method parameter type.
Also,
should essentially be short for
But only the field injection works as of now as far as I figure