use of org.apache.cayenne.di.mock.MockImplementation2 in project cayenne by apache.
the class DefaultInjectorCircularInjectionTest method testFieldInjection_CircularDependency.
@Test
public void testFieldInjection_CircularDependency() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1_DepOn2.class);
binder.bind(MockInterface2.class).to(MockImplementation2.class);
};
DefaultInjector injector = new DefaultInjector(module);
try {
injector.getInstance(MockInterface1.class);
fail("Circular dependency is not detected.");
} catch (DIRuntimeException e) {
// expected
} catch (StackOverflowError e) {
fail("Circular dependency is not detected, causing stack overflow");
}
}
use of org.apache.cayenne.di.mock.MockImplementation2 in project cayenne by apache.
the class DefaultInjectorCircularInjectionTest method testProviderInjection_CircularDependency.
@Test
public void testProviderInjection_CircularDependency() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1_DepOn2Provider.class);
binder.bind(MockInterface2.class).to(MockImplementation2.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface1 service = injector.getInstance(MockInterface1.class);
assertEquals("MockImplementation2Name", service.getName());
}
use of org.apache.cayenne.di.mock.MockImplementation2 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testFieldInjection.
@Test
public void testFieldInjection() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1.class);
binder.bind(MockInterface2.class).to(MockImplementation2.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface2 service = injector.getInstance(MockInterface2.class);
assertNotNull(service);
assertEquals("altered_MyName", service.getAlteredName());
}
Aggregations