Search in sources :

Example 1 with MockImplementation5

use of org.apache.cayenne.di.mock.MockImplementation5 in project cayenne by apache.

the class DefaultInjectorInjectionTest method testTypedListInjection.

@Test
public void testTypedListInjection() {
    Module module = binder -> {
        binder.bind(MockInterface1.class).to(MockImplementation1_ListConfigurationMock5.class);
        binder.bind(MockInterface2.class).to(MockImplementation2_ListConfiguration.class);
        // Bind list for MockImplementation2_ListConfiguration
        binder.bindList(Object.class, "xyz").add("xvalue").add("yvalue").add(MockImplementation5.class);
        // Bind list for MockImplementation1_ListConfigurationMock5
        binder.bindList(MockInterface5.class).add(MockImplementation5.class).add(new MockInterface5() {

            @Override
            public String toString() {
                return "abc";
            }
        });
        binder.bindList(Object.class).add("avalue").add("bvalue").add(MockImplementation5.class);
        // Add to list for MockImplementation1_ListConfigurationMock5
        binder.bindList(MockInterface5.class).add(new MockInterface5() {

            @Override
            public String toString() {
                return "cde";
            }
        });
        // Create named list for MockInterface5
        binder.bindList(MockInterface5.class, "another_binding").add(new MockInterface5() {

            @Override
            public String toString() {
                return "fgh";
            }
        });
    };
    DefaultInjector injector = new DefaultInjector(module);
    MockInterface1 service = injector.getInstance(MockInterface1.class);
    assertNotNull(service);
    assertEquals(";xyz;abc;cde", service.getName());
    MockInterface2 service2 = injector.getInstance(MockInterface2.class);
    assertNotNull(service2);
    assertTrue(service2 instanceof MockImplementation2_ListConfiguration);
    assertEquals(";xvalue;yvalue;xyz", service2.getName());
}
Also used : MockImplementation1_ListConfigurationMock5(org.apache.cayenne.di.mock.MockImplementation1_ListConfigurationMock5) Module(org.apache.cayenne.di.Module) MockImplementation2_ListConfiguration(org.apache.cayenne.di.mock.MockImplementation2_ListConfiguration) ArrayList(java.util.ArrayList) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) MockImplementation1Alt(org.apache.cayenne.di.mock.MockImplementation1Alt) MockImplementation1_WithInjector(org.apache.cayenne.di.mock.MockImplementation1_WithInjector) Map(java.util.Map) Key(org.apache.cayenne.di.Key) MockImplementation1_ListConfiguration(org.apache.cayenne.di.mock.MockImplementation1_ListConfiguration) MockImplementation1_MapConfiguration(org.apache.cayenne.di.mock.MockImplementation1_MapConfiguration) MockImplementation1Alt2(org.apache.cayenne.di.mock.MockImplementation1Alt2) Collection(java.util.Collection) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) MockImplementation2(org.apache.cayenne.di.mock.MockImplementation2) MockImplementation2_Named(org.apache.cayenne.di.mock.MockImplementation2_Named) Test(org.junit.Test) MockImplementation3(org.apache.cayenne.di.mock.MockImplementation3) MockImplementation4(org.apache.cayenne.di.mock.MockImplementation4) MockImplementation5(org.apache.cayenne.di.mock.MockImplementation5) MockInterface2(org.apache.cayenne.di.mock.MockInterface2) MockImplementation1_MapWithWildcards(org.apache.cayenne.di.mock.MockImplementation1_MapWithWildcards) MockImplementation2_ConstructorProvider(org.apache.cayenne.di.mock.MockImplementation2_ConstructorProvider) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) MockImplementation4Alt2(org.apache.cayenne.di.mock.MockImplementation4Alt2) MockImplementation2Sub1(org.apache.cayenne.di.mock.MockImplementation2Sub1) MockImplementation4Alt(org.apache.cayenne.di.mock.MockImplementation4Alt) DIRuntimeException(org.apache.cayenne.di.DIRuntimeException) MockInterface4(org.apache.cayenne.di.mock.MockInterface4) Assert(org.junit.Assert) MockInterface3(org.apache.cayenne.di.mock.MockInterface3) MockInterface5(org.apache.cayenne.di.mock.MockInterface5) MockImplementation5(org.apache.cayenne.di.mock.MockImplementation5) MockImplementation2_ListConfiguration(org.apache.cayenne.di.mock.MockImplementation2_ListConfiguration) MockInterface2(org.apache.cayenne.di.mock.MockInterface2) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) MockImplementation1_ListConfigurationMock5(org.apache.cayenne.di.mock.MockImplementation1_ListConfigurationMock5) MockInterface5(org.apache.cayenne.di.mock.MockInterface5) Test(org.junit.Test)

Example 2 with MockImplementation5

use of org.apache.cayenne.di.mock.MockImplementation5 in project cayenne by apache.

the class DefaultInjectorInjectionTest method testListInjection_addOrderedTypes.

@Test
public void testListInjection_addOrderedTypes() {
    Module module = binder -> {
        binder.bind(MockInterface1.class).to(MockImplementation1_ListConfiguration.class);
        binder.bind(MockInterface5.class).to(MockImplementation5.class);
        binder.bindList(Object.class, "xyz").add("1value").insertBefore("5value", MockInterface5.class).add("2value").addAfter("6value", MockInterface5.class).add("3value").add(MockInterface5.class);
    };
    DefaultInjector injector = new DefaultInjector(module);
    MockInterface1 service = injector.getInstance(MockInterface1.class);
    assertNotNull(service);
    assertEquals(";1value;2value;5value;xyz;6value;3value", service.getName());
}
Also used : MockImplementation1_ListConfigurationMock5(org.apache.cayenne.di.mock.MockImplementation1_ListConfigurationMock5) Module(org.apache.cayenne.di.Module) MockImplementation2_ListConfiguration(org.apache.cayenne.di.mock.MockImplementation2_ListConfiguration) ArrayList(java.util.ArrayList) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) MockImplementation1Alt(org.apache.cayenne.di.mock.MockImplementation1Alt) MockImplementation1_WithInjector(org.apache.cayenne.di.mock.MockImplementation1_WithInjector) Map(java.util.Map) Key(org.apache.cayenne.di.Key) MockImplementation1_ListConfiguration(org.apache.cayenne.di.mock.MockImplementation1_ListConfiguration) MockImplementation1_MapConfiguration(org.apache.cayenne.di.mock.MockImplementation1_MapConfiguration) MockImplementation1Alt2(org.apache.cayenne.di.mock.MockImplementation1Alt2) Collection(java.util.Collection) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) MockImplementation2(org.apache.cayenne.di.mock.MockImplementation2) MockImplementation2_Named(org.apache.cayenne.di.mock.MockImplementation2_Named) Test(org.junit.Test) MockImplementation3(org.apache.cayenne.di.mock.MockImplementation3) MockImplementation4(org.apache.cayenne.di.mock.MockImplementation4) MockImplementation5(org.apache.cayenne.di.mock.MockImplementation5) MockInterface2(org.apache.cayenne.di.mock.MockInterface2) MockImplementation1_MapWithWildcards(org.apache.cayenne.di.mock.MockImplementation1_MapWithWildcards) MockImplementation2_ConstructorProvider(org.apache.cayenne.di.mock.MockImplementation2_ConstructorProvider) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) MockImplementation4Alt2(org.apache.cayenne.di.mock.MockImplementation4Alt2) MockImplementation2Sub1(org.apache.cayenne.di.mock.MockImplementation2Sub1) MockImplementation4Alt(org.apache.cayenne.di.mock.MockImplementation4Alt) DIRuntimeException(org.apache.cayenne.di.DIRuntimeException) MockInterface4(org.apache.cayenne.di.mock.MockInterface4) Assert(org.junit.Assert) MockInterface3(org.apache.cayenne.di.mock.MockInterface3) MockInterface5(org.apache.cayenne.di.mock.MockInterface5) MockImplementation5(org.apache.cayenne.di.mock.MockImplementation5) MockImplementation1_ListConfiguration(org.apache.cayenne.di.mock.MockImplementation1_ListConfiguration) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) MockInterface5(org.apache.cayenne.di.mock.MockInterface5) Test(org.junit.Test)

Example 3 with MockImplementation5

use of org.apache.cayenne.di.mock.MockImplementation5 in project cayenne by apache.

the class DefaultInjectorInjectionTest method testListInjection_addType.

@Test
public void testListInjection_addType() {
    Module module = binder -> {
        binder.bind(MockInterface5.class).to(MockImplementation5.class);
        binder.bind(MockInterface1.class).to(MockImplementation1_ListConfiguration.class);
        binder.bindList(Object.class, "xyz").add(MockInterface5.class).add("yvalue");
    };
    DefaultInjector injector = new DefaultInjector(module);
    MockInterface1 service = injector.getInstance(MockInterface1.class);
    assertNotNull(service);
    assertEquals(";xyz;yvalue", service.getName());
}
Also used : MockImplementation1_ListConfigurationMock5(org.apache.cayenne.di.mock.MockImplementation1_ListConfigurationMock5) Module(org.apache.cayenne.di.Module) MockImplementation2_ListConfiguration(org.apache.cayenne.di.mock.MockImplementation2_ListConfiguration) ArrayList(java.util.ArrayList) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) MockImplementation1Alt(org.apache.cayenne.di.mock.MockImplementation1Alt) MockImplementation1_WithInjector(org.apache.cayenne.di.mock.MockImplementation1_WithInjector) Map(java.util.Map) Key(org.apache.cayenne.di.Key) MockImplementation1_ListConfiguration(org.apache.cayenne.di.mock.MockImplementation1_ListConfiguration) MockImplementation1_MapConfiguration(org.apache.cayenne.di.mock.MockImplementation1_MapConfiguration) MockImplementation1Alt2(org.apache.cayenne.di.mock.MockImplementation1Alt2) Collection(java.util.Collection) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) MockImplementation2(org.apache.cayenne.di.mock.MockImplementation2) MockImplementation2_Named(org.apache.cayenne.di.mock.MockImplementation2_Named) Test(org.junit.Test) MockImplementation3(org.apache.cayenne.di.mock.MockImplementation3) MockImplementation4(org.apache.cayenne.di.mock.MockImplementation4) MockImplementation5(org.apache.cayenne.di.mock.MockImplementation5) MockInterface2(org.apache.cayenne.di.mock.MockInterface2) MockImplementation1_MapWithWildcards(org.apache.cayenne.di.mock.MockImplementation1_MapWithWildcards) MockImplementation2_ConstructorProvider(org.apache.cayenne.di.mock.MockImplementation2_ConstructorProvider) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) MockImplementation4Alt2(org.apache.cayenne.di.mock.MockImplementation4Alt2) MockImplementation2Sub1(org.apache.cayenne.di.mock.MockImplementation2Sub1) MockImplementation4Alt(org.apache.cayenne.di.mock.MockImplementation4Alt) DIRuntimeException(org.apache.cayenne.di.DIRuntimeException) MockInterface4(org.apache.cayenne.di.mock.MockInterface4) Assert(org.junit.Assert) MockInterface3(org.apache.cayenne.di.mock.MockInterface3) MockInterface5(org.apache.cayenne.di.mock.MockInterface5) MockImplementation5(org.apache.cayenne.di.mock.MockImplementation5) MockImplementation1_ListConfiguration(org.apache.cayenne.di.mock.MockImplementation1_ListConfiguration) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) Test(org.junit.Test)

Example 4 with MockImplementation5

use of org.apache.cayenne.di.mock.MockImplementation5 in project cayenne by apache.

the class DefaultInjectorInjectionTest method testListInjection_addOrderedValues.

@Test
public void testListInjection_addOrderedValues() {
    Module module = binder -> {
        binder.bind(MockInterface1.class).to(MockImplementation1_ListConfiguration.class);
        binder.bind(MockInterface5.class).to(MockImplementation5.class);
        binder.bindList(Object.class, "xyz").add("1value").add("2value").addAfter("5value", MockInterface5.class).insertBefore("3value", MockInterface5.class).add(MockInterface5.class);
    };
    DefaultInjector injector = new DefaultInjector(module);
    MockInterface1 service = injector.getInstance(MockInterface1.class);
    assertNotNull(service);
    assertEquals(";1value;2value;3value;xyz;5value", service.getName());
}
Also used : MockImplementation1_ListConfigurationMock5(org.apache.cayenne.di.mock.MockImplementation1_ListConfigurationMock5) Module(org.apache.cayenne.di.Module) MockImplementation2_ListConfiguration(org.apache.cayenne.di.mock.MockImplementation2_ListConfiguration) ArrayList(java.util.ArrayList) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) MockImplementation1Alt(org.apache.cayenne.di.mock.MockImplementation1Alt) MockImplementation1_WithInjector(org.apache.cayenne.di.mock.MockImplementation1_WithInjector) Map(java.util.Map) Key(org.apache.cayenne.di.Key) MockImplementation1_ListConfiguration(org.apache.cayenne.di.mock.MockImplementation1_ListConfiguration) MockImplementation1_MapConfiguration(org.apache.cayenne.di.mock.MockImplementation1_MapConfiguration) MockImplementation1Alt2(org.apache.cayenne.di.mock.MockImplementation1Alt2) Collection(java.util.Collection) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) MockImplementation2(org.apache.cayenne.di.mock.MockImplementation2) MockImplementation2_Named(org.apache.cayenne.di.mock.MockImplementation2_Named) Test(org.junit.Test) MockImplementation3(org.apache.cayenne.di.mock.MockImplementation3) MockImplementation4(org.apache.cayenne.di.mock.MockImplementation4) MockImplementation5(org.apache.cayenne.di.mock.MockImplementation5) MockInterface2(org.apache.cayenne.di.mock.MockInterface2) MockImplementation1_MapWithWildcards(org.apache.cayenne.di.mock.MockImplementation1_MapWithWildcards) MockImplementation2_ConstructorProvider(org.apache.cayenne.di.mock.MockImplementation2_ConstructorProvider) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) MockImplementation4Alt2(org.apache.cayenne.di.mock.MockImplementation4Alt2) MockImplementation2Sub1(org.apache.cayenne.di.mock.MockImplementation2Sub1) MockImplementation4Alt(org.apache.cayenne.di.mock.MockImplementation4Alt) DIRuntimeException(org.apache.cayenne.di.DIRuntimeException) MockInterface4(org.apache.cayenne.di.mock.MockInterface4) Assert(org.junit.Assert) MockInterface3(org.apache.cayenne.di.mock.MockInterface3) MockInterface5(org.apache.cayenne.di.mock.MockInterface5) MockImplementation5(org.apache.cayenne.di.mock.MockImplementation5) MockImplementation1_ListConfiguration(org.apache.cayenne.di.mock.MockImplementation1_ListConfiguration) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) MockInterface5(org.apache.cayenne.di.mock.MockInterface5) Test(org.junit.Test)

Example 5 with MockImplementation5

use of org.apache.cayenne.di.mock.MockImplementation5 in project cayenne by apache.

the class DefaultInjectorInjectionTest method testListInjection_OverrideImplicitlyBoundType.

@Test
public void testListInjection_OverrideImplicitlyBoundType() {
    Module m1 = binder -> {
        binder.bind(MockInterface1.class).to(MockImplementation1_ListConfiguration.class);
        binder.bindList(Object.class, "xyz").add(MockImplementation5.class);
    };
    Module m2 = binder -> binder.bind(MockImplementation5.class).toInstance(new MockImplementation5() {

        @Override
        public String toString() {
            return "abc";
        }
    });
    MockInterface1 service = new DefaultInjector(m1, m2).getInstance(MockInterface1.class);
    assertEquals("List element was not overridden in submodule", ";abc", service.getName());
}
Also used : MockImplementation1_ListConfigurationMock5(org.apache.cayenne.di.mock.MockImplementation1_ListConfigurationMock5) Module(org.apache.cayenne.di.Module) MockImplementation2_ListConfiguration(org.apache.cayenne.di.mock.MockImplementation2_ListConfiguration) ArrayList(java.util.ArrayList) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) MockImplementation1Alt(org.apache.cayenne.di.mock.MockImplementation1Alt) MockImplementation1_WithInjector(org.apache.cayenne.di.mock.MockImplementation1_WithInjector) Map(java.util.Map) Key(org.apache.cayenne.di.Key) MockImplementation1_ListConfiguration(org.apache.cayenne.di.mock.MockImplementation1_ListConfiguration) MockImplementation1_MapConfiguration(org.apache.cayenne.di.mock.MockImplementation1_MapConfiguration) MockImplementation1Alt2(org.apache.cayenne.di.mock.MockImplementation1Alt2) Collection(java.util.Collection) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) MockImplementation2(org.apache.cayenne.di.mock.MockImplementation2) MockImplementation2_Named(org.apache.cayenne.di.mock.MockImplementation2_Named) Test(org.junit.Test) MockImplementation3(org.apache.cayenne.di.mock.MockImplementation3) MockImplementation4(org.apache.cayenne.di.mock.MockImplementation4) MockImplementation5(org.apache.cayenne.di.mock.MockImplementation5) MockInterface2(org.apache.cayenne.di.mock.MockInterface2) MockImplementation1_MapWithWildcards(org.apache.cayenne.di.mock.MockImplementation1_MapWithWildcards) MockImplementation2_ConstructorProvider(org.apache.cayenne.di.mock.MockImplementation2_ConstructorProvider) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) MockImplementation4Alt2(org.apache.cayenne.di.mock.MockImplementation4Alt2) MockImplementation2Sub1(org.apache.cayenne.di.mock.MockImplementation2Sub1) MockImplementation4Alt(org.apache.cayenne.di.mock.MockImplementation4Alt) DIRuntimeException(org.apache.cayenne.di.DIRuntimeException) MockInterface4(org.apache.cayenne.di.mock.MockInterface4) Assert(org.junit.Assert) MockInterface3(org.apache.cayenne.di.mock.MockInterface3) MockInterface5(org.apache.cayenne.di.mock.MockInterface5) MockImplementation5(org.apache.cayenne.di.mock.MockImplementation5) MockImplementation1_ListConfiguration(org.apache.cayenne.di.mock.MockImplementation1_ListConfiguration) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)10 Collection (java.util.Collection)10 Map (java.util.Map)10 DIRuntimeException (org.apache.cayenne.di.DIRuntimeException)10 Key (org.apache.cayenne.di.Key)10 Module (org.apache.cayenne.di.Module)10 MockImplementation1 (org.apache.cayenne.di.mock.MockImplementation1)10 MockImplementation1Alt (org.apache.cayenne.di.mock.MockImplementation1Alt)10 MockImplementation1Alt2 (org.apache.cayenne.di.mock.MockImplementation1Alt2)10 MockImplementation1_ListConfiguration (org.apache.cayenne.di.mock.MockImplementation1_ListConfiguration)10 MockImplementation1_ListConfigurationMock5 (org.apache.cayenne.di.mock.MockImplementation1_ListConfigurationMock5)10 MockImplementation1_MapConfiguration (org.apache.cayenne.di.mock.MockImplementation1_MapConfiguration)10 MockImplementation1_MapWithWildcards (org.apache.cayenne.di.mock.MockImplementation1_MapWithWildcards)10 MockImplementation1_WithInjector (org.apache.cayenne.di.mock.MockImplementation1_WithInjector)10 MockImplementation2 (org.apache.cayenne.di.mock.MockImplementation2)10 MockImplementation2Sub1 (org.apache.cayenne.di.mock.MockImplementation2Sub1)10 MockImplementation2_ConstructorProvider (org.apache.cayenne.di.mock.MockImplementation2_ConstructorProvider)10 MockImplementation2_ListConfiguration (org.apache.cayenne.di.mock.MockImplementation2_ListConfiguration)10 MockImplementation2_Named (org.apache.cayenne.di.mock.MockImplementation2_Named)10 MockImplementation3 (org.apache.cayenne.di.mock.MockImplementation3)10