Skip to content
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

Allow injection of config properties into test with @Inject #2062

Merged
merged 1 commit into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import javax.inject.Inject;
import javax.inject.Qualifier;

import org.eclipse.microprofile.config.inject.ConfigProperty;

import io.quarkus.arc.Arc;
import io.quarkus.arc.CurrentInjectionPointProvider.InjectionPointImpl;
import io.quarkus.deployment.test.TestResourceProvider;
Expand All @@ -21,7 +23,7 @@ public void inject(Object test) {
BeanManager beanManager = Arc.container().beanManager();
while (c != Object.class) {
for (Field field : c.getDeclaredFields()) {
if (field.isAnnotationPresent(Inject.class)) {
if (field.isAnnotationPresent(Inject.class) || field.isAnnotationPresent(ConfigProperty.class)) {
try {
Set<Annotation> qualifiers = new HashSet<>();
Set<Annotation> annotations = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.it.main;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class PropertyInjectionTestCase {

@ConfigProperty(name = "web-message")
String message;

@Test
void testConfigPropertyInjectedIntoTest() {
Assertions.assertEquals("A message", message);
}
}