use of org.apache.cayenne.di.mock.MockImplementation5 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());
}
use of org.apache.cayenne.di.mock.MockImplementation5 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testMapInjection_OverrideImplicitlyBoundType.
@Test
public void testMapInjection_OverrideImplicitlyBoundType() {
Module m1 = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1_MapConfiguration.class);
binder.bindMap(Object.class, "xyz").put("a", MockImplementation5.class);
};
Module m2 = binder -> binder.bind(MockImplementation5.class).toInstance(new MockImplementation5() {
@Override
public String toString() {
return "abc";
}
});
MockInterface1 service = new DefaultInjector(m1, m2).getInstance(MockInterface1.class);
assertEquals("Map element was not overridden in submodule", ";a=abc", service.getName());
}
use of org.apache.cayenne.di.mock.MockImplementation5 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testListInjection_OverrideExplicitlyBoundType.
@Test
public void testListInjection_OverrideExplicitlyBoundType() {
Module m1 = binder -> {
binder.bind(MockInterface5.class).to(MockImplementation5.class);
binder.bind(MockInterface1.class).to(MockImplementation1_ListConfiguration.class);
binder.bindList(Object.class, "xyz").add(MockInterface5.class);
};
Module m2 = binder -> binder.bind(MockInterface5.class).toInstance(new MockInterface5() {
@Override
public String toString() {
return "abc";
}
});
MockInterface1 service = new DefaultInjector(m1, m2).getInstance(MockInterface1.class);
assertEquals("List element was not overridden in submodule", ";abc", service.getName());
}
use of org.apache.cayenne.di.mock.MockImplementation5 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testListInjection_addTypeWithBinding.
@Test
public void testListInjection_addTypeWithBinding() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1_ListConfiguration.class);
binder.bindList(Object.class, "xyz").add(MockImplementation5.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.MockImplementation5 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testMapInjection_OverrideExplicitlyBoundType.
@Test
public void testMapInjection_OverrideExplicitlyBoundType() {
Module m1 = binder -> {
binder.bind(MockInterface5.class).to(MockImplementation5.class);
binder.bind(MockInterface1.class).to(MockImplementation1_MapConfiguration.class);
binder.bindMap(Object.class, "xyz").put("a", MockInterface5.class);
};
Module m2 = binder -> binder.bind(MockInterface5.class).toInstance(new MockInterface5() {
@Override
public String toString() {
return "abc";
}
});
MockInterface1 service = new DefaultInjector(m1, m2).getInstance(MockInterface1.class);
assertEquals("Map element was not overridden in submodule", ";a=abc", service.getName());
}
Aggregations