Search in sources :

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

Example 12 with TestingLoader

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

the class InjectionTest method providesSetConflictsWithProvidesTypeSetValues.

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

        @Provides(type = Provides.Type.SET_VALUES)
        Set<A> provideSetContribution() {
            throw new AssertionError();
        }

        @Provides
        Set<A> provideSet() {
            throw new AssertionError();
        }
    }
    try {
        ObjectGraph.createWith(new TestingLoader(), new TestModule());
        fail();
    } catch (IllegalArgumentException expected) {
    }
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 13 with TestingLoader

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

the class InjectionTest method atInjectAlwaysRequiredForConstruction.

/** https://github.com/square/dagger/issues/231 */
@Test
public void atInjectAlwaysRequiredForConstruction() {
    @Module(injects = ArrayList.class)
    class TestModule {
    }
    ObjectGraph objectGraph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    objectGraph.validate();
    try {
        objectGraph.get(ArrayList.class);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e.getMessage()).contains("Unable to create binding for java.util.ArrayList");
    }
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 14 with TestingLoader

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

the class InjectionTest method providesSetConflictsWithProvidesTypeSet.

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

        @Provides(type = Provides.Type.SET)
        A provideSetElement() {
            throw new AssertionError();
        }

        @Provides
        Set<A> provideSet() {
            throw new AssertionError();
        }
    }
    try {
        ObjectGraph.createWith(new TestingLoader(), new TestModule());
        fail();
    } catch (IllegalArgumentException expected) {
    }
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

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

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