Package org.jboss.weld.junit
Class AbstractWeldInitiator.AbstractBuilder<I extends AbstractWeldInitiator,T extends AbstractWeldInitiator.AbstractBuilder<I,T>>
java.lang.Object
org.jboss.weld.junit.AbstractWeldInitiator.AbstractBuilder<I,T>
- Enclosing class:
- AbstractWeldInitiator
protected abstract static class AbstractWeldInitiator.AbstractBuilder<I extends AbstractWeldInitiator,T extends AbstractWeldInitiator.AbstractBuilder<I,T>>
extends Object
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Tactivate(Class<? extends Annotation>... normalScopes) Activate and deactivate contexts for the given normal scopes for the lifetime of the initialized Weld container, by default for each test method execution.Instructs the initiator to add the specified beans duringAfterBeanDiscoverynotification.bindResource(String name, Object resource) Binds a name to an object.build()protected abstract Ibuild(Weld weld, List<Object> instancesToInject, Set<Class<? extends Annotation>> scopesToActivate, Set<Bean<?>> beans) protected Function<InjectionPoint,Object> protected Function<InjectionPoint,Object> protected Function<InjectionPoint,Object> Instructs the initiator to inject the given non-contextual instance once the container is started, i.e.protected abstract Tself()setEjbFactory(Function<InjectionPoint, Object> ejbFactory) Makes it possible to mock@EJBinjection points.setPersistenceContextFactory(Function<InjectionPoint, Object> persistenceContextFactory) Makes it possible to mockPersistenceContextinjection points.setPersistenceUnitFactory(Function<InjectionPoint, Object> persistenceUnitFactory) Makes it possible to mockPersistenceUnitinjection points.
-
Field Details
-
weld
-
instancesToInject
-
scopesToActivate
-
beans
-
resources
-
-
Constructor Details
-
AbstractBuilder
-
-
Method Details
-
activate
Activate and deactivate contexts for the given normal scopes for the lifetime of the initialized Weld container, by default for each test method execution.ApplicationScopedis ignored as it is always active.- Parameters:
normalScopes-- Returns:
- self
-
getEjbFactory
-
getPersistenceContextFactory
-
getPersistenceUnitFactory
-
inject
Instructs the initiator to inject the given non-contextual instance once the container is started, i.e. during test execution.This method could be used e.g. to inject a test class instance:
public class InjectTest { @Rule public WeldInitiator weld = WeldInitiator.fromTestPackage().inject(this).build(); @Inject Foo foo; @Test public void testFoo() { assertEquals("foo", foo.getId()); } }Injected
Dependentbean instances are destroyed after the test execution. However, the lifecycle of the non-contextual instance is not managed by the container and all injected references will be invalid after the test execution.- Parameters:
instance-- Returns:
- self
-
addBeans
Instructs the initiator to add the specified beans duringAfterBeanDiscoverynotification.- Parameters:
beans-- Returns:
- self
- Since:
- 1.1
- See Also:
-
bindResource
Binds a name to an object. This allows to mockResourceinjection points easily, e.g.:@Dependent class Foo { @Resource(lookup = "bar") String bar; }- Parameters:
name-resource-- Returns:
- self
- Since:
- 1.2
-
setEjbFactory
Makes it possible to mock@EJBinjection points.Note that for Weld 3
org.jboss.weld.module:weld-ejbdependency is also required.- Parameters:
ejbFactory-- Returns:
- self
- Since:
- 1.2
-
setPersistenceUnitFactory
Makes it possible to mockPersistenceUnitinjection points.- Parameters:
persistenceUnitFactory-- Returns:
- self
- Since:
- 1.2
-
setPersistenceContextFactory
Makes it possible to mockPersistenceContextinjection points.- Parameters:
persistenceContextFactory-- Returns:
- self
- Since:
- 1.2
-
self
-
build
-
build
- Returns:
- a new initiator instance
-