use of org.apache.cayenne.di.mock.MockInterface1 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testMapInjection_Resumed.
@Test
public void testMapInjection_Resumed() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1_MapConfiguration.class);
// bind 1
binder.bindMap(Object.class, "xyz").put("x", "xvalue").put("y", "yvalue");
// second binding attempt to the same map...
binder.bindMap(Object.class, "xyz").put("z", "zvalue").put("x", "xvalue1");
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface1 service = injector.getInstance(MockInterface1.class);
assertNotNull(service);
assertEquals(";x=xvalue1;y=yvalue;z=zvalue", service.getName());
}
use of org.apache.cayenne.di.mock.MockInterface1 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testConstructorInjection.
@Test
public void testConstructorInjection() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1.class);
binder.bind(MockInterface4.class).to(MockImplementation4.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface4 service = injector.getInstance(MockInterface4.class);
assertNotNull(service);
assertEquals("constructor_MyName", service.getName());
}
use of org.apache.cayenne.di.mock.MockInterface1 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testFieldInjection_Named.
@Test
public void testFieldInjection_Named() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1.class);
binder.bind(Key.get(MockInterface1.class, "one")).to(MockImplementation1Alt.class);
binder.bind(Key.get(MockInterface1.class, "two")).to(MockImplementation1Alt2.class);
binder.bind(MockInterface2.class).to(MockImplementation2_Named.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface2 service = injector.getInstance(MockInterface2.class);
assertNotNull(service);
assertEquals("altered_alt", service.getAlteredName());
}
use of org.apache.cayenne.di.mock.MockInterface1 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testProviderInjection_Constructor.
@Test
public void testProviderInjection_Constructor() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1.class);
binder.bind(MockInterface2.class).to(MockImplementation2_ConstructorProvider.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface2 service = injector.getInstance(MockInterface2.class);
assertEquals("altered_MyName", service.getAlteredName());
}
use of org.apache.cayenne.di.mock.MockInterface1 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