Search in sources :

Example 86 with JavaClass

use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.

the class ClassFileImporterAutomaticResolutionTest method automatically_resolves_class_hierarchy.

@Test
public void automatically_resolves_class_hierarchy() {
    JavaClass child = ImporterWithAdjustedResolutionRuns.disableAllIterationsExcept(MAX_ITERATIONS_FOR_SUPERTYPES_PROPERTY_NAME).importClass(Child.class);
    JavaClass parent = child.getRawSuperclass().get();
    assertThat(parent).isFullyImported(true);
    JavaClass grandparent = parent.getRawSuperclass().get();
    assertThat(grandparent).isFullyImported(true);
    JavaClass parentInterfaceDirect = getOnlyElement(child.getRawInterfaces());
    assertThat(parentInterfaceDirect).isFullyImported(true);
    JavaClass grandParentInterfaceDirect = getOnlyElement(parentInterfaceDirect.getRawInterfaces());
    assertThat(grandParentInterfaceDirect).isFullyImported(true);
    JavaClass grandParentInterfaceIndirect = getOnlyElement(getOnlyElement(grandparent.getRawInterfaces()).getRawInterfaces());
    assertThat(grandParentInterfaceIndirect).isFullyImported(true);
}
Also used : JavaClass(com.tngtech.archunit.core.domain.JavaClass) Test(org.junit.Test)

Example 87 with JavaClass

use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.

the class ClassFileImporterAutomaticResolutionTest method automatically_resolves_method_reference_target_owners.

@Test
public void automatically_resolves_method_reference_target_owners() {
    class Target {

        void method() {
        }
    }
    @SuppressWarnings({ "unused", "ConstantConditions" })
    class Origin {

        Runnable resolvesMethodCallTargetOwner() {
            Target target = null;
            return target::method;
        }
    }
    JavaClass javaClass = ImporterWithAdjustedResolutionRuns.disableAllIterationsExcept(MAX_ITERATIONS_FOR_ACCESSES_TO_TYPES_PROPERTY_NAME).importClass(Origin.class);
    JavaMethodReference reference = getOnlyElement(javaClass.getMethodReferencesFromSelf());
    assertThat(reference.getTargetOwner()).isFullyImported(true);
}
Also used : JavaMethodReference(com.tngtech.archunit.core.domain.JavaMethodReference) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Test(org.junit.Test)

Example 88 with JavaClass

use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.

the class ClassFileImporterAutomaticResolutionTest method automatically_resolves_meta_annotation_types.

@Test
public void automatically_resolves_meta_annotation_types() {
    JavaClass javaClass = ImporterWithAdjustedResolutionRuns.disableAllIterationsExcept(MAX_ITERATIONS_FOR_ANNOTATION_TYPES_PROPERTY_NAME).importClass(MetaAnnotatedClass.class);
    JavaAnnotation<JavaClass> someAnnotation = javaClass.getAnnotationOfType(MetaAnnotatedAnnotation.class.getName());
    JavaAnnotation<JavaClass> someMetaAnnotation = someAnnotation.getRawType().getAnnotationOfType(SomeMetaAnnotation.class.getName());
    JavaAnnotation<JavaClass> someMetaMetaAnnotation = someMetaAnnotation.getRawType().getAnnotationOfType(SomeMetaMetaAnnotation.class.getName());
    JavaAnnotation<JavaClass> someMetaMetaMetaAnnotation = someMetaMetaAnnotation.getRawType().getAnnotationOfType(SomeMetaMetaMetaAnnotationWithParameters.class.getName());
    assertThatType(someMetaMetaMetaAnnotation.getType()).matches(SomeMetaMetaMetaAnnotationWithParameters.class);
}
Also used : JavaClass(com.tngtech.archunit.core.domain.JavaClass) Test(org.junit.Test)

Example 89 with JavaClass

use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.

the class ClassFileImporterAutomaticResolutionTest method automatically_resolves_class_objects.

@Test
public void automatically_resolves_class_objects() {
    @SuppressWarnings("unused")
    class Origin {

        Class<?> call() {
            return String.class;
        }
    }
    JavaClass javaClass = ImporterWithAdjustedResolutionRuns.disableAllIterationsExcept(MAX_ITERATIONS_FOR_ACCESSES_TO_TYPES_PROPERTY_NAME).importClass(Origin.class);
    ReferencedClassObject classObject = getOnlyElement(javaClass.getReferencedClassObjects());
    assertThat(classObject.getRawType()).isFullyImported(true);
    assertThatType(classObject.getRawType()).matches(String.class);
}
Also used : JavaClass(com.tngtech.archunit.core.domain.JavaClass) ReferencedClassObject(com.tngtech.archunit.core.domain.ReferencedClassObject) Test(org.junit.Test)

Example 90 with JavaClass

use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.

the class ClassFileImporterAutomaticResolutionTest method importFirstTypeArgumentMethodParameterBound.

private static JavaType importFirstTypeArgumentMethodParameterBound(Class<?> clazz) {
    JavaClass javaClass = ImporterWithAdjustedResolutionRuns.disableAllIterationsExcept(MAX_ITERATIONS_FOR_GENERIC_SIGNATURE_TYPES_PROPERTY_NAME, MAX_ITERATIONS_FOR_GENERIC_SIGNATURE_TYPES_DEFAULT_VALUE).importClass(clazz);
    JavaMethod method = getOnlyElement(javaClass.getMethods());
    return getFirstTypeArgumentUpperBound(method.getParameterTypes().get(0));
}
Also used : JavaClass(com.tngtech.archunit.core.domain.JavaClass) JavaMethod(com.tngtech.archunit.core.domain.JavaMethod)

Aggregations

JavaClass (com.tngtech.archunit.core.domain.JavaClass)234 Test (org.junit.Test)183 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)65 JavaMethod (com.tngtech.archunit.core.domain.JavaMethod)42 ConditionEvents (com.tngtech.archunit.lang.ConditionEvents)25 ArchCondition (com.tngtech.archunit.lang.ArchCondition)24 SimpleConditionEvent (com.tngtech.archunit.lang.SimpleConditionEvent)20 JavaMethodCall (com.tngtech.archunit.core.domain.JavaMethodCall)19 List (java.util.List)19 JavaFieldAccess (com.tngtech.archunit.core.domain.JavaFieldAccess)16 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)15 DescribedPredicate (com.tngtech.archunit.base.DescribedPredicate)12 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)12 Serializable (java.io.Serializable)12 JavaField (com.tngtech.archunit.core.domain.JavaField)11 Test (org.junit.jupiter.api.Test)11 JavaCodeUnit (com.tngtech.archunit.core.domain.JavaCodeUnit)10 JavaConstructor (com.tngtech.archunit.core.domain.JavaConstructor)10 Collectors (java.util.stream.Collectors)10 JavaType (com.tngtech.archunit.core.domain.JavaType)9