Skip to content

Commit

Permalink
Allow beans to be injected in tests even if they aren't used in the app
Browse files Browse the repository at this point in the history
Fixes: #1749
  • Loading branch information
geoand committed Apr 2, 2019
1 parent d63d2a1 commit 059eaa5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.arc.deployment;

import org.jboss.jandex.DotName;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.runtime.LaunchMode;

public class TestsAsBeanDefiningAnnotationsProcessor {

@BuildStep
public void testsAsBeanDefiningAnnotations(LaunchModeBuildItem launchMode,
BuildProducer<BeanDefiningAnnotationBuildItem> producer) {
if (launchMode.getLaunchMode() != LaunchMode.TEST) {
return;
}

producer.produce(new BeanDefiningAnnotationBuildItem(DotName.createSimple("io.quarkus.test.junit.QuarkusTest")));
producer.produce(new BeanDefiningAnnotationBuildItem(DotName.createSimple("org.junit.runner.RunWith")));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkus.example.arc;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class UnusedBean {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkus.example.test;

import static org.junit.jupiter.api.Assertions.assertNotNull;

import javax.inject.Inject;

import org.junit.jupiter.api.Test;

import io.quarkus.example.arc.UnusedBean;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class BeanOnlyInTestCase {

@Inject
UnusedBean unusedBean;

@Test
void assertBeanIsInjected() {
assertNotNull(unusedBean);
}
}

0 comments on commit 059eaa5

Please sign in to comment.