use of org.apache.cayenne.di.mock.MockImplementation1 in project cayenne by apache.
the class DefaultInjectorBindingTest method testClassBinding.
@Test
public void testClassBinding() {
Module module = binder -> binder.bind(MockInterface1.class).to(MockImplementation1.class);
DefaultInjector injector = new DefaultInjector(module);
MockInterface1 service = injector.getInstance(MockInterface1.class);
assertNotNull(service);
assertEquals("MyName", service.getName());
}
use of org.apache.cayenne.di.mock.MockImplementation1 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.MockImplementation1 in project cayenne by apache.
the class DefaultInjectorBindingTest method testClassReBinding.
@Test
public void testClassReBinding() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1.class);
binder.bind(MockInterface1.class).to(MockImplementation1Alt.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface1 service = injector.getInstance(MockInterface1.class);
assertNotNull(service);
assertEquals("alt", service.getName());
}
use of org.apache.cayenne.di.mock.MockImplementation1 in project cayenne by apache.
the class DefaultInjectorDecorationTest method testSingleDecorator_Provider_ConstructorInjection.
@Test
public void testSingleDecorator_Provider_ConstructorInjection() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1.class);
binder.decorate(MockInterface1.class).before(MockInterface1_Decorator4.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface1 service = injector.getInstance(MockInterface1.class);
assertNotNull(service);
assertEquals("[4MyName4]", service.getName());
}
use of org.apache.cayenne.di.mock.MockImplementation1 in project cayenne by apache.
the class DefaultInjectorDecorationTest method testSingleDecorator_After.
@Test
public void testSingleDecorator_After() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1.class);
binder.decorate(MockInterface1.class).after(MockInterface1_Decorator1.class);
};
DefaultInjector injector = new DefaultInjector(module);
MockInterface1 service = injector.getInstance(MockInterface1.class);
assertNotNull(service);
assertEquals("[MyName]", service.getName());
}
Aggregations