use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassFileImporterAnnotationsTest method imports_simple_annotation.
@Test
public void imports_simple_annotation() {
JavaClass javaClass = new ClassFileImporter().importPackagesOf(AnnotationToImport.class).get(AnnotationToImport.class);
assertThat(javaClass).matches(AnnotationToImport.class).hasNoSuperclass().hasInterfacesMatchingInAnyOrder(Annotation.class).isInterface(true).isEnum(false).isAnnotation(true).isRecord(false);
assertThat(getAnnotationDefaultValue(javaClass, "someStringMethod", String.class)).isEqualTo("DEFAULT");
assertThatType(getAnnotationDefaultValue(javaClass, "someTypeMethod", JavaClass.class)).matches(List.class);
assertThat(getAnnotationDefaultValue(javaClass, "someEnumMethod", JavaEnumConstant.class)).isEquivalentTo(EnumToImport.SECOND);
assertThatType(getAnnotationDefaultValue(javaClass, "someAnnotationMethod", JavaAnnotation.class).getRawType()).matches(AnnotationParameter.class);
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassFileImporterAnnotationsTest method imports_class_with_annotation_with_empty_array.
@Test
public void imports_class_with_annotation_with_empty_array() {
JavaClass clazz = new ClassFileImporter().importPackagesOf(ClassWithAnnotationWithEmptyArrays.class).get(ClassWithAnnotationWithEmptyArrays.class);
JavaAnnotation<?> annotation = clazz.getAnnotationOfType(ClassAnnotationWithArrays.class.getName());
assertThat(Array.getLength(annotation.get("primitives").get())).isZero();
assertThat(Array.getLength(annotation.get("objects").get())).isZero();
assertThat(Array.getLength(annotation.get("enums").get())).isZero();
assertThat(Array.getLength(annotation.get("classes").get())).isZero();
assertThat(Array.getLength(annotation.get("annotations").get())).isZero();
ClassAnnotationWithArrays reflected = clazz.getAnnotationOfType(ClassAnnotationWithArrays.class);
assertThat(reflected.primitives()).isEmpty();
assertThat(reflected.objects()).isEmpty();
assertThat(reflected.enums()).isEmpty();
assertThat(reflected.classes()).isEmpty();
assertThat(reflected.annotations()).isEmpty();
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassFileImporterAnnotationsTest method imports_method_with_annotation_with_empty_array.
@Test
public void imports_method_with_annotation_with_empty_array() {
JavaClass clazz = new ClassFileImporter().importPackagesOf(ClassWithAnnotatedMethods.class).get(ClassWithAnnotatedMethods.class);
JavaAnnotation<?> annotation = clazz.getMethod(methodAnnotatedWithEmptyArrays).getAnnotationOfType(MethodAnnotationWithArrays.class.getName());
assertThat(Array.getLength(annotation.get("primitives").get())).isZero();
assertThat(Array.getLength(annotation.get("objects").get())).isZero();
assertThat(Array.getLength(annotation.get("enums").get())).isZero();
assertThat(Array.getLength(annotation.get("classes").get())).isZero();
assertThat(Array.getLength(annotation.get("annotations").get())).isZero();
MethodAnnotationWithArrays reflected = annotation.as(MethodAnnotationWithArrays.class);
assertThat(reflected.primitives()).isEmpty();
assertThat(reflected.objects()).isEmpty();
assertThat(reflected.enums()).isEmpty();
assertThat(reflected.classes()).isEmpty();
assertThat(reflected.annotations()).isEmpty();
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassFileImporterAutomaticResolutionTest method automatically_resolves_field_types.
@Test
public void automatically_resolves_field_types() {
@SuppressWarnings("unused")
class FieldTypeWithoutAnyFurtherReference {
String field;
}
JavaClass javaClass = ImporterWithAdjustedResolutionRuns.disableAllIterationsExcept(MAX_ITERATIONS_FOR_MEMBER_TYPES_PROPERTY_NAME).importClass(FieldTypeWithoutAnyFurtherReference.class);
assertThat(javaClass.getField("field").getRawType()).as("field type").isFullyImported(true);
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassFileImporterAutomaticResolutionTest method automatically_resolves_method_return_types.
@Test
public void automatically_resolves_method_return_types() {
@SuppressWarnings("unused")
class MemberTypesWithoutAnyFurtherReference {
File returnType() {
return null;
}
}
JavaClass javaClass = ImporterWithAdjustedResolutionRuns.disableAllIterationsExcept(MAX_ITERATIONS_FOR_MEMBER_TYPES_PROPERTY_NAME).importClass(MemberTypesWithoutAnyFurtherReference.class);
assertThat(javaClass.getMethod("returnType").getRawReturnType()).as("method return type").isFullyImported(true);
}
Aggregations