use of com.tngtech.archunit.core.importer.testexamples.SomeAnnotation in project ArchUnit by TNG.
the class ClassFileImporterAutomaticResolutionTest method automatically_resolves_field_annotations.
@Test
public void automatically_resolves_field_annotations() {
JavaClass clazz = ImporterWithAdjustedResolutionRuns.disableAllIterationsExcept(MAX_ITERATIONS_FOR_ANNOTATION_TYPES_PROPERTY_NAME).importClass(ClassWithAnnotatedFields.class);
JavaAnnotation<?> annotation = clazz.getField("fieldAnnotatedWithAnnotationFromParentPackage").getAnnotationOfType(SomeAnnotation.class.getName());
assertThat(annotation.getRawType()).isFullyImported(true);
assertThat(annotation.get("mandatory")).contains("mandatory");
assertThat(annotation.get("optional")).contains("optional");
SomeAnnotation reflected = annotation.as(SomeAnnotation.class);
assertThat(reflected.mandatory()).isEqualTo("mandatory");
assertThat(reflected.optional()).isEqualTo("optional");
}
use of com.tngtech.archunit.core.importer.testexamples.SomeAnnotation in project ArchUnit by TNG.
the class ClassFileImporterAutomaticResolutionTest method automatically_resolves_class_annotations.
@Test
public void automatically_resolves_class_annotations() {
JavaClass clazz = ImporterWithAdjustedResolutionRuns.disableAllIterationsExcept(MAX_ITERATIONS_FOR_ANNOTATION_TYPES_PROPERTY_NAME).importClass(ClassWithUnimportedAnnotation.class);
JavaAnnotation<?> annotation = clazz.getAnnotationOfType(SomeAnnotation.class.getName());
assertThat(annotation.getRawType()).isFullyImported(true);
assertThat(annotation.get("mandatory")).contains("mandatory");
assertThat(annotation.get("optional")).contains("optional");
assertThat((JavaEnumConstant) annotation.get("mandatoryEnum").get()).isEquivalentTo(SOME_VALUE);
assertThat((JavaEnumConstant) annotation.get("optionalEnum").get()).isEquivalentTo(OTHER_VALUE);
SomeAnnotation reflected = clazz.getAnnotationOfType(SomeAnnotation.class);
assertThat(reflected.mandatory()).isEqualTo("mandatory");
assertThat(reflected.optional()).isEqualTo("optional");
assertThat(reflected.mandatoryEnum()).isEqualTo(SOME_VALUE);
assertThat(reflected.optionalEnum()).isEqualTo(OTHER_VALUE);
}
use of com.tngtech.archunit.core.importer.testexamples.SomeAnnotation in project ArchUnit by TNG.
the class ClassFileImporterAutomaticResolutionTest method automatically_resolves_method_annotations.
@Test
public void automatically_resolves_method_annotations() {
JavaClass clazz = ImporterWithAdjustedResolutionRuns.disableAllIterationsExcept(MAX_ITERATIONS_FOR_ANNOTATION_TYPES_PROPERTY_NAME).importClass(ClassWithAnnotatedMethods.class);
JavaAnnotation<?> annotation = clazz.getMethod(methodAnnotatedWithAnnotationFromParentPackage).getAnnotationOfType(SomeAnnotation.class.getName());
assertThat(annotation.getRawType()).isFullyImported(true);
assertThat(annotation.get("mandatory")).contains("mandatory");
assertThat(annotation.get("optional")).contains("optional");
SomeAnnotation reflected = annotation.as(SomeAnnotation.class);
assertThat(reflected.mandatory()).isEqualTo("mandatory");
assertThat(reflected.optional()).isEqualTo("optional");
}
Aggregations