override production Module

4 views
Skip to first unread message

deanhiller

unread,
Feb 14, 2011, 10:16:28 PM2/14/11
to atunit
I have a production module and would really really love to use the

Module functionalTestModule
= Modules.override(new ProductionModule()).with(new
TestFixtureAModule());

Right now, I see a configure(Binder b) is created when I implement
Module interface but is there a way to implement something else that
return the new functionalTestModule instead back to AtUnit???? this
way I don't have to redefine some of the bindings found in
ProductionModule as there are some wirings that we want from
production and others we want to override.

thanks,
Dean

JasonQR

unread,
Mar 4, 2011, 8:37:27 AM3/4/11
to atunit
Can you get the same behavior by calling
AbstractModule#install(Module) from within your test case's
#configure() method?

deanhiller

unread,
Mar 4, 2011, 10:15:00 AM3/4/11
to atunit
possibly, thanks for the reply. We ended up hacking AtUnit for now
and have our own container...too bad AtUnit doesn't have an annotation
like this one....@Container(GUICE, prodModule=ProductionModule.class)
though so no one would need this

public class UnitGuiceContainer extends GuiceContainer {

@Override
public Object createTest(Class<?> testClass, Map<Field, Object>
fieldValues)
throws Exception {

FieldModule fields = new FieldModule(fieldValues);

Injector injector;
if (Module.class.isAssignableFrom(testClass)) {
Module override = Modules.override(new
ProductionModule()).with(
(Module) testClass.newInstance());
injector = Guice.createInjector(fields, override);
} else {
injector = Guice.createInjector(fields);
}
return injector.getInstance(testClass);
Reply all
Reply to author
Forward
0 new messages