Search in sources :

Example 1 with MockImplementation1_DepOn2

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

the class DefaultInjectorCircularInjectionTest method testFieldInjection_CircularDependency.

@Test
public void testFieldInjection_CircularDependency() {
    Module module = binder -> {
        binder.bind(MockInterface1.class).to(MockImplementation1_DepOn2.class);
        binder.bind(MockInterface2.class).to(MockImplementation2.class);
    };
    DefaultInjector injector = new DefaultInjector(module);
    try {
        injector.getInstance(MockInterface1.class);
        fail("Circular dependency is not detected.");
    } catch (DIRuntimeException e) {
    // expected
    } catch (StackOverflowError e) {
        fail("Circular dependency is not detected, causing stack overflow");
    }
}
Also used : MockImplementation2_Constructor(org.apache.cayenne.di.mock.MockImplementation2_Constructor) MockImplementation1_DepOn2(org.apache.cayenne.di.mock.MockImplementation1_DepOn2) Module(org.apache.cayenne.di.Module) MockImplementation2(org.apache.cayenne.di.mock.MockImplementation2) Test(org.junit.Test) MockImplementation3(org.apache.cayenne.di.mock.MockImplementation3) MockImplementation2_I3Dependency(org.apache.cayenne.di.mock.MockImplementation2_I3Dependency) MockImplementation1_DepOn2Constructor(org.apache.cayenne.di.mock.MockImplementation1_DepOn2Constructor) MockInterface2(org.apache.cayenne.di.mock.MockInterface2) MockInterface1(org.apache.cayenne.di.mock.MockInterface1) DIRuntimeException(org.apache.cayenne.di.DIRuntimeException) Assert.fail(org.junit.Assert.fail) MockImplementation1_DepOn2Provider(org.apache.cayenne.di.mock.MockImplementation1_DepOn2Provider) MockInterface3(org.apache.cayenne.di.mock.MockInterface3) Assert.assertEquals(org.junit.Assert.assertEquals) DIRuntimeException(org.apache.cayenne.di.DIRuntimeException) Module(org.apache.cayenne.di.Module) MockImplementation1_DepOn2(org.apache.cayenne.di.mock.MockImplementation1_DepOn2) MockImplementation2(org.apache.cayenne.di.mock.MockImplementation2) Test(org.junit.Test)

Aggregations

DIRuntimeException (org.apache.cayenne.di.DIRuntimeException)1 Module (org.apache.cayenne.di.Module)1 MockImplementation1_DepOn2 (org.apache.cayenne.di.mock.MockImplementation1_DepOn2)1 MockImplementation1_DepOn2Constructor (org.apache.cayenne.di.mock.MockImplementation1_DepOn2Constructor)1 MockImplementation1_DepOn2Provider (org.apache.cayenne.di.mock.MockImplementation1_DepOn2Provider)1 MockImplementation2 (org.apache.cayenne.di.mock.MockImplementation2)1 MockImplementation2_Constructor (org.apache.cayenne.di.mock.MockImplementation2_Constructor)1 MockImplementation2_I3Dependency (org.apache.cayenne.di.mock.MockImplementation2_I3Dependency)1 MockImplementation3 (org.apache.cayenne.di.mock.MockImplementation3)1 MockInterface1 (org.apache.cayenne.di.mock.MockInterface1)1 MockInterface2 (org.apache.cayenne.di.mock.MockInterface2)1 MockInterface3 (org.apache.cayenne.di.mock.MockInterface3)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.fail (org.junit.Assert.fail)1 Test (org.junit.Test)1