Search in sources :

Example 1 with SomeAnnotation

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");
}
Also used : JavaClass(com.tngtech.archunit.core.domain.JavaClass) SomeAnnotation(com.tngtech.archunit.core.importer.testexamples.SomeAnnotation) Test(org.junit.Test)

Example 2 with SomeAnnotation

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);
}
Also used : JavaClass(com.tngtech.archunit.core.domain.JavaClass) SomeAnnotation(com.tngtech.archunit.core.importer.testexamples.SomeAnnotation) JavaEnumConstant(com.tngtech.archunit.core.domain.JavaEnumConstant) Test(org.junit.Test)

Example 3 with SomeAnnotation

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");
}
Also used : JavaClass(com.tngtech.archunit.core.domain.JavaClass) SomeAnnotation(com.tngtech.archunit.core.importer.testexamples.SomeAnnotation) Test(org.junit.Test)

Aggregations

JavaClass (com.tngtech.archunit.core.domain.JavaClass)3 SomeAnnotation (com.tngtech.archunit.core.importer.testexamples.SomeAnnotation)3 Test (org.junit.Test)3 JavaEnumConstant (com.tngtech.archunit.core.domain.JavaEnumConstant)1