use of android.content.Context in project AndroidTraining by mixi-inc.
the class Proton method initialize.
public static void initialize(Application app, Module... modules) {
synchronized (Proton.class) {
checkState(sInjectors == null, "Already initialized Proton");
sInjectors = new WeakHashMap<Context, InjectorImpl>();
sBindings = new Bindings();
sProviderListeners = new ProviderListeners();
sFieldListeners = new FieldListeners();
for (Module module : modules) module.configure(sBindings, sProviderListeners, sFieldListeners);
InjectorImpl injector = new InjectorImpl(app, sBindings, sProviderListeners, sFieldListeners, null);
sInjectors.put(app, injector);
}
}
use of android.content.Context in project AndroidTraining by mixi-inc.
the class ContextScopedInjectionTest method testInject.
public void testInject() {
Context context1 = new MockContext(mMockApplication);
Client obj1 = Proton.getInjector(context1).inject(new Client());
assertNotNull(obj1.contextScopedClass1);
assertEquals(obj1.contextScopedClass1, obj1.contextScopedClass2);
assertNotNull(obj1.contextScopedClassProvider1);
assertEquals(obj1.contextScopedClassProvider1, obj1.contextScopedClassProvider2);
Client obj2 = Proton.getInjector(context1).inject(new Client());
assertEquals(obj1.contextScopedClass1, obj2.contextScopedClass2);
assertEquals(obj1.contextScopedClassProvider1, obj2.contextScopedClassProvider2);
Client obj3 = Proton.getInjector(new MockContext(mMockApplication)).inject(new Client());
assertNotSame(obj1.contextScopedClass1, obj3.contextScopedClass1);
assertNotSame(obj1.contextScopedClassProvider1, obj3.contextScopedClassProvider1);
}
use of android.content.Context in project AndroidTraining by mixi-inc.
the class ApplicationScopedInjectionTest method testGetInstanceWithIllegalApplicationScoped.
public void testGetInstanceWithIllegalApplicationScoped() {
try {
Context context = new MockContext(mMockApplication);
Proton.getInjector(context).getInstance(IllegalApplicationScopedClass.class);
fail();
} catch (ProvisionException exp) {
}
}
use of android.content.Context in project AndroidTraining by mixi-inc.
the class ApplicationScopedInjectionTest method testGetInstanceWithApplicationScoped.
public void testGetInstanceWithApplicationScoped() {
Context context1 = new MockContext(mMockApplication);
Client c = Proton.getInjector(context1).getInstance(Client.class);
assertNotNull(c.applicationScopedClass);
assertEquals(c.applicationScopedClass, Proton.getInjector(context1).getInstance(ApplicationScopedClass.class));
assertEquals(c.applicationScopedClass, Proton.getInjector(new MockContext(mMockApplication)).getInstance(ApplicationScopedClass.class));
}
use of android.content.Context in project AndroidTraining by mixi-inc.
the class ContextInjectionTest method testGetProvider.
public void testGetProvider() {
Context context = new MockContext(mMockApplication);
Provider<Context> provider1 = Proton.getInjector(context).getProvider(Context.class);
Provider<Context> provider2 = Proton.getInjector(context).getProvider(Context.class);
assertEquals(context, provider1.get());
assertEquals(provider1, provider2);
}
Aggregations