Search in sources :

Example 16 with ObjectGraph

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
    }
}
Also used : ObjectGraph(dagger.ObjectGraph) ObjectGraphService.getObjectGraph(mortar.dagger1support.ObjectGraphService.getObjectGraph) Test(org.junit.Test)

Example 17 with ObjectGraph

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
    }
}
Also used : ObjectGraph(dagger.ObjectGraph) ObjectGraphService.getObjectGraph(mortar.dagger1support.ObjectGraphService.getObjectGraph) Test(org.junit.Test)

Example 18 with ObjectGraph

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);
}
Also used : Context(android.content.Context) ObjectGraph(dagger.ObjectGraph) LinkedList(java.util.LinkedList) MainApplication(com.karumi.rosie.sample.main.MainApplication) Before(org.junit.Before)

Example 19 with ObjectGraph

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();
}
Also used : ObjectGraph(dagger.ObjectGraph)

Aggregations

ObjectGraph (dagger.ObjectGraph)19 Test (org.junit.Test)8 Before (org.junit.Before)7 TestModule (com.tevinjeffrey.rutgersct.TestModule)6 ObjectGraphService.getObjectGraph (mortar.dagger1support.ObjectGraphService.getObjectGraph)6 BaseUnitTest (org.thoughtcrime.securesms.BaseUnitTest)2 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)2 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)2 Context (android.content.Context)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 MainApplication (com.karumi.rosie.sample.main.MainApplication)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 Matchers.anyString (org.mockito.Matchers.anyString)1 NotFoundException (org.whispersystems.signalservice.api.push.exceptions.NotFoundException)1 PushNetworkException (org.whispersystems.signalservice.api.push.exceptions.PushNetworkException)1