use of org.apache.cayenne.di.mock.MockImplementation2_ListConfiguration 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());
}
Aggregations