use of dagger.internal.TestingLoader in project dagger by square.
the class ExtensionWithSetBindingsTest method duplicateBindingsInSecondaryModule.
@Test
public void duplicateBindingsInSecondaryModule() {
try {
ObjectGraph.createWith(new TestingLoader(), new EmptyModule(), new DuplicateModule());
fail("Should throw exception.");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().startsWith("DuplicateModule: Duplicate"));
}
}
use of dagger.internal.TestingLoader in project dagger by square.
the class ExtensionTest method basicInjection.
@Test
public void basicInjection() {
ObjectGraph root = ObjectGraph.createWith(new TestingLoader(), new RootModule());
assertThat(root.get(A.class)).isNotNull();
// Present and Singleton.
assertThat(root.get(A.class)).isSameAs(root.get(A.class));
// Not singleton.
assertThat(root.get(B.class)).isNotSameAs(root.get(B.class));
// Not declared in RootModule.
assertFailInjectNotRegistered(root, C.class);
// Not declared in RootModule.
assertFailInjectNotRegistered(root, D.class);
// Extension graph behaves as the root graph would for root-ish things.
ObjectGraph extension = root.plus(new ExtensionModule());
assertThat(root.get(A.class)).isSameAs(extension.get(A.class));
assertThat(root.get(B.class)).isNotSameAs(extension.get(B.class));
assertThat(root.get(B.class).a).isSameAs(extension.get(B.class).a);
assertThat(extension.get(C.class).a).isNotNull();
assertThat(extension.get(D.class).c).isNotNull();
}
use of dagger.internal.TestingLoader in project dagger by square.
the class ExtensionWithStateTest method basicInjectionWithExtension.
@Test
public void basicInjectionWithExtension() {
A a = new A();
ObjectGraph root = ObjectGraph.createWith(new TestingLoader(), new RootModule(a));
assertThat(root.get(A.class)).isSameAs(a);
// Extension graph behaves as the root graph would for root-ish things.
ObjectGraph extension = root.plus(new ExtensionModule());
assertThat(extension.get(A.class)).isSameAs(a);
assertThat(extension.get(B.class).a).isSameAs(a);
}
use of dagger.internal.TestingLoader in project dagger by square.
the class InjectionTest method noJitBindingsForInterfaces.
@Test
public void noJitBindingsForInterfaces() {
class TestEntryPoint {
@Inject
RandomAccess randomAccess;
}
@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 InjectionTest method nonEntryPointNeedsInjectAnnotation.
@Test
public void nonEntryPointNeedsInjectAnnotation() {
@Module
class TestModule {
@Provides
String provideString(NoInjections noInjections) {
throw new AssertionError();
}
}
ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
try {
graph.validate();
fail();
} catch (IllegalStateException expected) {
}
}
Aggregations