use of dagger.internal.TestingLoader in project dagger by square.
the class ModuleTest method childModuleWithEntryPoint.
@Test
public void childModuleWithEntryPoint() {
@Module(includes = ModuleWithEntryPoint.class)
class TestModule {
@Provides
String provideString() {
return "injected";
}
}
ObjectGraph objectGraph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
TestEntryPoint entryPoint = objectGraph.get(TestEntryPoint.class);
assertThat(entryPoint.s).isEqualTo("injected");
}
use of dagger.internal.TestingLoader in project dagger by square.
the class ModuleTest method childModuleWithBinding.
@Test
public void childModuleWithBinding() {
@Module(injects = TestEntryPoint.class, includes = ModuleWithBinding.class)
class TestModule {
}
ObjectGraph objectGraph = ObjectGraph.createWith(new TestingLoader(), new TestModule());
TestEntryPoint entryPoint = new TestEntryPoint();
objectGraph.inject(entryPoint);
assertThat(entryPoint.s).isEqualTo("injected");
}
use of dagger.internal.TestingLoader in project dagger by square.
the class ExtensionTest method scopedGraphs.
@Test
public void scopedGraphs() {
ObjectGraph app = ObjectGraph.createWith(new TestingLoader(), new RootModule());
assertThat(app.get(A.class)).isNotNull();
assertThat(app.get(A.class)).isSameAs(app.get(A.class));
assertThat(app.get(B.class)).isNotSameAs(app.get(B.class));
assertFailInjectNotRegistered(app, C.class);
assertFailInjectNotRegistered(app, D.class);
ObjectGraph request1 = app.plus(new ExtensionModule());
ObjectGraph request2 = app.plus(new ExtensionModule());
for (ObjectGraph request : Arrays.asList(request1, request2)) {
assertThat(request.get(A.class)).isNotNull();
assertThat(request.get(A.class)).isSameAs(request.get(A.class));
assertThat(request.get(B.class)).isNotSameAs(request.get(B.class));
assertThat(request.get(C.class)).isNotNull();
assertThat(request.get(C.class)).isSameAs(request.get(C.class));
assertThat(request.get(D.class)).isNotSameAs(request.get(D.class));
}
// Singletons are one-per-graph-instance where they are declared.
assertThat(request1.get(C.class)).isNotSameAs(request2.get(C.class));
// Singletons that come from common roots should be one-per-common-graph-instance.
assertThat(request1.get(C.class).a).isSameAs(request2.get(C.class).a);
}
use of dagger.internal.TestingLoader in project dagger by square.
the class ExtensionWithSetBindingsTest method basicInjectionWithExtension.
@Test
public void basicInjectionWithExtension() {
ObjectGraph root = ObjectGraph.createWith(new TestingLoader(), new RootModule());
RealSingleton rs = root.get(RealSingleton.class);
assertThat(rs.ints).containsExactly(0, 1);
ObjectGraph extension = root.plus(new ExtensionModule());
Main main = extension.get(Main.class);
assertThat(main.ints).containsExactly(0, 1, 2, 3);
// Second time around.
ObjectGraph extension2 = root.plus(new ExtensionModule());
Main main2 = extension2.get(Main.class);
assertThat(main2.ints).containsExactly(0, 1, 4, 5);
}
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");
}
Aggregations