use of dagger.internal.TestingLoader in project dagger by square.
the class InjectionTest method privateFieldsFail.
@Test
public void privateFieldsFail() {
class Test {
@Inject
private Object nope;
}
@Module(injects = Test.class)
class TestModule {
@Provides
Object provideObject() {
return null;
}
}
try {
ObjectGraph.createWith(new TestingLoader(), new TestModule()).inject(new Test());
fail();
} catch (IllegalStateException e) {
assertThat(e.getMessage()).contains("Can't inject private field: ");
}
}
use of dagger.internal.TestingLoader in project dagger by square.
the class InjectionTest method getInstance.
@Test
public void getInstance() {
final AtomicInteger next = new AtomicInteger(0);
@Module(injects = Integer.class)
class TestModule {
@Provides
Integer provideInteger() {
return next.getAndIncrement();
}
}
ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
assertThat((int) graph.get(Integer.class)).isEqualTo(0);
assertThat((int) graph.get(Integer.class)).isEqualTo(1);
}
use of dagger.internal.TestingLoader in project dagger by square.
the class InjectionTest method testSingletonLinkingThroughExtensionGraph.
@Test
public void testSingletonLinkingThroughExtensionGraph() {
ObjectGraph root = ObjectGraph.createWith(new TestingLoader(), new RootModule());
// DO NOT CALL root.get(C.class)) HERE to get forced-linking behaviour from plus();
ObjectGraph extension = root.plus(new ExtensionModule());
assertThat(extension.get(SingletonLinkedFromExtension.class).c).isSameAs(root.get(C.class));
}
use of dagger.internal.TestingLoader in project dagger by square.
the class InjectionTest method noConstructorInjectionsForClassesWithTypeParameters.
@Test
public void noConstructorInjectionsForClassesWithTypeParameters() {
class TestEntryPoint {
@Inject
Parameterized<Long> parameterized;
}
@Module(injects = TestEntryPoint.class)
class TestModule {
@Provides
String provideString() {
return "injected";
}
}
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 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) {
}
}
Aggregations