use of org.apache.cayenne.di.mock.MockInterface2 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.MockInterface2 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.MockInterface2 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testTypedListInjection.
@Test
public void testTypedListInjection() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1_ListConfigurationMock5.class);
binder.bind(MockInterface2.class).to(MockImplementation2_ListConfiguration.class);
// Bind list for MockImplementation2_ListConfiguration
binder.bindList(Object.class, "xyz").add("xvalue").add("yvalue").add(MockImplementation5.class);
// Bind list for MockImplementation1_ListConfigurationMock5
binder.bindList(MockInterface5.class).add(MockImplementation5.class).add(new MockInterface5() {
@Override
public String toString() {
return "abc";
}
});
binder.bindList(Object.class).add("avalue").add("bvalue").add(MockImplementation5.class);
// Add to list for MockImplementation1_ListConfigurationMock5
binder.bindList(MockInterface5.class).add(new MockInterface5() {
@Override
public String toString() {
return "cde";
}
});
// Create named list for MockInterface5
binder.bindList(MockInterface5.class, "another_binding").add(new MockInterface5() {
@Override
public String toString() {
return "fgh";
}
});
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface1 service = injector.getInstance(MockInterface1.class);
assertNotNull(service);
assertEquals(";xyz;abc;cde", service.getName());
MockInterface2 service2 = injector.getInstance(MockInterface2.class);
assertNotNull(service2);
assertTrue(service2 instanceof MockImplementation2_ListConfiguration);
assertEquals(";xvalue;yvalue;xyz", service2.getName());
}
use of org.apache.cayenne.di.mock.MockInterface2 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());
}
use of org.apache.cayenne.di.mock.MockInterface2 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());
}
}
Aggregations