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
-
-
Constructor Summary
Constructors Constructor Description AbstractBuilder(Weld weld)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.TaddBeans(Bean<?>... beans)Instructs the initiator to add the specified beans duringAfterBeanDiscoverynotification.TbindResource(String name, Object resource)Binds a name to an object.Ibuild()protected abstract Ibuild(Weld weld, List<Object> instancesToInject, Set<Class<? extends Annotation>> scopesToActivate, Set<Bean<?>> beans)protected Function<InjectionPoint,Object>getEjbFactory()protected Function<InjectionPoint,Object>getPersistenceContextFactory()protected Function<InjectionPoint,Object>getPersistenceUnitFactory()Tinject(Object instance)Instructs the initiator to inject the given non-contextual instance once the container is started, i.e.protected abstract Tself()TsetEjbFactory(Function<InjectionPoint,Object> ejbFactory)Makes it possible to mock@EJBinjection points.TsetPersistenceContextFactory(Function<InjectionPoint,Object> persistenceContextFactory)Makes it possible to mockPersistenceContextinjection points.TsetPersistenceUnitFactory(Function<InjectionPoint,Object> persistenceUnitFactory)Makes it possible to mockPersistenceUnitinjection points.
-
-
-
Constructor Detail
-
AbstractBuilder
public AbstractBuilder(Weld weld)
-
-
Method Detail
-
activate
@SafeVarargs public final T activate(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.ApplicationScopedis ignored as it is always active.- Parameters:
normalScopes-- Returns:
- self
-
getEjbFactory
protected Function<InjectionPoint,Object> getEjbFactory()
-
getPersistenceContextFactory
protected Function<InjectionPoint,Object> getPersistenceContextFactory()
-
getPersistenceUnitFactory
protected Function<InjectionPoint,Object> getPersistenceUnitFactory()
-
inject
public T inject(Object instance)
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
public T addBeans(Bean<?>... beans)
Instructs the initiator to add the specified beans duringAfterBeanDiscoverynotification.- Parameters:
beans-- Returns:
- self
- Since:
- 1.1
- See Also:
AfterBeanDiscovery.addBean(Bean),MockBean,MockInterceptor
-
bindResource
public T bindResource(String name, Object resource)
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
public T setEjbFactory(Function<InjectionPoint,Object> ejbFactory)
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
public T setPersistenceUnitFactory(Function<InjectionPoint,Object> persistenceUnitFactory)
Makes it possible to mockPersistenceUnitinjection points.- Parameters:
persistenceUnitFactory-- Returns:
- self
- Since:
- 1.2
-
setPersistenceContextFactory
public T setPersistenceContextFactory(Function<InjectionPoint,Object> persistenceContextFactory)
Makes it possible to mockPersistenceContextinjection points.- Parameters:
persistenceContextFactory-- Returns:
- self
- Since:
- 1.2
-
self
protected abstract T self()
-
build
protected abstract I build(Weld weld, List<Object> instancesToInject, Set<Class<? extends Annotation>> scopesToActivate, Set<Bean<?>> beans)
-
build
public I build()
- Returns:
- a new initiator instance
-
-