From 35e3539392607f7a206690970c0471bddc3f34ba Mon Sep 17 00:00:00 2001 From: Oliver Wiebeck Date: Tue, 6 Feb 2024 16:46:51 +0100 Subject: [PATCH] Allow for multiple TestConfigProperty annotations on methods --- .../test/component/TestConfigProperty.java | 2 +- .../component/beans/MultiPropComponent.java | 20 ++++++++++++++ ...eConfigPropertiesDeclaredOnMethodTest.java | 26 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test-framework/junit5-component/src/test/java/io/quarkus/test/component/beans/MultiPropComponent.java create mode 100644 test-framework/junit5-component/src/test/java/io/quarkus/test/component/declarative/MultipleConfigPropertiesDeclaredOnMethodTest.java diff --git a/test-framework/junit5-component/src/main/java/io/quarkus/test/component/TestConfigProperty.java b/test-framework/junit5-component/src/main/java/io/quarkus/test/component/TestConfigProperty.java index 7b7cfeaa8ef28..f898c3adf23c4 100644 --- a/test-framework/junit5-component/src/main/java/io/quarkus/test/component/TestConfigProperty.java +++ b/test-framework/junit5-component/src/main/java/io/quarkus/test/component/TestConfigProperty.java @@ -36,7 +36,7 @@ String value(); @Retention(RUNTIME) - @Target(TYPE) + @Target({ TYPE, METHOD }) @interface TestConfigProperties { TestConfigProperty[] value(); diff --git a/test-framework/junit5-component/src/test/java/io/quarkus/test/component/beans/MultiPropComponent.java b/test-framework/junit5-component/src/test/java/io/quarkus/test/component/beans/MultiPropComponent.java new file mode 100644 index 0000000000000..a0b2380bec8d1 --- /dev/null +++ b/test-framework/junit5-component/src/test/java/io/quarkus/test/component/beans/MultiPropComponent.java @@ -0,0 +1,20 @@ +package io.quarkus.test.component.beans; + +import jakarta.enterprise.context.ApplicationScoped; + +import org.eclipse.microprofile.config.inject.ConfigProperty; + +@ApplicationScoped +public class MultiPropComponent { + + @ConfigProperty(name = "foo") + String foo; + + @ConfigProperty(name = "bar") + String bar; + + public String getFooBar() { + return foo + bar; + } + +} diff --git a/test-framework/junit5-component/src/test/java/io/quarkus/test/component/declarative/MultipleConfigPropertiesDeclaredOnMethodTest.java b/test-framework/junit5-component/src/test/java/io/quarkus/test/component/declarative/MultipleConfigPropertiesDeclaredOnMethodTest.java new file mode 100644 index 0000000000000..da778a82a4f2a --- /dev/null +++ b/test-framework/junit5-component/src/test/java/io/quarkus/test/component/declarative/MultipleConfigPropertiesDeclaredOnMethodTest.java @@ -0,0 +1,26 @@ +package io.quarkus.test.component.declarative; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.component.QuarkusComponentTest; +import io.quarkus.test.component.TestConfigProperty; +import io.quarkus.test.component.beans.MultiPropComponent; + +@QuarkusComponentTest +public class MultipleConfigPropertiesDeclaredOnMethodTest { + + @Inject + MultiPropComponent component; + + @TestConfigProperty(key = "foo", value = "BAR") + @TestConfigProperty(key = "bar", value = "BAZ") + @Test + public void testPing() { + assertEquals("BARBAZ", component.getFooBar()); + } + +}