From 3df85968e7c3bfd924de376e72015dc9b279fc33 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 28 Mar 2022 10:05:27 +0300 Subject: [PATCH] Provide proper error message when using @ConfigProperty in @QuarkusIntegrationTest These tests do not support injection (as they are not beans), but this fact is not obvious. This error message (which is analogous to what we already have with @Inject) should make this fact salient. --- .../io/quarkus/test/junit/IntegrationTestUtil.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java index 5dfe8ccea9b61..454ded5d53195 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java @@ -34,6 +34,7 @@ import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.inject.ConfigProperty; import org.jboss.jandex.Index; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.platform.commons.JUnitException; @@ -72,13 +73,18 @@ static void ensureNoInjectAnnotationIsUsed(Class testClass) { Class current = testClass; while (current.getSuperclass() != null) { for (Field field : current.getDeclaredFields()) { - Inject injectAnnotation = field.getAnnotation(Inject.class); - if (injectAnnotation != null) { + if (field.getAnnotation(Inject.class) != null) { throw new JUnitException( "@Inject is not supported in @NativeImageTest and @QuarkusIntegrationTest tests. Offending field is " + field.getDeclaringClass().getTypeName() + "." + field.getName()); } + if (field.getAnnotation(ConfigProperty.class) != null) { + throw new JUnitException( + "@ConfigProperty is not supported in @NativeImageTest and @QuarkusIntegrationTest tests. Offending field is " + + field.getDeclaringClass().getTypeName() + "." + + field.getName()); + } } current = current.getSuperclass(); }