Search in sources :

Example 16 with MockImplementation1

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

Example 17 with MockImplementation1

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

the class DefaultInjectorInjectionTest method testProviderInjection_Constructor.

@Test
public void testProviderInjection_Constructor() {
    Module module = binder -> {
        binder.bind(MockInterface1.class).to(MockImplementation1.class);
        binder.bind(MockInterface2.class).to(MockImplementation2_ConstructorProvider.class);
    };
    DefaultInjector injector = new DefaultInjector(module);
    MockInterface2 service = injector.getInstance(MockInterface2.class);
    assertEquals("altered_MyName", 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) MockImplementation2_ConstructorProvider(org.apache.cayenne.di.mock.MockImplementation2_ConstructorProvider) MockInterface2(org.apache.cayenne.di.mock.MockInterface2) Module(org.apache.cayenne.di.Module) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) Test(org.junit.Test)

Example 18 with MockImplementation1

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

the class DefaultInjectorScopeTest method testNoScope.

@Test
public void testNoScope() {
    Module module = binder -> binder.bind(MockInterface1.class).to(MockImplementation1.class).withoutScope();
    DefaultInjector injector = new DefaultInjector(module);
    MockInterface1 instance1 = injector.getInstance(MockInterface1.class);
    MockInterface1 instance2 = injector.getInstance(MockInterface1.class);
    MockInterface1 instance3 = injector.getInstance(MockInterface1.class);
    assertNotNull(instance1);
    assertNotNull(instance2);
    assertNotNull(instance3);
    assertNotSame(instance1, instance2);
    assertNotSame(instance2, instance3);
    assertNotSame(instance3, instance1);
}
Also used : MockImplementation1_Provider(org.apache.cayenne.di.mock.MockImplementation1_Provider) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) Test(org.junit.Test) BeforeScopeEnd(org.apache.cayenne.di.BeforeScopeEnd) MockImplementation1_EventAnnotations(org.apache.cayenne.di.mock.MockImplementation1_EventAnnotations) Assert(org.junit.Assert) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) Test(org.junit.Test)

Example 19 with MockImplementation1

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

the class DefaultInjectorScopeTest method testSingletonScope.

@Test
public void testSingletonScope() {
    Module module = binder -> binder.bind(MockInterface1.class).to(MockImplementation1.class).inSingletonScope();
    DefaultInjector injector = new DefaultInjector(module);
    MockInterface1 instance1 = injector.getInstance(MockInterface1.class);
    MockInterface1 instance2 = injector.getInstance(MockInterface1.class);
    MockInterface1 instance3 = injector.getInstance(MockInterface1.class);
    assertNotNull(instance1);
    assertNotNull(instance2);
    assertNotNull(instance3);
    assertSame(instance1, instance2);
    assertSame(instance2, instance3);
}
Also used : MockImplementation1_Provider(org.apache.cayenne.di.mock.MockImplementation1_Provider) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) Test(org.junit.Test) BeforeScopeEnd(org.apache.cayenne.di.BeforeScopeEnd) MockImplementation1_EventAnnotations(org.apache.cayenne.di.mock.MockImplementation1_EventAnnotations) Assert(org.junit.Assert) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) MockImplementation1(org.apache.cayenne.di.mock.MockImplementation1) Test(org.junit.Test)

Aggregations

Module (org.apache.cayenne.di.Module)19 MockImplementation1 (org.apache.cayenne.di.mock.MockImplementation1)19 MockInterface1 (org.apache.cayenne.di.mock.MockInterface1)19 Test (org.junit.Test)19 Assert (org.junit.Assert)14 Key (org.apache.cayenne.di.Key)11 MockImplementation1Alt (org.apache.cayenne.di.mock.MockImplementation1Alt)11 MockImplementation1Alt2 (org.apache.cayenne.di.mock.MockImplementation1Alt2)11 ArrayList (java.util.ArrayList)7 Collection (java.util.Collection)7 Map (java.util.Map)7 DIRuntimeException (org.apache.cayenne.di.DIRuntimeException)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