use of org.apache.cayenne.di.mock.MockImplementation1 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.MockImplementation1 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.MockImplementation1 in project cayenne by apache.
the class DefaultInjectorScopeTest method testNoScope.
@Test
public void testNoScope() {
Module module = binder -> binder.bind(MockInterface1.class).to(MockImplementation1.class).withoutScope();
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);
assertNotSame(instance1, instance2);
assertNotSame(instance2, instance3);
assertNotSame(instance3, instance1);
}
use of org.apache.cayenne.di.mock.MockImplementation1 in project cayenne by apache.
the class DefaultInjectorScopeTest method testSingletonScope.
@Test
public void testSingletonScope() {
Module module = binder -> binder.bind(MockInterface1.class).to(MockImplementation1.class).inSingletonScope();
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);
}
Aggregations