use of org.apache.cayenne.di.mock.MockInterface5 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.MockInterface5 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testListInjection_addOrderedTypes.
@Test
public void testListInjection_addOrderedTypes() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1_ListConfiguration.class);
binder.bind(MockInterface5.class).to(MockImplementation5.class);
binder.bindList(Object.class, "xyz").add("1value").insertBefore("5value", MockInterface5.class).add("2value").addAfter("6value", MockInterface5.class).add("3value").add(MockInterface5.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface1 service = injector.getInstance(MockInterface1.class);
assertNotNull(service);
assertEquals(";1value;2value;5value;xyz;6value;3value", service.getName());
}
use of org.apache.cayenne.di.mock.MockInterface5 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testListInjection_addType.
@Test
public void testListInjection_addType() {
Module module = binder -> {
binder.bind(MockInterface5.class).to(MockImplementation5.class);
binder.bind(MockInterface1.class).to(MockImplementation1_ListConfiguration.class);
binder.bindList(Object.class, "xyz").add(MockInterface5.class).add("yvalue");
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface1 service = injector.getInstance(MockInterface1.class);
assertNotNull(service);
assertEquals(";xyz;yvalue", service.getName());
}
use of org.apache.cayenne.di.mock.MockInterface5 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testListInjection_addOrderedValues.
@Test
public void testListInjection_addOrderedValues() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1_ListConfiguration.class);
binder.bind(MockInterface5.class).to(MockImplementation5.class);
binder.bindList(Object.class, "xyz").add("1value").add("2value").addAfter("5value", MockInterface5.class).insertBefore("3value", MockInterface5.class).add(MockInterface5.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface1 service = injector.getInstance(MockInterface1.class);
assertNotNull(service);
assertEquals(";1value;2value;3value;xyz;5value", service.getName());
}
use of org.apache.cayenne.di.mock.MockInterface5 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testListInjection_addAllValues.
@Test
public void testListInjection_addAllValues() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1_ListConfiguration.class);
Collection<Object> firstList = new ArrayList<>();
firstList.add("1value");
firstList.add("2value");
firstList.add("3value");
Collection<Object> secondList = new ArrayList<>();
secondList.add("6value");
secondList.add("7value");
secondList.add("8value");
binder.bind(MockInterface5.class).to(MockImplementation5.class);
binder.bindList(Object.class, "xyz").insertAllBefore(firstList, MockInterface5.class).addAllAfter(secondList, MockInterface5.class).add("5value").add(MockInterface5.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface1 service = injector.getInstance(MockInterface1.class);
assertNotNull(service);
assertEquals(";1value;2value;3value;xyz;6value;7value;8value;5value", service.getName());
}
Aggregations