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