Search in sources :

Example 31 with TestingLoader

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

the class InjectStaticsTest method injectStatics.

@Test
public void injectStatics() {
    @Module(staticInjections = InjectsOneField.class)
    class TestModule {

        @Provides
        String provideString() {
            return "static";
        }
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    assertThat(InjectsOneField.staticField).isNull();
    graph.injectStatics();
    assertThat(InjectsOneField.staticField).isEqualTo("static");
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 32 with TestingLoader

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

the class InjectStaticsTest method instanceFieldsNotInjectedByInjectStatics.

@Test
public void instanceFieldsNotInjectedByInjectStatics() {
    @Module(staticInjections = InjectsStaticAndNonStatic.class, injects = InjectsStaticAndNonStatic.class)
    class TestModule {

        @Provides
        String provideString() {
            return "static";
        }

        @Provides
        Integer provideInteger() {
            throw new AssertionError();
        }
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    assertThat(InjectsStaticAndNonStatic.staticField).isNull();
    graph.injectStatics();
    assertThat(InjectsStaticAndNonStatic.staticField).isEqualTo("static");
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 33 with TestingLoader

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

the class InjectStaticsTest method staticFieldsNotInjectedByInjectMembers.

@Test
public void staticFieldsNotInjectedByInjectMembers() {
    @Module(staticInjections = InjectsStaticAndNonStatic.class, injects = InjectsStaticAndNonStatic.class)
    class TestModule {

        @Provides
        String provideString() {
            throw new AssertionError();
        }

        @Provides
        Integer provideInteger() {
            return 5;
        }
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    assertThat(InjectsStaticAndNonStatic.staticField).isNull();
    InjectsStaticAndNonStatic object = new InjectsStaticAndNonStatic();
    graph.inject(object);
    assertThat(InjectsStaticAndNonStatic.staticField).isNull();
    assertThat(object.nonStaticField).isEqualTo(5);
}
Also used : TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 34 with TestingLoader

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

the class InjectionTest method noProvideBindingsForAbstractClasses.

@Test
public void noProvideBindingsForAbstractClasses() {
    class TestEntryPoint {

        @Inject
        AbstractList abstractList;
    }
    @Module(injects = TestEntryPoint.class)
    class TestModule {
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    try {
        graph.validate();
        fail();
    } catch (IllegalStateException expected) {
    }
}
Also used : AbstractList(java.util.AbstractList) TestingLoader(dagger.internal.TestingLoader) Test(org.junit.Test)

Example 35 with TestingLoader

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

the class SetBindingTest method validateEmptySetBinding.

@Test
public void validateEmptySetBinding() {
    class TestEntryPoint {

        @Inject
        Set<String> strings;
    }
    @Module(injects = TestEntryPoint.class)
    class TestModule {

        @Provides(type = SET_VALUES)
        Set<String> provideDefault() {
            return emptySet();
        }
    }
    ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
    graph.validate();
}
Also used : Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) 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