use of dagger.internal.TestingLoader in project dagger by square.
the class SetBindingTest method validateLibraryModules_nonLibraryContributors.
@Test
public void validateLibraryModules_nonLibraryContributors() {
class TestEntryPoint {
}
@Module(library = true)
class SetModule1 {
@Provides(type = SET)
public String provideString() {
return "a";
}
}
@Module
class SetModule2 {
@Provides(type = SET)
public String provideString() {
return "b";
}
}
@Module(injects = TestEntryPoint.class, includes = { SetModule1.class, SetModule2.class })
class TestModule {
}
ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new TestModule(), new SetModule1(), new SetModule2());
try {
graph.validate();
fail();
} catch (IllegalStateException expected) {
}
}
use of dagger.internal.TestingLoader in project dagger by square.
the class ThreadSafetyTest method concurrentLazyAccess.
@Test
public void concurrentLazyAccess() throws Exception {
final List<Future<Integer>> futures = new ArrayList<Future<Integer>>();
final ObjectGraph graph = ObjectGraph.createWith(new TestingLoader(), new LatchingModule(latch));
final LazyEntryPoint lep = graph.get(LazyEntryPoint.class);
for (int i = 0; i < THREAD_COUNT; i++) {
futures.add(es.submit(new Callable<Integer>() {
@Override
public Integer call() {
latch.countDown();
return lep.lazy.get();
}
}));
}
latch.countDown();
for (Future<Integer> future : futures) {
assertThat(future.get(1, TimeUnit.SECONDS)).named("Lock failure - count should never increment").isEqualTo(0);
}
}
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 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 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);
}
Aggregations