Hi Philippe.
Thanks a lot for the tip, it definitely helped me getting around the
new concepts behind Jukito.
I spent some trying to combine the use of Jukito's JukitoModule and
GWTP's MockHandlerModule.
Basically my issue was that I wanted my DispatchAsyncStub to take a
MockHandlerModule as a constructor's argument, so I needed
MockHandlerModule to be injected.
public class DispatchAsyncStub implements DispatchAsync {
private DispatchAsync dispatch;
@Inject
public DispatchAsyncStub(final MockHandlerModule mockHandlerModule) {
dispatch = Guice.createInjector(new DispatchModule(), new
ServerHandlerModule(),
mockHandlerModule).getInstance(DispatchAsync.class);
}
}
I wanted the above implementation of DispatchAsyncStub in order to
reuse it across various test units. But the server action handlers to
be bound would change from test unit to test unit, so I needed the
flexibility to pass a dedicated MockHandlerModule each time.
Then my JukitoModule looks something like this:
public static class Module extends JukitoModule {
private final ActionHandler actionHandler =
mock(ActionHandler.class);
@Provides
protected MockHandlerModule createMockHandlerModule() {
return new MockHandlerModule() {
@Override
protected void configureMockHandlers() {
bindMockActionHandler(ActionHandler.class, actionHandler);
}
};
}
@Provides
protected ActionHandler createLoginHandler() {
return actionHandler;
}
}
... where there is this one mock (actionHandler) that I have to
explicitly mock via the original Mockito function. This is because I
need to manipulate it already inside the JukitoModule. And that is
because the provider for MockHandlerModule is a method of the
JukitoModule.
Then obviously ActionHandler can be injected anywhere I want,
including inside the setup routine (@Before) in order to stub it. This
injection occurs smoothly thanks to the provider method that creates
the right one each time it's injected. The right one being the one
that was bound through bindMockActionHandler (whew.)
Well if you got some time to get into my post I'd be happy to know
whether this is the way to go, otherwise, hopefully, this will help
others during their first steps with Jukito.
Thumbs up for this new tool!
Luc
On Apr 24, 6:28 pm, Philippe Beaudoin <
philippe.beaud...@gmail.com>
wrote: