diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMock.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMock.java index 11b2791389d75..06fa8a6951574 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMock.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMock.java @@ -3,6 +3,7 @@ import java.lang.annotation.Annotation; import javax.enterprise.inject.spi.CDI; +import javax.enterprise.util.TypeLiteral; import org.junit.jupiter.api.TestInstance; @@ -56,4 +57,16 @@ public static void installMockForType(T mock, Class instance, Ann } MockSupport.installMock(CDI.current().select(instance, qualifiers).get(), mock); } + + /** + * Installs a mock for a CDI normal scoped bean by typeLiteral and qualifiers + * + * @param mock The mock object + * @param typeLiteral TypeLiteral representing the required type + * @param qualifiers The CDI qualifiers of the bean to mock + * @param The bean type + */ + public static void installMockForType(T mock, TypeLiteral typeLiteral, Annotation... qualifiers) { + MockSupport.installMock(CDI.current().select(typeLiteral, qualifiers).get(), mock); + } }