Search in sources :

Example 16 with TestingLoader

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

the class InjectionTest method getInstanceOfPrimitive.

@Test
public void getInstanceOfPrimitive() {
    @Module(injects = int.class)
    class TestModule {

        @Provides
        int provideInt() {
            return 1;
        }
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    assertEquals(1, (int) graph.get(int.class));
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 17 with TestingLoader

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

the class InjectionTest method getInstanceOfArray.

@Test
public void getInstanceOfArray() {
    @Module(injects = int[].class)
    class TestModule {

        @Provides
        int[] provideIntArray() {
            return new int[] { 1, 2, 3 };
        }
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    assertEquals("[1, 2, 3]", Arrays.toString(graph.get(int[].class)));
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 18 with TestingLoader

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

the class InjectionTest method objectGraphGetInterface.

@Test
public void objectGraphGetInterface() {
    final Runnable runnable = new Runnable() {

        @Override
        public void run() {
        }
    };
    @Module(injects = Runnable.class)
    class TestModule {

        @Provides
        Runnable provideRunnable() {
            return runnable;
        }
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    graph.validate();
    assertThat(graph.get(Runnable.class)).isSameAs(runnable);
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 19 with TestingLoader

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

the class InjectionTest method providerMethodsConflict.

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

        @Provides
        A provideA1() {
            throw new AssertionError();
        }

        @Provides
        A provideA2() {
            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 20 with TestingLoader

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

the class LazyInjectionTest method getLazyDoesNotCauseProvidesResultToBeLoaded.

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

        @Provides
        LazyProvidesResult provideLazy() {
            throw new AssertionError();
        }
    }
    ObjectGraph.createWith(new TestingLoader(), new TestModule());
    assertThat(lazyProvidesResultLoaded).isFalse();
}
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