Search in sources :

Example 1 with TestingLoader

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

the class ExtensionWithSetBindingsTest method duplicateBindingsInSecondaryModule.

@Test
public void duplicateBindingsInSecondaryModule() {
    try {
        ObjectGraph.createWith(new TestingLoader(), new EmptyModule(), new DuplicateModule());
        fail("Should throw exception.");
    } catch (IllegalArgumentException e) {
        assertTrue(e.getMessage().startsWith("DuplicateModule: Duplicate"));
    }
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 2 with TestingLoader

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

the class ExtensionTest method basicInjection.

@Test
public void basicInjection() {
    ObjectGraph root = ObjectGraph.createWith(new TestingLoader(), new RootModule());
    assertThat(root.get(A.class)).isNotNull();
    // Present and Singleton.
    assertThat(root.get(A.class)).isSameAs(root.get(A.class));
    // Not singleton.
    assertThat(root.get(B.class)).isNotSameAs(root.get(B.class));
    // Not declared in RootModule.
    assertFailInjectNotRegistered(root, C.class);
    // Not declared in RootModule.
    assertFailInjectNotRegistered(root, D.class);
    // Extension graph behaves as the root graph would for root-ish things.
    ObjectGraph extension = root.plus(new ExtensionModule());
    assertThat(root.get(A.class)).isSameAs(extension.get(A.class));
    assertThat(root.get(B.class)).isNotSameAs(extension.get(B.class));
    assertThat(root.get(B.class).a).isSameAs(extension.get(B.class).a);
    assertThat(extension.get(C.class).a).isNotNull();
    assertThat(extension.get(D.class).c).isNotNull();
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 3 with TestingLoader

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

the class ExtensionWithStateTest method basicInjectionWithExtension.

@Test
public void basicInjectionWithExtension() {
    A a = new A();
    ObjectGraph root = ObjectGraph.createWith(new TestingLoader(), new RootModule(a));
    assertThat(root.get(A.class)).isSameAs(a);
    // Extension graph behaves as the root graph would for root-ish things.
    ObjectGraph extension = root.plus(new ExtensionModule());
    assertThat(extension.get(A.class)).isSameAs(a);
    assertThat(extension.get(B.class).a).isSameAs(a);
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 4 with TestingLoader

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

the class InjectionTest method noJitBindingsForInterfaces.

@Test
public void noJitBindingsForInterfaces() {
    class TestEntryPoint {

        @Inject
        RandomAccess randomAccess;
    }
    @Module(injects = TestEntryPoint.class)
    class TestModule {
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    try {
        graph.validate();
        fail();
    } catch (IllegalStateException expected) {
    }
}
Also used : TestingLoader(dagger.internal.TestingLoader) RandomAccess(java.util.RandomAccess) Test(org.junit.Test)

Example 5 with TestingLoader

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

the class InjectionTest method nonEntryPointNeedsInjectAnnotation.

@Test
public void nonEntryPointNeedsInjectAnnotation() {
    @Module
    class TestModule {

        @Provides
        String provideString(NoInjections noInjections) {
            throw new AssertionError();
        }
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    try {
        graph.validate();
        fail();
    } catch (IllegalStateException expected) {
    }
}
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