From ece996027adcd53330b68b89023cfe1134293f54 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sat, 2 Mar 2024 12:36:12 +0100 Subject: [PATCH] auto-detect inject method parameter types --- .../jboss/weld/junit5/auto/ClassScanning.java | 2 +- .../junit5/auto/InjectMethodParamTest.java | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 junit5/src/test/java/org/jboss/weld/junit5/auto/InjectMethodParamTest.java diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/ClassScanning.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/ClassScanning.java index 5b063952..233aa0c1 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/ClassScanning.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/ClassScanning.java @@ -101,7 +101,7 @@ static void scanForRequiredBeanClasses(List> testClasses, Weld weld, bo .forEach(cls -> addClassesToProcess(classesToProcess, cls)); AnnotationSupport.findAnnotatedMethods(currClass, Inject.class, HierarchyTraversalMode.BOTTOM_UP).stream() - .map(Method::getReturnType) + .flatMap(method -> getExecutableParameterTypes(method, explicitInjection).stream()) .forEach(cls -> addClassesToProcess(classesToProcess, cls)); findFirstAnnotatedConstructor(currClass, Inject.class) diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/InjectMethodParamTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/InjectMethodParamTest.java new file mode 100644 index 00000000..9f98b388 --- /dev/null +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/InjectMethodParamTest.java @@ -0,0 +1,29 @@ +package org.jboss.weld.junit5.auto; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import jakarta.enterprise.context.Dependent; +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; + +@EnableAutoWeld +class InjectMethodParamTest { + + @Dependent + static class Foo { + } + + private Foo foo; + + @Inject + private void setFoo(Foo foo) { + this.foo = foo; + } + + @Test + void testInjectMethodParametersAreAddedToContainerWithNoConfiguration() { + assertNotNull(foo); + } + +}