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");
}
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");
}
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);
}
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) {
}
}
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();
}
Aggregations