T - public class MockBean<T> extends Object implements javax.enterprise.inject.spi.Bean<T>, javax.enterprise.inject.spi.PassivationCapable
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.
WeldInitiator.Builder#addBean(Bean)| Modifier and Type | Class and Description |
|---|---|
static class |
MockBean.Builder<T>
A builder instance should not be reused nor shared.
|
static interface |
MockBean.CreateFunction<T> |
static interface |
MockBean.DestroyFunction<T> |
| Modifier and Type | Method and Description |
|---|---|
static <T> MockBean.Builder<T> |
builder()
By default, the bean:
has no name
has
Dependent scope
has Any qualifier and Default is added automatically if no other qualifiers are set
has Object bean type
has no stereotypes
is not an alternative
|
T |
create(javax.enterprise.context.spi.CreationalContext<T> creationalContext) |
void |
destroy(T instance,
javax.enterprise.context.spi.CreationalContext<T> creationalContext) |
Class<?> |
getBeanClass() |
String |
getId() |
Set<javax.enterprise.inject.spi.InjectionPoint> |
getInjectionPoints() |
String |
getName() |
Set<Annotation> |
getQualifiers() |
Class<? extends Annotation> |
getScope() |
Set<Class<? extends Annotation>> |
getStereotypes() |
Set<Type> |
getTypes() |
boolean |
isAlternative() |
boolean |
isNullable() |
static <T> javax.enterprise.inject.spi.Bean<T> |
of(T beanInstance,
Type... beanTypes)
A convenient method to create a
Bean with default values (see also builder()). |
static <T> MockBean.Builder<T> |
read(Class<T> beanClass)
A convenient method to create a
MockBean.Builder initialized from the specified bean class. |
public static <T> MockBean.Builder<T> builder()
Dependent scopeAny qualifier and Default is added automatically if no other qualifiers are setObject bean type
Note that MockBean.Builder.creating(Object) or Builder#create(CreateFunction) must be always set. Otherwise, an IllegalStateException is
thrown during MockBean.Builder.build() invocation.
public static <T> javax.enterprise.inject.spi.Bean<T> of(T beanInstance,
Type... beanTypes)
Bean with default values (see also builder()). Additionaly, the specified bean types are added to the
set of bean types and Contextual.create(CreationalContext) will always return the specified bean instance.beanInstance - beanTypes - MockBean instancepublic static <T> MockBean.Builder<T> read(Class<T> beanClass)
MockBean.Builder initialized 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, Unmanaged is used to create/destroy the bean instance. However, it is possible to override this behavior.
beanClass - public T create(javax.enterprise.context.spi.CreationalContext<T> creationalContext)
create in interface javax.enterprise.context.spi.Contextual<T>public void destroy(T instance, javax.enterprise.context.spi.CreationalContext<T> creationalContext)
destroy in interface javax.enterprise.context.spi.Contextual<T>public Class<?> getBeanClass()
getBeanClass in interface javax.enterprise.inject.spi.Bean<T>public Set<javax.enterprise.inject.spi.InjectionPoint> getInjectionPoints()
getInjectionPoints in interface javax.enterprise.inject.spi.Bean<T>public boolean isNullable()
isNullable in interface javax.enterprise.inject.spi.Bean<T>public Set<Type> getTypes()
getTypes in interface javax.enterprise.inject.spi.BeanAttributes<T>public Set<Annotation> getQualifiers()
getQualifiers in interface javax.enterprise.inject.spi.BeanAttributes<T>public Class<? extends Annotation> getScope()
getScope in interface javax.enterprise.inject.spi.BeanAttributes<T>public String getName()
getName in interface javax.enterprise.inject.spi.BeanAttributes<T>public Set<Class<? extends Annotation>> getStereotypes()
getStereotypes in interface javax.enterprise.inject.spi.BeanAttributes<T>public boolean isAlternative()
isAlternative in interface javax.enterprise.inject.spi.BeanAttributes<T>public String getId()
getId in interface javax.enterprise.inject.spi.PassivationCapableCopyright © 2018. All rights reserved.