Search in sources :

Example 36 with TestingLoader

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

the class SetBindingTest method validateSetBinding.

@Test
public void validateSetBinding() {
    class TestEntryPoint {

        @Inject
        Set<String> strings;
    }
    @Module(injects = TestEntryPoint.class)
    class TestModule {

        @Provides(type = SET)
        String provideString1() {
            return "string1";
        }

        @Provides(type = SET)
        String provideString2() {
            return "string2";
        }
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    graph.validate();
}
Also used : Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 37 with TestingLoader

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

the class SetBindingTest method validateLibraryModules.

@Test
public void validateLibraryModules() {
    class TestEntryPoint {
    }
    @Module(library = true)
    class SetModule {

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

Example 38 with TestingLoader

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

the class ThreadSafetyTest method concurrentSingletonAccess.

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

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

Example 39 with TestingLoader

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

the class UnusedProviderTest method unusedSetValuesBinding.

@Test
public void unusedSetValuesBinding() throws Exception {
    @Module
    class TestModule {

        @Provides(type = Provides.Type.SET_VALUES)
        Set<String> provideA() {
            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)

Example 40 with TestingLoader

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

the class UnusedProviderTest method whenLibraryModulePlussedToNecessaryModule_shouldNotFailOnUnusedLibraryModule.

@Test
public void whenLibraryModulePlussedToNecessaryModule_shouldNotFailOnUnusedLibraryModule() throws Exception {
    class EntryPoint {
    }
    class BagOfMoney {
    }
    @Module(injects = EntryPoint.class, library = true)
    class ExampleLibraryModule {

        @Provides
        BagOfMoney providesMoney() {
            return new BagOfMoney();
        }
    }
    @Module(injects = EntryPoint.class)
    class TestModule {
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    graph = graph.plus(new ExampleLibraryModule());
    graph.validate();
}
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