public abstract class MockHandlerModule extends AbstractModule
HandlerModule
to bind Actions to ActionHandlers and ActionValidators.
You should subclass this module and use the 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 and Description |
---|
MockHandlerModule() |
Modifier and Type | Method and Description |
---|---|
protected <A extends Action<R>,R extends Result,H extends ActionHandler<A,R>> |
bindMockActionHandler(Class<H> handlerClass,
H mockHandler)
Registers a mock server-side action handlers.
|
protected <A extends Action<R>,R extends Result,H extends AbstractClientActionHandler<A,R>> |
bindMockClientActionHandler(Class<A> actionClass,
H mockHandler)
Registers a mock client-side action handlers.
|
protected <A extends Action<R>,R extends Result,H extends ActionHandler<A,R>> |
bindMockHandler(Class<H> handler,
H mockHandler)
Deprecated.
|
protected void |
configure() |
protected abstract void |
configureMockHandlers() |
addError, addError, addError, bind, bind, bind, bindConstant, binder, bindInterceptor, bindListener, bindScope, configure, convertToTypes, currentStage, getMembersInjector, getMembersInjector, getProvider, getProvider, install, requestInjection, requestStaticInjection, requireBinding, requireBinding
protected void configure()
configure
in class AbstractModule
protected 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
ActionHandler
handlerClass
- 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 Action
R
- Type of Result
H
- Type of AbstractClientActionHandler
actionClass
- Implementation of ActionHandler
to link
and bindmockHandler
- Instance of the ActionHandler
to execute
actions of type <A>Copyright © 2010-2014 ArcBees. All Rights Reserved.