Search in sources :

Example 26 with TestingLoader

use of dagger.internal.TestingLoader in project dagger by square.

the class ModuleTest method childModuleWithEntryPoint.

@Test
public void childModuleWithEntryPoint() {
    @Module(includes = ModuleWithEntryPoint.class)
    class TestModule {

        @Provides
        String provideString() {
            return "injected";
        }
    }
    ObjectGraph objectGraph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    TestEntryPoint entryPoint = objectGraph.get(TestEntryPoint.class);
    assertThat(entryPoint.s).isEqualTo("injected");
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 27 with TestingLoader

use of dagger.internal.TestingLoader in project dagger by square.

the class ModuleTest method childModuleWithBinding.

@Test
public void childModuleWithBinding() {
    @Module(injects = TestEntryPoint.class, includes = ModuleWithBinding.class)
    class TestModule {
    }
    ObjectGraph objectGraph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    TestEntryPoint entryPoint = new TestEntryPoint();
    objectGraph.inject(entryPoint);
    assertThat(entryPoint.s).isEqualTo("injected");
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 28 with TestingLoader

use of dagger.internal.TestingLoader in project dagger by square.

the class ExtensionTest method scopedGraphs.

@Test
public void scopedGraphs() {
    ObjectGraph app = ObjectGraph.createWith(new TestingLoader(), new RootModule());
    assertThat(app.get(A.class)).isNotNull();
    assertThat(app.get(A.class)).isSameAs(app.get(A.class));
    assertThat(app.get(B.class)).isNotSameAs(app.get(B.class));
    assertFailInjectNotRegistered(app, C.class);
    assertFailInjectNotRegistered(app, D.class);
    ObjectGraph request1 = app.plus(new ExtensionModule());
    ObjectGraph request2 = app.plus(new ExtensionModule());
    for (ObjectGraph request : Arrays.asList(request1, request2)) {
        assertThat(request.get(A.class)).isNotNull();
        assertThat(request.get(A.class)).isSameAs(request.get(A.class));
        assertThat(request.get(B.class)).isNotSameAs(request.get(B.class));
        assertThat(request.get(C.class)).isNotNull();
        assertThat(request.get(C.class)).isSameAs(request.get(C.class));
        assertThat(request.get(D.class)).isNotSameAs(request.get(D.class));
    }
    // Singletons are one-per-graph-instance where they are declared.
    assertThat(request1.get(C.class)).isNotSameAs(request2.get(C.class));
    // Singletons that come from common roots should be one-per-common-graph-instance.
    assertThat(request1.get(C.class).a).isSameAs(request2.get(C.class).a);
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 29 with TestingLoader

use of dagger.internal.TestingLoader in project dagger by square.

the class ExtensionWithSetBindingsTest method basicInjectionWithExtension.

@Test
public void basicInjectionWithExtension() {
    ObjectGraph root = ObjectGraph.createWith(new TestingLoader(), new RootModule());
    RealSingleton rs = root.get(RealSingleton.class);
    assertThat(rs.ints).containsExactly(0, 1);
    ObjectGraph extension = root.plus(new ExtensionModule());
    Main main = extension.get(Main.class);
    assertThat(main.ints).containsExactly(0, 1, 2, 3);
    // Second time around.
    ObjectGraph extension2 = root.plus(new ExtensionModule());
    Main main2 = extension2.get(Main.class);
    assertThat(main2.ints).containsExactly(0, 1, 4, 5);
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 30 with TestingLoader

use of dagger.internal.TestingLoader in project dagger by square.

the class InjectStaticsTest method injectStatics.

@Test
public void injectStatics() {
    @Module(staticInjections = InjectsOneField.class)
    class TestModule {

        @Provides
        String provideString() {
            return "static";
        }
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    assertThat(InjectsOneField.staticField).isNull();
    graph.injectStatics();
    assertThat(InjectsOneField.staticField).isEqualTo("static");
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Aggregations

TestingLoader (dagger.internal.TestingLoader)65 Test (org.junit.Test)65 ArrayList (java.util.ArrayList)3 Collections.emptySet (java.util.Collections.emptySet)3 LinkedHashSet (java.util.LinkedHashSet)3 Set (java.util.Set)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AbstractList (java.util.AbstractList)2 Callable (java.util.concurrent.Callable)2 Future (java.util.concurrent.Future)2 List (java.util.List)1 RandomAccess (java.util.RandomAccess)1 Provider (javax.inject.Provider)1