Search in sources :

Example 61 with TestingLoader

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

the class UnusedProviderTest method unusedSetBinding.

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

        @Provides(type = Provides.Type.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 62 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 63 with TestingLoader

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

the class UnusedProviderTest method unusedProviderMethod_whenNotLibraryModule_fails.

@Test
public void unusedProviderMethod_whenNotLibraryModule_fails() throws Exception {
    class EntryPoint {
    }
    class BagOfMoney {
    }
    @Module(injects = EntryPoint.class)
    class TestModule {

        @Provides
        BagOfMoney providesMoney() {
            return new BagOfMoney();
        }
    }
    try {
        ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
        graph.validate();
        fail("Validation should have exploded!");
    } catch (IllegalStateException expected) {
    }
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 64 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)

Example 65 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)

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