Search in sources :

Example 51 with TestingLoader

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

the class InjectionTest method injectWildcardType.

@Test
public void injectWildcardType() {
    class TestEntryPoint {

        @Inject
        List<? extends Number> listOfNumbers;
    }
    @Module(injects = TestEntryPoint.class)
    class TestModule {

        @Provides
        List<? extends Number> provideList() {
            return Arrays.asList(1, 2);
        }
    }
    try {
        ObjectGraph.createWith(new TestingLoader(), new TestModule());
        fail();
    } catch (UnsupportedOperationException expected) {
    }
}
Also used : TestingLoader(dagger.internal.TestingLoader) AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 52 with TestingLoader

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

the class InjectionTest method getInstanceRequiresEntryPoint.

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

        @Provides
        Integer provideInteger() {
            throw new AssertionError();
        }
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    try {
        graph.get(Integer.class);
        fail();
    } catch (IllegalArgumentException expected) {
    }
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 53 with TestingLoader

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

the class InjectionTest method twoAtInjectConstructorsIsRejected.

@Test
public void twoAtInjectConstructorsIsRejected() {
    @Module(injects = TwoAtInjectConstructors.class)
    class TestModule {

        @Provides
        String provideString() {
            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 54 with TestingLoader

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

the class MembersInjectorTest method rejectUnconstructableSingleton.

@Test
public void rejectUnconstructableSingleton() {
    class TestEntryPoint {

        @Inject
        MembersInjector<UnconstructableSingleton> membersInjector;
    }
    @Module(injects = TestEntryPoint.class)
    class TestModule {
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    try {
        graph.get(TestEntryPoint.class);
        fail();
    } catch (IllegalStateException expected) {
    }
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 55 with TestingLoader

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

the class MembersInjectorTest method injectionOfUnconstructableFails.

@Test
public void injectionOfUnconstructableFails() {
    class TestEntryPoint {

        @Inject
        Unconstructable unconstructable;
    }
    @Module(injects = TestEntryPoint.class)
    class TestModule {
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    try {
        graph.get(TestEntryPoint.class);
        fail();
    } catch (IllegalStateException expected) {
    }
}
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