Package org.jboss.weld.junit
Class MockBean.Builder<T>
java.lang.Object
org.jboss.weld.junit.MockBean.Builder<T>
- Type Parameters:
T-
A builder instance should not be reused nor shared.
- Author:
- Martin Kouba
-
Method Summary
Modifier and TypeMethodDescriptionaddQualifier(Annotation qualifier) addStereotype(Class<? extends Annotation> stereotype) alternative(boolean value) build()create(MockBean.CreateFunction<T> callback) Each invocation ofContextual.create(CreationalContext)will return the same instance.destroy(MockBean.DestroyFunction<T> callback) globallySelectedAlternative(int priority) This beans is a globally enabled alternative with a priority equal to its method parameter.priority(int priority) Programmatic equivalent to to puttingPriorityannotation on a bean class.qualifiers(Annotation... qualifiers) scope(Class<? extends Annotation> scope) The bean is an alternative and should be automatically selected for the synthetic bean archive.selectedAlternative(Class<?> beanClass) The bean has the given bean class, is an alternative and should be automatically selected for the synthetic bean archive.stereotypes(Class<? extends Annotation>... stereotypes) useUnmanaged(Class<T> beanClass) UseUnmanagedto create/destroy the bean instance.
-
Method Details
-
beanClass
- Parameters:
beanClass-- Returns:
- self
- See Also:
-
scope
- Parameters:
scope-- Returns:
- self
- See Also:
-
name
- Parameters:
name-- Returns:
- self
- See Also:
-
types
- Parameters:
types-- Returns:
- self
- See Also:
-
types
- Parameters:
types-- Returns:
- self
-
addType
- Parameters:
type-- Returns:
- self
-
qualifiers
- Parameters:
qualifiers-- Returns:
- self
- See Also:
-
addQualifier
- Parameters:
qualifier-- Returns:
- self
-
alternative
- Parameters:
value-- Returns:
- self
- See Also:
-
priority
Programmatic equivalent to to puttingPriorityannotation on a bean class. Allows for globally enabled alternatives.- Parameters:
priority-- Returns:
- self
- See Also:
-
globallySelectedAlternative
This beans is a globally enabled alternative with a priority equal to its method parameter. Calling this method is a shortcut forpriority(int)andalternative(boolean)- Parameters:
priority-- Returns:
- self
-
selectedAlternative
The bean is an alternative and should be automatically selected for the synthetic bean archive.Users are encouraged to specify
beanClass(Class)when using this method. The bean class is used to determine which alternative beans are selected for a bean archive. By default, all mock beans share the same bean class -org.jboss.weld.junit.WeldCDIExtension.- Returns:
- self
- See Also:
-
selectedAlternative
The bean has the given bean class, is an alternative and should be automatically selected for the synthetic bean archive.- Parameters:
beanClass-- Returns:
- self
- See Also:
-
stereotypes
- Parameters:
stereotypes-- Returns:
- self
- See Also:
-
addStereotype
- Parameters:
stereotype-- Returns:
- self
-
creating
Each invocation ofContextual.create(CreationalContext)will return the same instance.- Parameters:
instance-- Returns:
- self
-
useUnmanaged
UseUnmanagedto create/destroy the bean instance.NOTE:
CreationalContext#toString()is used as a key in a map and therefore must be unique for the lifetime of a bean instance. Weld implementation fulfills this requirement.- Returns:
- self
- See Also:
-
create
- Parameters:
callback-- Returns:
- self
- See Also:
-
destroy
- Parameters:
callback-- Returns:
- self
- See Also:
-
build
- Returns:
- a new
MockBeaninstance - Throws:
IllegalStateException- If a create callback is not set
-