Search in sources :

Example 1 with MockInterface5

use of org.apache.cayenne.di.mock.MockInterface5 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 MockInterface5

use of org.apache.cayenne.di.mock.MockInterface5 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 MockInterface5

use of org.apache.cayenne.di.mock.MockInterface5 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 MockInterface5

use of org.apache.cayenne.di.mock.MockInterface5 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 MockInterface5

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

the class DefaultInjectorInjectionTest method testListInjection_addAllValues.

@Test
public void testListInjection_addAllValues() {
    Module module = binder -> {
        binder.bind(MockInterface1.class).to(MockImplementation1_ListConfiguration.class);
        Collection<Object> firstList = new ArrayList<>();
        firstList.add("1value");
        firstList.add("2value");
        firstList.add("3value");
        Collection<Object> secondList = new ArrayList<>();
        secondList.add("6value");
        secondList.add("7value");
        secondList.add("8value");
        binder.bind(MockInterface5.class).to(MockImplementation5.class);
        binder.bindList(Object.class, "xyz").insertAllBefore(firstList, MockInterface5.class).addAllAfter(secondList, MockInterface5.class).add("5value").add(MockInterface5.class);
    };
    DefaultInjector injector = new DefaultInjector(module);
    MockInterface1 service = injector.getInstance(MockInterface1.class);
    assertNotNull(service);
    assertEquals(";1value;2value;3value;xyz;6value;7value;8value;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) Collection(java.util.Collection) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) MockInterface5(org.apache.cayenne.di.mock.MockInterface5) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)7 Collection (java.util.Collection)7 Map (java.util.Map)7 DIRuntimeException (org.apache.cayenne.di.DIRuntimeException)7 Key (org.apache.cayenne.di.Key)7 Module (org.apache.cayenne.di.Module)7 MockImplementation1 (org.apache.cayenne.di.mock.MockImplementation1)7 MockImplementation1Alt (org.apache.cayenne.di.mock.MockImplementation1Alt)7 MockImplementation1Alt2 (org.apache.cayenne.di.mock.MockImplementation1Alt2)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 MockImplementation2_ListConfiguration (org.apache.cayenne.di.mock.MockImplementation2_ListConfiguration)7 MockImplementation2_Named (org.apache.cayenne.di.mock.MockImplementation2_Named)7 MockImplementation3 (org.apache.cayenne.di.mock.MockImplementation3)7