use of com.google.inject.AbstractModule in project scdl by passy.
the class AboutActivityTest method setup.
@Before
public void setup() {
final PackageInfo fakeInfo = new PackageInfo();
fakeInfo.versionName = "1.0.1";
TestHelper.overridenInjector(this, new AbstractModule() {
@Override
protected void configure() {
bind(PackageInfo.class).toInstance(fakeInfo);
}
});
}
use of com.google.inject.AbstractModule in project scdl by passy.
the class TestHelper method overridenInjector.
public static void overridenInjector(Object instance, AbstractModule module) {
final Application app = Robolectric.application;
// Allow overriding of integrated classes like Activity
Module moduleOverride = Modules.override(RoboGuice.newDefaultRoboModule(app)).with(module);
// Also allow overriding custom bindings like URLWrapper
moduleOverride = Modules.override(new SCDLModule()).with(moduleOverride);
RoboGuice.setBaseApplicationInjector(app, RoboGuice.DEFAULT_STAGE, moduleOverride);
final Injector injector = TestHelper.getInjector();
injector.injectMembers(instance);
}
use of com.google.inject.AbstractModule in project scdl by passy.
the class ResolveServiceTest method setUp.
@Before
public void setUp() {
final AbstractModule module = new AbstractModule() {
@Override
protected void configure() {
mUrlConnectionFactory = new FakeURLConnectionFactoryImpl("/fixtures/resolve.json");
mUrlConnectionFactory.setResponseCode(302);
bind(URLConnectionFactory.class).toInstance(mUrlConnectionFactory);
bind(PinningTrustManager.class).toInstance(new TrustManagerStub());
}
};
TestHelper.overridenInjector(this, module);
}
use of com.google.inject.AbstractModule in project roboguice by roboguice.
the class MapBinderTest method testMapBinderMultimapWithAnotation.
public void testMapBinderMultimapWithAnotation() {
AbstractModule ab1 = new AbstractModule() {
@Override
protected void configure() {
MapBinder<String, String> multibinder = MapBinder.newMapBinder(binder(), String.class, String.class, Abc.class);
multibinder.addBinding("a").toInstance("A");
multibinder.addBinding("b").toInstance("B1");
}
};
AbstractModule b2c = new AbstractModule() {
@Override
protected void configure() {
MapBinder<String, String> multibinder = MapBinder.newMapBinder(binder(), String.class, String.class, Abc.class);
multibinder.addBinding("b").toInstance("B2");
multibinder.addBinding("c").toInstance("C");
multibinder.permitDuplicates();
}
};
Injector injector = Guice.createInjector(ab1, b2c);
assertEquals(mapOf("a", setOf("A"), "b", setOf("B1", "B2"), "c", setOf("C")), injector.getInstance(Key.get(mapOfSetOfString, Abc.class)));
try {
injector.getInstance(Key.get(mapOfSetOfString));
fail();
} catch (ConfigurationException expected) {
}
assertMapVisitor(Key.get(mapOfString, Abc.class), stringType, stringType, setOf(ab1, b2c), BOTH, true, 0, instance("a", "A"), instance("b", "B1"), instance("b", "B2"), instance("c", "C"));
}
use of com.google.inject.AbstractModule in project roboguice by roboguice.
the class MapBinderTest method testMapBinderMapIsLazy.
public void testMapBinderMapIsLazy() {
Module module = new AbstractModule() {
@Override
protected void configure() {
MapBinder.newMapBinder(binder(), String.class, Integer.class).addBinding("num").toProvider(new Provider<Integer>() {
int nextValue = 1;
@Override
public Integer get() {
return nextValue++;
}
});
}
};
Injector injector = Guice.createInjector(module);
assertEquals(mapOf("num", 1), injector.getInstance(Key.get(mapOfInteger)));
assertEquals(mapOf("num", 2), injector.getInstance(Key.get(mapOfInteger)));
assertEquals(mapOf("num", 3), injector.getInstance(Key.get(mapOfInteger)));
assertMapVisitor(Key.get(mapOfInteger), stringType, intType, setOf(module), BOTH, false, 0, providerInstance("num", 1));
}
Aggregations