public abstract class TestModule extends AbstractModule
Module
with a bit of syntactic sugar to bind within
typical test scopes. Depends on mockito.
Depends on Mockito.Constructor and Description |
---|
TestModule() |
Modifier and Type | Method and Description |
---|---|
protected <T> void |
bindMany(Class<T> clazz,
Class<? extends T>... boundClasses)
This method binds many different classes to the same interface.
|
protected <T,V extends T> |
bindMany(TypeLiteral<T> type,
TypeLiteral<? extends T>... boundTypes)
This method binds many different type litterals to the same type litteral.
|
protected <T,V extends T> |
bindManyInstances(Class<T> clazz,
V... instances)
This method binds many different instances to the same class or interface.
|
protected <T,V extends T> |
bindManyInstances(TypeLiteral<T> type,
V... instances)
This method binds many different instances to the same type literal.
|
protected <T> ScopedBindingBuilder |
bindMock(Class<T> klass)
Binds an interface to a mocked version of itself.
|
protected <T> ScopedBindingBuilder |
bindMock(TypeLiteral<T> typeLiteral)
Binds an interface annotated with a
@Named to a
mocked version of itself. |
protected <T> LinkedBindingBuilder<T> |
bindNamed(Class<T> klass,
String name)
Binds an interface annotated with a
@Named . |
protected <T> LinkedBindingBuilder<T> |
bindNamed(TypeLiteral<T> typeLiteral,
String name)
Binds an interface annotated with a
@Named . |
protected <T> ScopedBindingBuilder |
bindNamedMock(Class<T> klass,
String name)
Binds an interface annotated with a
@Named to a
mocked version of itself. |
protected <T> ScopedBindingBuilder |
bindNamedMock(TypeLiteral<T> typeLiteral,
String name)
Binds an interface annotated with a
@Named to a
mocked version of itself. |
protected <T> ScopedBindingBuilder |
bindNamedSpy(Class<T> klass,
String name)
Binds a concrete object type annotated with a
@Named so that spies of instances are returned
instead of instances themselves. |
protected <T> ScopedBindingBuilder |
bindNamedSpy(TypeLiteral<T> typeLiteral,
String name)
Binds a concrete object type annotated with a
@Named so that spies of instances are returned
instead of instances themselves. |
protected void |
bindScopes() |
protected <T> ScopedBindingBuilder |
bindSpy(Class<T> klass)
Binds a concrete object type so that spies of instances are returned
instead of instances themselves.
|
protected <T> ScopedBindingBuilder |
bindSpy(TypeLiteral<T> typeLiteral)
Binds a concrete object type so that spies of instances are returned
instead of instances themselves.
|
void |
configure() |
protected abstract void |
configureTest()
Configures a test
Module via the exposed methods. |
void |
setTestClass(Class<?> testClass)
Attach the
TestModule to a given test class. |
addError, addError, addError, bind, bind, bind, bindConstant, binder, bindInterceptor, bindListener, bindScope, configure, convertToTypes, currentStage, getMembersInjector, getMembersInjector, getProvider, getProvider, install, requestInjection, requestStaticInjection, requireBinding, requireBinding
protected Class<?> testClass
public void setTestClass(Class<?> testClass)
TestModule
to a given test class.testClass
- The test class to attach to this TestModule
.public void configure()
configure
in class AbstractModule
protected void bindScopes()
protected abstract void configureTest()
Module
via the exposed methods.protected <T> ScopedBindingBuilder bindMock(Class<T> klass)
TestSingleton
scope.T
- The type of the interface to bindklass
- The class to bindScopedBindingBuilder
.protected <T> ScopedBindingBuilder bindMock(TypeLiteral<T> typeLiteral)
@Named
to a
mocked version of itself. You will usually want to bind this in the
TestSingleton
scope.T
- The type of the interface to bind, a parameterized typetypeLiteral
- The TypeLiteral
corresponding to the parameterized type to bind.ScopedBindingBuilder
.protected <T> ScopedBindingBuilder bindSpy(Class<T> klass)
TestSingleton
scope.T
- The type of the interface to bindklass
- The class to bindScopedBindingBuilder
.protected <T> ScopedBindingBuilder bindSpy(TypeLiteral<T> typeLiteral)
TestSingleton
scope.T
- The type of the interface to bind, a parameterized typetypeLiteral
- The TypeLiteral
corresponding to the parameterized type to bind.ScopedBindingBuilder
.protected <T> ScopedBindingBuilder bindNamedMock(Class<T> klass, String name)
@Named
to a
mocked version of itself. You will usually want to bind this in the
TestSingleton
scope.T
- The type of the interface to bindklass
- The class to bindname
- The name used with the @Named
annotation.ScopedBindingBuilder
.protected <T> ScopedBindingBuilder bindNamedMock(TypeLiteral<T> typeLiteral, String name)
@Named
to a
mocked version of itself. You will usually want to bind this in the
TestSingleton
scope.T
- The type of the interface to bindtypeLiteral
- The TypeLiteral
corresponding to the parameterized type to bind.name
- The name used with the @Named
annotation.ScopedBindingBuilder
.protected <T> ScopedBindingBuilder bindNamedSpy(Class<T> klass, String name)
@Named
so that spies of instances are returned
instead of instances themselves. You will usually want to bind this in the
TestSingleton
scope.T
- The type of the interface to bindklass
- The class to bindname
- The name used with the @Named
annotation.ScopedBindingBuilder
.protected <T> ScopedBindingBuilder bindNamedSpy(TypeLiteral<T> typeLiteral, String name)
@Named
so that spies of instances are returned
instead of instances themselves. You will usually want to bind this in the
TestSingleton
scope.T
- The type of the interface to bindtypeLiteral
- The TypeLiteral
corresponding to the parameterized type to bind.name
- The name used with the @Named
annotation.ScopedBindingBuilder
.protected <T,V extends T> void bindManyInstances(Class<T> clazz, V... instances)
String
or a simple POJO). For more
complex classes use bindMany(java.lang.Class<T>, java.lang.Class<? extends T>...)
.
The specified Class
will be bound to all the different instances, each
binding using a different unique annotation.
This method is useful when combined with the @All
annotation.clazz
- The Class
to which the instances will be bound.instances
- All the instances to bind.protected <T,V extends T> void bindManyInstances(TypeLiteral<T> type, V... instances)
String
or a simple POJO). For more
complex classes use bindMany(java.lang.Class<T>, java.lang.Class<? extends T>...)
.
The specified TypeLiteral
will be bound to all the different instances, each
binding using a different unique annotation.
This method is useful when combined with the @All
annotation.type
- The TypeLiteral
to which the instances will be bound.instances
- All the instances to bind.protected <T> void bindMany(Class<T> clazz, Class<? extends T>... boundClasses)
TestScope.SINGLETON
scope.
This method is useful when combined with the @All
annotation.clazz
- The Class
to which the instances will be bound.boundClasses
- All the classes to bind.protected <T,V extends T> void bindMany(TypeLiteral<T> type, TypeLiteral<? extends T>... boundTypes)
TestScope.SINGLETON
scope.
This method is useful when combined with the @All
annotation.type
- The Class
to which the instances will be bound.boundTypes
- All the types to bind.protected <T> LinkedBindingBuilder<T> bindNamed(Class<T> klass, String name)
@Named
.T
- The type of the interface to bindklass
- The class to bindname
- The name used with the @Named
annotation.ScopedBindingBuilder
.protected <T> LinkedBindingBuilder<T> bindNamed(TypeLiteral<T> typeLiteral, String name)
@Named
.T
- The type of the interface to bindtypeLiteral
- The TypeLiteral
corresponding to the parameterized type to bind.name
- The name used with the @Named
annotation.ScopedBindingBuilder
.Copyright © 2010-2013 ArcBees Inc.. All Rights Reserved.