Package org.jboss.weld.junit5
Class WeldInitiator
- java.lang.Object
-
- org.jboss.weld.junit.AbstractWeldInitiator
-
- org.jboss.weld.junit5.WeldInitiator
-
- All Implemented Interfaces:
jakarta.enterprise.inject.Instance<Object>
,jakarta.inject.Provider<Object>
,Iterable<Object>
,org.jboss.weld.environment.ContainerInstance
public class WeldInitiator extends AbstractWeldInitiator
JUnit 5 initiator - can be used to customize the Weld SE container started byWeldJunit5Extension
.@ExtendWith(WeldJunit5Extension.class) public class SimpleTest { @WeldSetup public WeldInitiator weld = WeldInitiator.of(Foo.class); @Test public void testFoo() { // Weld container is started automatically // WeldInitiator can be used to perform programmatic lookup of beans assertEquals("baz", weld.select(Foo.class).get().getBaz()); } }
- Author:
- Matej Novotny
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WeldInitiator.Builder
This builder can be used to customize the finalWeldInitiator
instance, e.g.-
Nested classes/interfaces inherited from class org.jboss.weld.junit.AbstractWeldInitiator
AbstractWeldInitiator.AbstractBuilder<I extends AbstractWeldInitiator,T extends AbstractWeldInitiator.AbstractBuilder<I,T>>, AbstractWeldInitiator.ToInject
-
-
Field Summary
-
Fields inherited from class org.jboss.weld.junit.AbstractWeldInitiator
beans, container, extension, instancesToInject, scopesToActivate, weld
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.jboss.weld.environment.se.Weld
createWeld()
The returnedWeld
instance has: automatic discovery disabled concurrent deployment disabledstatic WeldInitiator.Builder
from(Class<?>... beanClasses)
Create a builder instance.static WeldInitiator.Builder
from(org.jboss.weld.environment.se.Weld weld)
Create a builder instance.static WeldInitiator.Builder
fromTestPackage()
Create a builder instance.static WeldInitiator
of(Class<?>... beanClasses)
The container is configured with the result ofcreateWeld()
method and the given bean classes are added.static WeldInitiator
of(org.jboss.weld.environment.se.Weld weld)
The container is configured through a providedWeld
instance.static WeldInitiator
ofTestPackage()
The container is configured with the result ofcreateWeld()
method and all the classes from the test class package are added.static WeldInitiator
performDefaultDiscovery()
The container is instructed to do automatic bean discovery, the resulting bean archive is NOT synthetic.-
Methods inherited from class org.jboss.weld.junit.AbstractWeldInitiator
container, createToInject, destroy, event, get, getBeanManager, getId, initWeldContainer, injectInstances, injectNonContextual, isAmbiguous, isRunning, isUnsatisfied, iterator, releaseInstances, select, select, select, shutdown, shutdownWeldContainer
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
of
public static WeldInitiator of(Class<?>... beanClasses)
The container is configured with the result ofcreateWeld()
method and the given bean classes are added. If any of added classes is an extension, it is automatically recognized and enabled.- Parameters:
beanClasses
-- Returns:
- a new WeldInitiator instance
- See Also:
Weld.beanClasses(Class...)
-
of
public static WeldInitiator of(org.jboss.weld.environment.se.Weld weld)
The container is configured through a providedWeld
instance.- Parameters:
weld
-- Returns:
- a new WeldInitiator instance
-
ofTestPackage
public static WeldInitiator ofTestPackage()
The container is configured with the result ofcreateWeld()
method and all the classes from the test class package are added.- Returns:
- a new WeldInitiator instance
-
performDefaultDiscovery
public static WeldInitiator performDefaultDiscovery()
The container is instructed to do automatic bean discovery, the resulting bean archive is NOT synthetic. Note that this requires beans.xml to be present. It is equals toWeldInitiator.of(new Weld())
invocation.- Returns:
- a new WeldInitiator instance
-
from
public static WeldInitiator.Builder from(Class<?>... beanClasses)
Create a builder instance.- Parameters:
beanClasses
-- Returns:
- a builder instance
- See Also:
of(Class...)
-
from
public static WeldInitiator.Builder from(org.jboss.weld.environment.se.Weld weld)
Create a builder instance.- Parameters:
weld
-- Returns:
- a builder instance
- See Also:
of(Weld)
-
fromTestPackage
public static WeldInitiator.Builder fromTestPackage()
Create a builder instance.- Returns:
- a builder instance
- See Also:
ofTestPackage()
-
createWeld
public static org.jboss.weld.environment.se.Weld createWeld()
The returnedWeld
instance has:- automatic discovery disabled
- concurrent deployment disabled
- Returns:
- a new
Weld
instance suitable for testing - See Also:
AbstractWeldInitiator.createWeld()
-
-