use of org.apache.cayenne.di.mock.MockInterface1 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testFieldInjection.
@Test
public void testFieldInjection() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1.class);
binder.bind(MockInterface2.class).to(MockImplementation2.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface2 service = injector.getInstance(MockInterface2.class);
assertNotNull(service);
assertEquals("altered_MyName", service.getAlteredName());
}
use of org.apache.cayenne.di.mock.MockInterface1 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.MockInterface1 in project cayenne by apache.
the class DefaultInjectorInjectionTest method testInjectorInjection.
@Test
public void testInjectorInjection() {
Module module = binder -> binder.bind(MockInterface1.class).to(MockImplementation1_WithInjector.class);
DefaultInjector injector = new DefaultInjector(module);
MockInterface1 service = injector.getInstance(MockInterface1.class);
assertNotNull(service);
assertEquals("injector_not_null", service.getName());
}
use of org.apache.cayenne.di.mock.MockInterface1 in project cayenne by apache.
the class DefaultInjectorScopeTest method testDefaultScope_IsSingleton.
@Test
public void testDefaultScope_IsSingleton() {
Module module = binder -> binder.bind(MockInterface1.class).to(MockImplementation1.class);
DefaultInjector injector = new DefaultInjector(module);
MockInterface1 instance1 = injector.getInstance(MockInterface1.class);
MockInterface1 instance2 = injector.getInstance(MockInterface1.class);
MockInterface1 instance3 = injector.getInstance(MockInterface1.class);
assertNotNull(instance1);
assertNotNull(instance2);
assertNotNull(instance3);
assertSame(instance1, instance2);
assertSame(instance2, instance3);
}
use of org.apache.cayenne.di.mock.MockInterface1 in project cayenne by apache.
the class DefaultInjectorBindingTest method testInstanceBinding.
@Test
public void testInstanceBinding() {
final MockImplementation1 instance = new MockImplementation1();
Module module = binder -> binder.bind(MockInterface1.class).toInstance(instance);
DefaultInjector injector = new DefaultInjector(module);
MockInterface1 service = injector.getInstance(MockInterface1.class);
assertNotNull(service);
assertSame(instance, service);
}
Aggregations