Search in sources :

Example 1 with MockImplementation1

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());
}
Also used : MockInterface1Provider(org.apache.cayenne.di.mock.MockInterface1Provider) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) MockImplementation1Alt(org.apache.cayenne.di.mock.MockImplementation1Alt) MockImplementation1Alt2(org.apache.cayenne.di.mock.MockImplementation1Alt2) Module(org.apache.cayenne.di.Module) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) Test(org.junit.Test) Assert(org.junit.Assert) Key(org.apache.cayenne.di.Key) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) Test(org.junit.Test)

Example 2 with MockImplementation1

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());
}
Also used : MockInterface1Provider(org.apache.cayenne.di.mock.MockInterface1Provider) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) MockImplementation1Alt(org.apache.cayenne.di.mock.MockImplementation1Alt) MockImplementation1Alt2(org.apache.cayenne.di.mock.MockImplementation1Alt2) Module(org.apache.cayenne.di.Module) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) Test(org.junit.Test) Assert(org.junit.Assert) Key(org.apache.cayenne.di.Key) MockImplementation1Alt(org.apache.cayenne.di.mock.MockImplementation1Alt) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) MockImplementation1Alt2(org.apache.cayenne.di.mock.MockImplementation1Alt2) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) Test(org.junit.Test)

Example 3 with MockImplementation1

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());
}
Also used : MockInterface1Provider(org.apache.cayenne.di.mock.MockInterface1Provider) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) MockImplementation1Alt(org.apache.cayenne.di.mock.MockImplementation1Alt) MockImplementation1Alt2(org.apache.cayenne.di.mock.MockImplementation1Alt2) Module(org.apache.cayenne.di.Module) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) Test(org.junit.Test) Assert(org.junit.Assert) Key(org.apache.cayenne.di.Key) MockImplementation1Alt(org.apache.cayenne.di.mock.MockImplementation1Alt) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) Test(org.junit.Test)

Example 4 with MockImplementation1

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());
}
Also used : MockInterface1(org.apache.cayenne.di.mock.MockInterface1) MockInterface1_Decorator1(org.apache.cayenne.di.mock.MockInterface1_Decorator1) Assert.assertNotNull(org.junit.Assert.assertNotNull) MockInterface1_Decorator3(org.apache.cayenne.di.mock.MockInterface1_Decorator3) Module(org.apache.cayenne.di.Module) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) MockInterface1_Decorator2(org.apache.cayenne.di.mock.MockInterface1_Decorator2) MockInterface1_Decorator5(org.apache.cayenne.di.mock.MockInterface1_Decorator5) Test(org.junit.Test) MockInterface1_Decorator4(org.apache.cayenne.di.mock.MockInterface1_Decorator4) Assert.assertEquals(org.junit.Assert.assertEquals) MockInterface1_Decorator4(org.apache.cayenne.di.mock.MockInterface1_Decorator4) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) Test(org.junit.Test)

Example 5 with MockImplementation1

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());
}
Also used : MockInterface1(org.apache.cayenne.di.mock.MockInterface1) MockInterface1_Decorator1(org.apache.cayenne.di.mock.MockInterface1_Decorator1) Assert.assertNotNull(org.junit.Assert.assertNotNull) MockInterface1_Decorator3(org.apache.cayenne.di.mock.MockInterface1_Decorator3) Module(org.apache.cayenne.di.Module) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) MockInterface1_Decorator2(org.apache.cayenne.di.mock.MockInterface1_Decorator2) MockInterface1_Decorator5(org.apache.cayenne.di.mock.MockInterface1_Decorator5) Test(org.junit.Test) MockInterface1_Decorator4(org.apache.cayenne.di.mock.MockInterface1_Decorator4) Assert.assertEquals(org.junit.Assert.assertEquals) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) MockInterface1_Decorator1(org.apache.cayenne.di.mock.MockInterface1_Decorator1) Test(org.junit.Test)

Aggregations

Module (org.apache.cayenne.di.Module)19 MockImplementation1 (org.apache.cayenne.di.mock.MockImplementation1)19 MockInterface1 (org.apache.cayenne.di.mock.MockInterface1)19 Test (org.junit.Test)19 Assert (org.junit.Assert)14 Key (org.apache.cayenne.di.Key)11 MockImplementation1Alt (org.apache.cayenne.di.mock.MockImplementation1Alt)11 MockImplementation1Alt2 (org.apache.cayenne.di.mock.MockImplementation1Alt2)11 ArrayList (java.util.ArrayList)7 Collection (java.util.Collection)7 Map (java.util.Map)7 DIRuntimeException (org.apache.cayenne.di.DIRuntimeException)7 MockImplementation1_ListConfiguration (org.apache.cayenne.di.mock.MockImplementation1_ListConfiguration)7 MockImplementation1_ListConfigurationMock5 (org.apache.cayenne.di.mock.MockImplementation1_ListConfigurationMock5)7 MockImplementation1_MapConfiguration (org.apache.cayenne.di.mock.MockImplementation1_MapConfiguration)7 MockImplementation1_MapWithWildcards (org.apache.cayenne.di.mock.MockImplementation1_MapWithWildcards)7 MockImplementation1_WithInjector (org.apache.cayenne.di.mock.MockImplementation1_WithInjector)7 MockImplementation2 (org.apache.cayenne.di.mock.MockImplementation2)7 MockImplementation2Sub1 (org.apache.cayenne.di.mock.MockImplementation2Sub1)7 MockImplementation2_ConstructorProvider (org.apache.cayenne.di.mock.MockImplementation2_ConstructorProvider)7