Search in sources :

Example 1 with MockImplementation1Alt2

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

the class DefaultInjectorInjectionTest method testConstructorInjection_Named.

@Test
public void testConstructorInjection_Named() {
    Module module = binder -> {
        binder.bind(MockInterface1.class).to(MockImplementation1.class);
        binder.bind(Key.get(MockInterface1.class, "one")).to(MockImplementation1Alt.class);
        binder.bind(Key.get(MockInterface1.class, "two")).to(MockImplementation1Alt2.class);
        binder.bind(MockInterface4.class).to(MockImplementation4Alt.class);
    };
    DefaultInjector injector = new DefaultInjector(module);
    MockInterface4 service = injector.getInstance(MockInterface4.class);
    assertNotNull(service);
    assertEquals("constructor_alt2", 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) MockImplementation1Alt(org.apache.cayenne.di.mock.MockImplementation1Alt) MockImplementation4Alt(org.apache.cayenne.di.mock.MockImplementation4Alt) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) MockInterface4(org.apache.cayenne.di.mock.MockInterface4) MockImplementation1Alt2(org.apache.cayenne.di.mock.MockImplementation1Alt2) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) Test(org.junit.Test)

Example 2 with MockImplementation1Alt2

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

the class DefaultInjectorInjectionTest method testConstructorInjection_Named_Mixed.

@Test
public void testConstructorInjection_Named_Mixed() {
    Module module = binder -> {
        binder.bind(MockInterface1.class).to(MockImplementation1.class);
        binder.bind(Key.get(MockInterface1.class, "one")).to(MockImplementation1Alt.class);
        binder.bind(Key.get(MockInterface1.class, "two")).to(MockImplementation1Alt2.class);
        binder.bind(MockInterface3.class).to(MockImplementation3.class);
        binder.bind(MockInterface4.class).to(MockImplementation4Alt2.class);
    };
    DefaultInjector injector = new DefaultInjector(module);
    MockInterface4 service = injector.getInstance(MockInterface4.class);
    assertNotNull(service);
    assertEquals("constructor_alt2_XName", 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) MockImplementation1Alt(org.apache.cayenne.di.mock.MockImplementation1Alt) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) MockImplementation3(org.apache.cayenne.di.mock.MockImplementation3) MockInterface4(org.apache.cayenne.di.mock.MockInterface4) MockImplementation1Alt2(org.apache.cayenne.di.mock.MockImplementation1Alt2) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) MockImplementation4Alt2(org.apache.cayenne.di.mock.MockImplementation4Alt2) Test(org.junit.Test)

Example 3 with MockImplementation1Alt2

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

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

the class DefaultInjectorInjectionTest method testFieldInjection_Named.

@Test
public void testFieldInjection_Named() {
    Module module = binder -> {
        binder.bind(MockInterface1.class).to(MockImplementation1.class);
        binder.bind(Key.get(MockInterface1.class, "one")).to(MockImplementation1Alt.class);
        binder.bind(Key.get(MockInterface1.class, "two")).to(MockImplementation1Alt2.class);
        binder.bind(MockInterface2.class).to(MockImplementation2_Named.class);
    };
    DefaultInjector injector = new DefaultInjector(module);
    MockInterface2 service = injector.getInstance(MockInterface2.class);
    assertNotNull(service);
    assertEquals("altered_alt", service.getAlteredName());
}
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) MockImplementation1Alt(org.apache.cayenne.di.mock.MockImplementation1Alt) MockImplementation2_Named(org.apache.cayenne.di.mock.MockImplementation2_Named) MockInterface2(org.apache.cayenne.di.mock.MockInterface2) 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)

Aggregations

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