use of org.apache.cayenne.di.mock.MockInterface1 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.MockInterface1 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.MockInterface1 in project cayenne by apache.
the class DefaultInjectorBindingTest method testProviderBinding.
@Test
public void testProviderBinding() {
Module module = binder -> binder.bind(MockInterface1.class).toProvider(MockInterface1Provider.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.MockInterface1 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.MockInterface1 in project cayenne by apache.
the class DefaultInjectorCircularInjectionTest method testFieldInjection_CircularDependency.
@Test
public void testFieldInjection_CircularDependency() {
Module module = binder -> {
binder.bind(MockInterface1.class).to(MockImplementation1_DepOn2.class);
binder.bind(MockInterface2.class).to(MockImplementation2.class);
};
DefaultInjector injector = new DefaultInjector(module);
try {
injector.getInstance(MockInterface1.class);
fail("Circular dependency is not detected.");
} catch (DIRuntimeException e) {
// expected
} catch (StackOverflowError e) {
fail("Circular dependency is not detected, causing stack overflow");
}
}
Aggregations