use of org.apache.cayenne.di.DIRuntimeException in project cayenne by apache.
the class FieldInjectingProvider method injectMember.
private void injectMember(Object object, Field field, String bindingName) {
Object value = value(field, bindingName);
field.setAccessible(true);
try {
field.set(object, value);
} catch (Exception e) {
String message = String.format("Error injecting into field %s.%s of type %s", field.getDeclaringClass().getName(), field.getName(), field.getType().getName());
throw new DIRuntimeException(message, e);
}
}
use of org.apache.cayenne.di.DIRuntimeException in project cayenne by apache.
the class DefaultInjectorCircularInjectionTest method testConstructorInjection_WithFieldInjectionDeps.
@Test
public void testConstructorInjection_WithFieldInjectionDeps() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1_DepOn2Constructor.class);
binder.bind(MockInterface2.class).to(MockImplementation2_I3Dependency.class);
binder.bind(MockInterface3.class).to(MockImplementation3.class);
};
DefaultInjector injector = new DefaultInjector(module);
try {
injector.getInstance(MockInterface1.class);
} catch (DIRuntimeException e) {
fail("Circular dependency is detected incorrectly: " + e.getMessage());
}
}
use of org.apache.cayenne.di.DIRuntimeException 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");
}
}
Aggregations