use of org.apache.cayenne.di.mock.MockImplementation1Alt2 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testConstructorInjection_Named.
@Test
public void testConstructorInjection_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(MockInterface4.class).to(MockImplementation4Alt.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface4 service = injector.getInstance(MockInterface4.class);
assertNotNull(service);
assertEquals("constructor_alt2", service.getName());
}
use of org.apache.cayenne.di.mock.MockImplementation1Alt2 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testConstructorInjection_Named_Mixed.
@Test
public void testConstructorInjection_Named_Mixed() {
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(MockInterface3.class).to(MockImplementation3.class);
binder.bind(MockInterface4.class).to(MockImplementation4Alt2.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface4 service = injector.getInstance(MockInterface4.class);
assertNotNull(service);
assertEquals("constructor_alt2_XName", service.getName());
}
use of org.apache.cayenne.di.mock.MockImplementation1Alt2 in project cayenne by apache.
the class DefaultInjectorBindingTest method testClassNamedBinding.
@Test
public void testClassNamedBinding() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1.class);
binder.bind(Key.get(MockInterface1.class, "abc")).to(MockImplementation1Alt.class);
binder.bind(Key.get(MockInterface1.class, "xyz")).to(MockImplementation1Alt2.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface1 defaultObject = injector.getInstance(MockInterface1.class);
assertNotNull(defaultObject);
assertEquals("MyName", defaultObject.getName());
MockInterface1 abcObject = injector.getInstance(Key.get(MockInterface1.class, "abc"));
assertNotNull(abcObject);
assertEquals("alt", abcObject.getName());
MockInterface1 xyzObject = injector.getInstance(Key.get(MockInterface1.class, "xyz"));
assertNotNull(xyzObject);
assertEquals("alt2", xyzObject.getName());
}
use of org.apache.cayenne.di.mock.MockImplementation1Alt2 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());
}
Aggregations