Search in sources :

Example 21 with TestingLoader

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

the class UnusedProviderTest method unusedProvidesMethod_whenModuleLibrary_passes.

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

        @Provides
        BagOfMoney providesMoney() {
            return new BagOfMoney();
        }
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    graph.validate();
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 22 with TestingLoader

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

the class LazyInjectionTest method getLazyDoesNotCauseProvidesParametersToBeLoaded.

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

        @Provides
        Object provideObject(LazyProvidesParameter parameter) {
            throw new AssertionError();
        }
    }
    ObjectGraph.createWith(new TestingLoader(), new TestModule());
    assertThat(lazyProvidesParameterLoaded).isFalse();
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 23 with TestingLoader

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

the class ModuleTest method moduleExtendingClassThrowsException.

@Test
public void moduleExtendingClassThrowsException() {
    try {
        ObjectGraph.createWith(new TestingLoader(), new ThreadModule());
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage()).startsWith("Modules must not extend from other classes: ");
    }
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 24 with TestingLoader

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

the class ModuleTest method provideRawLazyFails.

@Test
public void provideRawLazyFails() {
    @Module
    class ProvidesRawLazyModule {

        @Provides
        Lazy provideObject() {
            return null;
        }
    }
    try {
        ObjectGraph.createWith(new TestingLoader(), new ProvidesRawLazyModule());
        fail();
    } catch (IllegalStateException e) {
        assertThat(e.getMessage()).startsWith("@Provides method must not return Lazy directly: ");
        assertThat(e.getMessage()).endsWith("ProvidesRawLazyModule.provideObject");
    }
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 25 with TestingLoader

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

the class ModuleTest method childModuleWithStaticInjection.

@Test
public void childModuleWithStaticInjection() {
    @Module(includes = ModuleWithStaticInjection.class)
    class TestModule {

        @Provides
        String provideString() {
            return "injected";
        }
    }
    ObjectGraph objectGraph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    TestStaticInjection.s = null;
    objectGraph.injectStatics();
    assertThat(TestStaticInjection.s).isEqualTo("injected");
}
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