Search in sources :

Example 6 with TestingLoader

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

the class SetBindingTest method validateLibraryModules_nonLibraryContributors.

@Test
public void validateLibraryModules_nonLibraryContributors() {
    class TestEntryPoint {
    }
    @Module(library = true)
    class SetModule1 {

        @Provides(type = SET)
        public String provideString() {
            return "a";
        }
    }
    @Module
    class SetModule2 {

        @Provides(type = SET)
        public String provideString() {
            return "b";
        }
    }
    @Module(injects = TestEntryPoint.class, includes = { SetModule1.class, SetModule2.class })
    class TestModule {
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule(), new SetModule1(), new SetModule2());
    try {
        graph.validate();
        fail();
    } catch (IllegalStateException expected) {
    }
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 7 with TestingLoader

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

the class ThreadSafetyTest method concurrentLazyAccess.

@Test
public void concurrentLazyAccess() throws Exception {
    final List<Future<Integer>> futures = new ArrayList<Future<Integer>>();
    final ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new LatchingModule(latch));
    final LazyEntryPoint lep = graph.get(LazyEntryPoint.class);
    for (int i = 0; i < THREAD_COUNT; i++) {
        futures.add(es.submit(new Callable<Integer>() {

            @Override
            public Integer call() {
                latch.countDown();
                return lep.lazy.get();
            }
        }));
    }
    latch.countDown();
    for (Future<Integer> future : futures) {
        assertThat(future.get(1, TimeUnit.SECONDS)).named("Lock failure - count should never increment").isEqualTo(0);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestingLoader(dagger.internal.TestingLoader) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 8 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 9 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 10 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)

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