Package org.jboss.weld.junit
Class MockBean<T>
java.lang.Object
org.jboss.weld.junit.MockBean<T>
- Type Parameters:
T- See alsoWeldInitiator.Builder#addBean(Bean)method.
- All Implemented Interfaces:
Contextual<T>,Bean<T>,BeanAttributes<T>,PassivationCapable
This custom
Bean implementation is useful for mocking.
A new instance is usually created through a MockBean.Builder (see also builder()) and then passed to the
WeldInitiator.Builder#addBeans(Bean...) method.
- Since:
- 1.1
- Author:
- Martin Kouba
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA builder instance should not be reused nor shared.static interfacestatic interface -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMockBean(Class<?> beanClass, Set<Class<? extends Annotation>> stereotypes, boolean alternative, boolean selectForSyntheticBeanArchive, String name, Set<Annotation> qualifiers, Set<Type> types, Class<? extends Annotation> scope, MockBean.CreateFunction<T> createCallback, MockBean.DestroyFunction<T> destroyCallback) -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> MockBean.Builder<T>builder()create(CreationalContext<T> creationalContext) voiddestroy(T instance, CreationalContext<T> creationalContext) Class<?>getId()getName()Class<? extends Annotation>getScope()Set<Class<? extends Annotation>>getTypes()booleanstatic <T> Bean<T>static <T> MockBean.Builder<T>A convenient method to create aMockBean.Builderinitialized from the specified bean class.
-
Constructor Details
-
MockBean
protected MockBean(Class<?> beanClass, Set<Class<? extends Annotation>> stereotypes, boolean alternative, boolean selectForSyntheticBeanArchive, String name, Set<Annotation> qualifiers, Set<Type> types, Class<? extends Annotation> scope, MockBean.CreateFunction<T> createCallback, MockBean.DestroyFunction<T> destroyCallback)
-
-
Method Details
-
builder
By default, the bean:- has no name
- has
Dependentscope - has
Anyqualifier andDefaultis added automatically if no other qualifiers are set - has
Objectbean type - has no stereotypes
- is not an alternative
Note that
MockBean.Builder.creating(Object)orMockBean.Builder.create(CreateFunction)must be always set. Otherwise, anIllegalStateExceptionis thrown duringMockBean.Builder.build()invocation.- Returns:
- a new builder instance
-
of
A convenient method to create aBeanwith default values (see alsobuilder()). Additionaly, the specified bean types are added to the set of bean types andContextual.create(CreationalContext)will always return the specified bean instance.- Parameters:
beanInstance-beanTypes-- Returns:
- a
MockBeaninstance
-
read
A convenient method to create aMockBean.Builderinitialized from the specified bean class.Note that the container may not be started yet and so it is not possible to use CDI SPI. Instead, we try to simulate the default bean discovery.
By default,
Unmanagedis used to create/destroy the bean instance. However, it is possible to override this behavior.- Parameters:
beanClass-- Returns:
- a new builder instance initialized from the specified bean class
-
create
- Specified by:
createin interfaceContextual<T>
-
destroy
- Specified by:
destroyin interfaceContextual<T>
-
getBeanClass
- Specified by:
getBeanClassin interfaceBean<T>
-
getInjectionPoints
- Specified by:
getInjectionPointsin interfaceBean<T>
-
getTypes
- Specified by:
getTypesin interfaceBeanAttributes<T>
-
getQualifiers
- Specified by:
getQualifiersin interfaceBeanAttributes<T>
-
getScope
- Specified by:
getScopein interfaceBeanAttributes<T>
-
getName
- Specified by:
getNamein interfaceBeanAttributes<T>
-
getStereotypes
- Specified by:
getStereotypesin interfaceBeanAttributes<T>
-
isAlternative
public boolean isAlternative()- Specified by:
isAlternativein interfaceBeanAttributes<T>
-
getId
- Specified by:
getIdin interfacePassivationCapable
-