-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow beans to be injected in tests even if they aren't used in the app
Fixes: #1749
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...ment/src/main/java/io/quarkus/arc/deployment/TestsAsBeanDefiningAnnotationsProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
integration-tests/main/src/main/java/io/quarkus/example/arc/UnusedBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
22 changes: 22 additions & 0 deletions
22
integration-tests/main/src/test/java/io/quarkus/example/test/BeanOnlyInTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |