use of dagger.ObjectGraph in project mortar by square.
the class ObjectGraphServiceTest method getActivityScopeWithMoreModules.
@Test
public void getActivityScopeWithMoreModules() {
MortarScope root = createRootScope(ObjectGraph.create(new AppleModule()));
MortarScope activityScope = root.buildChild().withService(SERVICE_NAME, create(root, new DogfoodModule(), new EggplanModule())).build("moar");
ObjectGraph objectGraph = getObjectGraph(activityScope);
assertThat(objectGraph.get(HasApple.class).string).isEqualTo(Apple.class.getName());
assertThat(objectGraph.get(HasDogfood.class).string).isEqualTo(Dogfood.class.getName());
assertThat(objectGraph.get(HasEggplant.class).string).isEqualTo(Eggplant.class.getName());
try {
objectGraph.get(HasCarrot.class);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// pass
}
}
use of dagger.ObjectGraph in project mortar by square.
the class ObjectGraphServiceTest method requireGrandchildWithOneModule.
@Test
public void requireGrandchildWithOneModule() {
MortarScope root = createRootScope(ObjectGraph.create(new AppleModule()));
MortarScope activityScope = root.buildChild().withService(SERVICE_NAME, create(root, new BagelModule())).build("activity");
MortarScope child = activityScope.buildChild().withService(SERVICE_NAME, create(activityScope, new CarrotModule())).build("child");
MortarScope grandchild = child.buildChild().withService(SERVICE_NAME, create(child, new DogfoodModule())).build("grandchild");
ObjectGraph objectGraph = getObjectGraph(grandchild);
assertThat(objectGraph.get(HasApple.class).string).isEqualTo(Apple.class.getName());
assertThat(objectGraph.get(HasBagel.class).string).isEqualTo(Bagel.class.getName());
assertThat(objectGraph.get(HasCarrot.class).string).isEqualTo(Carrot.class.getName());
assertThat(objectGraph.get(HasDogfood.class).string).isEqualTo(Dogfood.class.getName());
try {
objectGraph.get(HasEggplant.class);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// pass
}
}
use of dagger.ObjectGraph in project Rosie by Karumi.
the class InjectedInstrumentationTest method setUp.
@Before
public void setUp() {
MainApplication application = getApplication();
List<Object> childTestModules = getTestModules();
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
List<Object> testModules = new LinkedList<>(childTestModules);
testModules.add(new BaseTestModule(context));
ObjectGraph objectGraph = application.plusGraph(testModules);
application.replaceGraph(objectGraph);
objectGraph.inject(this);
}
use of dagger.ObjectGraph in project dagger by square.
the class TestApp method main.
public static void main(String[] args) {
ObjectGraph root = ObjectGraph.create(new RootModule(), new ContributingModule());
root.get(TestApp.class).run();
}
Aggregations