|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.google.inject.AbstractModule
com.gwtplatform.tester.MockHandlerModule
public abstract class MockHandlerModule
Module for use in test cases when creating a guice injector that needs to
provide mock handlers.
Your injector must also have an class that subclasses guice.HandlerModule
to bind Actions to ActionHandlers and ActionValidators.
configureMockHandlers()
method to:
bindMockActionHandler(Class, ActionHandler).bindMockClientActionHandler(Class, AbstractClientActionHandler).
// create mock handlers
CreateFooActionHandler mockCreateFooActionHandler =
mock(CreateFooActionHandler.class);
GeocodeAddressClientActionHandler geocodeAddressClientActionHandler =
mock(GeocodeAddressClientActionHandler.class);
// create injector
Injector injector =
Guice.createInjector(new MyHandlerModule(),
new MockHandlerModule() {
@Override
protected void configureMockHandlers() {
bindMockActionHandler(
CreateFooActionHandler.class,
mockCreateFooActionHandler);
}
bindMockClientActionHandler(
GeocodeAddressAction.class,
geocodeAddressClientActionHandler);
});
// get dispatcher
DispatchAsync dispatcher = injector.getInstance(DispatchAsync.class);
// create mock result
final CreateFooResult result =
new CreateFooResult(new Key(Foo.class, 1));
// configure mockito to return mock result on specific action
when(
businessCreateActionHandler.execute(
eq(new CreateFooAction("Bar")),
any(ExecutionContext.class))).thenReturn(result);
// configuring mockito to return result for clent action handler
// is a bit more complex
final GeocodeAddressResult geocodeAddressResult = new GeocodeAddressResult(...);
doAnswer(new Answer<Object>() {
@SuppressWarnings("unchecked")
public Object answer(InvocationOnMock invocation) {
AsyncCallback<GeocodeAddressResult> callback
= (AsyncCallback<GeocodeAddressResult>) invocation.getArguments()[1];
callback.onSuccess(new GeocodeAddressResult(geocodeAddressResult));
return null;
}
}).when(geocodeAddressClientActionHandler)
.execute(
eq(new GeocodeAddressAction("2 Google Way, New Zealand",
"nz")), any(AsyncCallback.class),
any(ClientDispatchRequest.class), any(ExecuteCommand.class));
| Constructor Summary | |
|---|---|
MockHandlerModule()
|
|
| Method Summary | ||
|---|---|---|
protected
|
bindMockActionHandler(Class<H> handlerClass,
H mockHandler)
Registers a mock server-side action handlers. |
|
protected
|
bindMockClientActionHandler(Class<A> actionClass,
H mockHandler)
Registers a mock client-side action handlers. |
|
protected
|
bindMockHandler(Class<H> handler,
H mockHandler)
Deprecated. |
|
protected void |
configure()
|
|
protected abstract void |
configureMockHandlers()
|
|
| Methods inherited from class com.google.inject.AbstractModule |
|---|
addError, addError, addError, bind, bind, bind, bindConstant, binder, bindInterceptor, bindListener, bindScope, configure, convertToTypes, currentStage, getMembersInjector, getMembersInjector, getProvider, getProvider, install, requestInjection, requestStaticInjection, requireBinding, requireBinding |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MockHandlerModule()
| Method Detail |
|---|
protected void configure()
configure in class AbstractModuleprotected abstract void configureMockHandlers()
@Deprecated
protected <A extends Action<R>,R extends Result,H extends ActionHandler<A,R>> void bindMockHandler(Class<H> handler,
H mockHandler)
protected <A extends Action<R>,R extends Result,H extends ActionHandler<A,R>> void bindMockActionHandler(Class<H> handlerClass,
H mockHandler)
DispatchAsync#execute() or
DispatchAsync#undo().
A - Type of Action that will be executed by mock handlerR - Type of Result that will be returned by mock handlerH - Type of the mock handler that extends
ActionHandlerhandlerClass - The type of the mock server-side handlermockHandler - Instance of the ActionHandler to execute
actions of type <A>
protected <A extends Action<R>,R extends Result,H extends AbstractClientActionHandler<A,R>> void bindMockClientActionHandler(Class<A> actionClass,
H mockHandler)
DispatchAsync#execute() or
DispatchAsync#undo().
If both mock client and mock server action handlers have been registered,
the server side action handler will only be called if the mock client side
action handler calls
ExecuteCommand#execute() or
UndoCommand#undo()
A - Type of ActionR - Type of ResultH - Type of AbstractClientActionHandleractionClass - Implementation of ActionHandler to link
and bindmockHandler - Instance of the ActionHandler to execute
actions of type <A>
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||