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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations