use of org.apache.cayenne.di.mock.MockInterface2 in project cayenne by apache.
the class DefaultInjectorCircularInjectionTest method testConstructorInjection_CircularDependency.
@Test
public void testConstructorInjection_CircularDependency() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1_DepOn2Constructor.class);
binder.bind(MockInterface2.class).to(MockImplementation2_Constructor.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.MockInterface2 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testFieldInjectionSuperclass.
@Test
public void testFieldInjectionSuperclass() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1.class);
binder.bind(MockInterface2.class).to(MockImplementation2Sub1.class);
binder.bind(MockInterface3.class).to(MockImplementation3.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface2 service = injector.getInstance(MockInterface2.class);
assertNotNull(service);
assertEquals("altered_MyName:XName", service.getAlteredName());
}
use of org.apache.cayenne.di.mock.MockInterface2 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testFieldInjection_Named.
@Test
public void testFieldInjection_Named() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1.class);
binder.bind(Key.get(MockInterface1.class, "one")).to(MockImplementation1Alt.class);
binder.bind(Key.get(MockInterface1.class, "two")).to(MockImplementation1Alt2.class);
binder.bind(MockInterface2.class).to(MockImplementation2_Named.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface2 service = injector.getInstance(MockInterface2.class);
assertNotNull(service);
assertEquals("altered_alt", service.getAlteredName());
}
use of org.apache.cayenne.di.mock.MockInterface2 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testProviderInjection_Constructor.
@Test
public void testProviderInjection_Constructor() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1.class);
binder.bind(MockInterface2.class).to(MockImplementation2_ConstructorProvider.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface2 service = injector.getInstance(MockInterface2.class);
assertEquals("altered_MyName", service.getAlteredName());
}
Aggregations