Package io.quarkus.test.junit
Class QuarkusMock
java.lang.Object
io.quarkus.test.junit.QuarkusMock
Utility class that can be used to mock CDI normal scoped beans.
This includes beans that are
ApplicationScoped and
RequestScoped.
To use this inject the bean into a test, and then invoke the mock
method with your mock.
Mocks installed in BeforeAll will be present for every test,
while mocks installed within a test are cleared after the test has run. Note that you will
likely need to use TestInstance.Lifecycle.PER_CLASS to have a non-static before all method
that can access injected beans.
Note that as the bean is replaced globally you cannot use parallel test execution, as this will
result in race conditions where mocks from one test are active in another.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAllowed options for configuring mocked beans -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> voidinstallMockForInstance(T mock, T instance) Installs a mock for a CDI normal scoped beanstatic <T> voidinstallMockForInstance(T mock, T instance, QuarkusMock.Options options) static <T> voidinstallMockForType(T mock, jakarta.enterprise.util.TypeLiteral<? super T> typeLiteral, QuarkusMock.Options options, Annotation... qualifiers) Installs a mock for a CDI normal scoped bean by typeLiteral and qualifiersstatic <T> voidinstallMockForType(T mock, jakarta.enterprise.util.TypeLiteral<? super T> typeLiteral, Annotation... qualifiers) Installs a mock for a CDI normal scoped bean by typeLiteral and qualifiersstatic <T> voidinstallMockForType(T mock, Class<? super T> instance, Annotation... qualifiers) Installs a mock for a CDI normal scoped bean
-
Constructor Details
-
QuarkusMock
public QuarkusMock()
-
-
Method Details
-
installMockForInstance
public static <T> void installMockForInstance(T mock, T instance) Installs a mock for a CDI normal scoped bean- Type Parameters:
T- The bean type- Parameters:
mock- The mock objectinstance- The CDI normal scoped bean that was injected into your test
-
installMockForInstance
-
installMockForType
public static <T> void installMockForType(T mock, Class<? super T> instance, Annotation... qualifiers) Installs a mock for a CDI normal scoped bean- Type Parameters:
T- The bean type- Parameters:
mock- The mock objectinstance- The type of the CDI normal scoped bean to replacequalifiers- The CDI qualifiers of the bean to mock
-
installMockForType
public static <T> void installMockForType(T mock, jakarta.enterprise.util.TypeLiteral<? super T> typeLiteral, Annotation... qualifiers) Installs a mock for a CDI normal scoped bean by typeLiteral and qualifiers- Type Parameters:
T- The bean type- Parameters:
mock- The mock objecttypeLiteral- TypeLiteral representing the required typequalifiers- The CDI qualifiers of the bean to mock
-
installMockForType
public static <T> void installMockForType(T mock, jakarta.enterprise.util.TypeLiteral<? super T> typeLiteral, QuarkusMock.Options options, Annotation... qualifiers) Installs a mock for a CDI normal scoped bean by typeLiteral and qualifiers- Type Parameters:
T- The bean type- Parameters:
mock- The mock objecttypeLiteral- TypeLiteral representing the required typequalifiers- The CDI qualifiers of the bean to mock
-