Search in sources :

Example 41 with MockInterface1

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

the class DefaultInjectorScopeTest method testSingletonScope_AnnotatedEvents.

@Test
public void testSingletonScope_AnnotatedEvents() {
    MockImplementation1_EventAnnotations.reset();
    Module module = binder -> binder.bind(MockInterface1.class).to(MockImplementation1_EventAnnotations.class).inSingletonScope();
    DefaultInjector injector = new DefaultInjector(module);
    MockInterface1 instance1 = injector.getInstance(MockInterface1.class);
    assertEquals("XuI", instance1.getName());
    assertFalse(MockImplementation1_EventAnnotations.shutdown1);
    assertFalse(MockImplementation1_EventAnnotations.shutdown2);
    assertFalse(MockImplementation1_EventAnnotations.shutdown3);
    injector.getSingletonScope().postScopeEvent(BeforeScopeEnd.class);
    assertTrue(MockImplementation1_EventAnnotations.shutdown1);
    assertTrue(MockImplementation1_EventAnnotations.shutdown2);
    assertTrue(MockImplementation1_EventAnnotations.shutdown3);
}
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) MockImplementation1_EventAnnotations(org.apache.cayenne.di.mock.MockImplementation1_EventAnnotations) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) Test(org.junit.Test)

Example 42 with MockInterface1

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

the class DefaultInjectorScopeTest method testSingletonScope_WithProvider.

@Test
public void testSingletonScope_WithProvider() {
    Module module = binder -> binder.bind(MockInterface1.class).toProvider(MockImplementation1_Provider.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) MockImplementation1_Provider(org.apache.cayenne.di.mock.MockImplementation1_Provider) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) Test(org.junit.Test)

Example 43 with MockInterface1

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

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

the class DefaultInjectorScopeTest method testNoScope_WithProvider.

@Test
public void testNoScope_WithProvider() {
    Module module = binder -> binder.bind(MockInterface1.class).toProvider(MockImplementation1_Provider.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);
}
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) MockImplementation1_Provider(org.apache.cayenne.di.mock.MockImplementation1_Provider) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) Module(org.apache.cayenne.di.Module) Test(org.junit.Test)

Example 45 with MockInterface1

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