Search in sources :

Example 6 with MockInterface5

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

the class DefaultInjectorInjectionTest method testListInjection_OverrideExplicitlyBoundType.

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

        @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) MockInterface5(org.apache.cayenne.di.mock.MockInterface5) Test(org.junit.Test)

Example 7 with MockInterface5

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

the class DefaultInjectorInjectionTest method testMapInjection_OverrideExplicitlyBoundType.

@Test
public void testMapInjection_OverrideExplicitlyBoundType() {
    Module m1 = binder -> {
        binder.bind(MockInterface5.class).to(MockImplementation5.class);
        binder.bind(MockInterface1.class).to(MockImplementation1_MapConfiguration.class);
        binder.bindMap(Object.class, "xyz").put("a", MockInterface5.class);
    };
    Module m2 = binder -> binder.bind(MockInterface5.class).toInstance(new MockInterface5() {

        @Override
        public String toString() {
            return "abc";
        }
    });
    MockInterface1 service = new DefaultInjector(m1, m2).getInstance(MockInterface1.class);
    assertEquals("Map element was not overridden in submodule", ";a=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_MapConfiguration(org.apache.cayenne.di.mock.MockImplementation1_MapConfiguration) 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