Search in sources :

Example 16 with MockInterface1

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

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

the class DefaultInjectorInjectionTest method testListInjection_empty.

@Test
public void testListInjection_empty() {
    Module module = binder -> {
        binder.bind(MockInterface1.class).to(MockImplementation1_ListConfiguration.class);
        binder.bindList(Object.class, "xyz");
    };
    DefaultInjector injector = new DefaultInjector(module);
    MockInterface1 service = injector.getInstance(MockInterface1.class);
    assertNotNull(service);
    assertEquals("", 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) 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 18 with MockInterface1

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

the class DefaultInjectorInjectionTest method testListInjection_resumed.

@Test
public void testListInjection_resumed() {
    Module module = binder -> {
        binder.bind(MockInterface1.class).to(MockImplementation1_ListConfiguration.class);
        binder.bindList(Object.class, "xyz").add("xvalue").add("yvalue");
        binder.bindList(Object.class, "xyz").add("avalue");
    };
    DefaultInjector injector = new DefaultInjector(module);
    MockInterface1 service = injector.getInstance(MockInterface1.class);
    assertNotNull(service);
    assertEquals(";xvalue;yvalue;avalue", 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) 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 19 with MockInterface1

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

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

Module (org.apache.cayenne.di.Module)46 MockInterface1 (org.apache.cayenne.di.mock.MockInterface1)46 Test (org.junit.Test)46 MockImplementation1 (org.apache.cayenne.di.mock.MockImplementation1)41 Assert (org.junit.Assert)37 Key (org.apache.cayenne.di.Key)30 MockImplementation1Alt (org.apache.cayenne.di.mock.MockImplementation1Alt)30 MockImplementation1Alt2 (org.apache.cayenne.di.mock.MockImplementation1Alt2)30 DIRuntimeException (org.apache.cayenne.di.DIRuntimeException)29 MockImplementation2 (org.apache.cayenne.di.mock.MockImplementation2)29 MockImplementation3 (org.apache.cayenne.di.mock.MockImplementation3)29 MockInterface2 (org.apache.cayenne.di.mock.MockInterface2)29 MockInterface3 (org.apache.cayenne.di.mock.MockInterface3)29 ArrayList (java.util.ArrayList)25 Collection (java.util.Collection)25 Map (java.util.Map)25 MockImplementation1_ListConfiguration (org.apache.cayenne.di.mock.MockImplementation1_ListConfiguration)25 MockImplementation1_ListConfigurationMock5 (org.apache.cayenne.di.mock.MockImplementation1_ListConfigurationMock5)25 MockImplementation1_MapConfiguration (org.apache.cayenne.di.mock.MockImplementation1_MapConfiguration)25 MockImplementation1_MapWithWildcards (org.apache.cayenne.di.mock.MockImplementation1_MapWithWildcards)25