Search in sources :

Example 1 with ClassWithInnerClass

use of com.tngtech.archunit.core.importer.testexamples.innerclassimport.ClassWithInnerClass in project ArchUnit by TNG.

the class ClassFileImporterTest method imports_enclosing_classes.

@Test
public void imports_enclosing_classes() {
    JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/innerclassimport"));
    JavaClass classWithInnerClass = classes.get(ClassWithInnerClass.class);
    JavaClass innerClass = classes.get(ClassWithInnerClass.Inner.class);
    JavaClass anonymousClass = classes.get(ClassWithInnerClass.class.getName() + "$1");
    JavaClass localClass = classes.get(ClassWithInnerClass.class.getName() + "$1LocalCaller");
    JavaMethod calledTarget = getOnlyElement(classes.get(CalledClass.class).getMethods());
    assertThat(innerClass.getEnclosingClass()).contains(classWithInnerClass);
    assertThat(anonymousClass.getEnclosingClass()).contains(classWithInnerClass);
    assertThat(localClass.getEnclosingClass()).contains(classWithInnerClass);
    JavaMethodCall call = getOnlyElement(innerClass.getCodeUnitWithParameterTypes("call").getMethodCallsFromSelf());
    assertThatCall(call).isFrom("call").isTo(calledTarget).inLineNumber(31);
    call = getOnlyElement(anonymousClass.getCodeUnitWithParameterTypes("call").getMethodCallsFromSelf());
    assertThatCall(call).isFrom("call").isTo(calledTarget).inLineNumber(11);
    call = getOnlyElement(localClass.getCodeUnitWithParameterTypes("call").getMethodCallsFromSelf());
    assertThatCall(call).isFrom("call").isTo(calledTarget).inLineNumber(21);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) JavaClass(com.tngtech.archunit.core.domain.JavaClass) ClassWithInnerClass(com.tngtech.archunit.core.importer.testexamples.innerclassimport.ClassWithInnerClass) JavaMethod(com.tngtech.archunit.core.domain.JavaMethod) JavaMethodCall(com.tngtech.archunit.core.domain.JavaMethodCall) Test(org.junit.Test)

Aggregations

JavaClass (com.tngtech.archunit.core.domain.JavaClass)1 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)1 JavaMethod (com.tngtech.archunit.core.domain.JavaMethod)1 JavaMethodCall (com.tngtech.archunit.core.domain.JavaMethodCall)1 ClassWithInnerClass (com.tngtech.archunit.core.importer.testexamples.innerclassimport.ClassWithInnerClass)1 Test (org.junit.Test)1