-
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.
Browse files
Browse the repository at this point in the history
Allow beans to be injected in tests even if they aren't used in the application
- Loading branch information
Showing
6 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
core/deployment/src/main/java/io/quarkus/deployment/builditem/TestAnnotationBuildItem.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,20 @@ | ||
package io.quarkus.deployment.builditem; | ||
|
||
import org.jboss.builder.item.MultiBuildItem; | ||
|
||
/** | ||
* This is an optional build item that allows us to track annotations that will define test classes | ||
* It is only available during tests | ||
*/ | ||
public final class TestAnnotationBuildItem extends MultiBuildItem { | ||
|
||
private final String annotationClassName; | ||
|
||
public TestAnnotationBuildItem(String annotationClassName) { | ||
this.annotationClassName = annotationClassName; | ||
} | ||
|
||
public String getAnnotationClassName() { | ||
return annotationClassName; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...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,20 @@ | ||
package io.quarkus.arc.deployment; | ||
|
||
import java.util.List; | ||
|
||
import org.jboss.jandex.DotName; | ||
|
||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.TestAnnotationBuildItem; | ||
|
||
public class TestsAsBeanDefiningAnnotationsProcessor { | ||
|
||
@BuildStep | ||
public void produce(List<TestAnnotationBuildItem> items, BuildProducer<BeanDefiningAnnotationBuildItem> producer) { | ||
for (TestAnnotationBuildItem item : items) { | ||
producer.produce(new BeanDefiningAnnotationBuildItem(DotName.createSimple(item.getAnnotationClassName()))); | ||
} | ||
} | ||
|
||
} |
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); | ||
} | ||
} |
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
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