In my application I am using a FactoryModuleBuilder to automatically create instances of some class:
new AbstractModule() {
@Override
protected void configure() {
install(new FactoryModuleBuilder().implement(A.class,B.class).build(A.AFactory.class));
}
});
In my test I don't really want to use the implementation (class B) so I would like to configure a module so the factory would return a Mockito mock like this:
new AbstractModule() {
@Override
protected void configure() {
install(new FactoryModuleBuilder().implement(A.class,myMockInstance).build(A.AFactory.class));
}
});
Obviously the above doesn't make sense because implement() tells which implementation is supposed to be used for interface A but I hope it gets my point across that I want the created factory to use my mock object. Then I could use my mock as usual:
Mockito.when(myMockInstance.doStuff()).thenReturn(result);
Is this possible or do I have to create manually a class C implementing A which will act as a mock?