use of com.tngtech.archunit.core.domain.JavaClass 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.domain.JavaClass 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.domain.JavaClass 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");
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassFileImporterAutomaticResolutionTest method automatically_resolves_parameter_annotations.
@Test
public void automatically_resolves_parameter_annotations() {
JavaClass clazz = ImporterWithAdjustedResolutionRuns.disableAllIterationsExcept(MAX_ITERATIONS_FOR_ANNOTATION_TYPES_PROPERTY_NAME).importClass(ClassWithMethodWithAnnotatedParameters.class);
JavaAnnotation<?> annotation = clazz.getMethod(methodWithOneAnnotatedParameterWithTwoAnnotations, String.class).getParameters().get(0).getAnnotationOfType(SomeParameterAnnotation.class.getName());
assertThat(annotation.getRawType()).isFullyImported(true);
assertThat((JavaEnumConstant) annotation.get("value").get()).isEquivalentTo(OTHER_VALUE);
assertThat((JavaEnumConstant) annotation.get("valueWithDefault").get()).isEquivalentTo(SOME_VALUE);
SomeParameterAnnotation reflected = annotation.as(SomeParameterAnnotation.class);
assertThat(reflected.value()).isEqualTo(OTHER_VALUE);
assertThat(reflected.valueWithDefault()).isEqualTo(SOME_VALUE);
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassFileImporterAutomaticResolutionTest method automatically_resolves_constructor_call_target_owners.
@Test
public void automatically_resolves_constructor_call_target_owners() {
class Target {
}
@SuppressWarnings("unused")
class Origin {
void resolvesConstructorCallTargetOwner() {
new Target();
}
}
JavaClass javaClass = ImporterWithAdjustedResolutionRuns.disableAllIterationsExcept(MAX_ITERATIONS_FOR_ACCESSES_TO_TYPES_PROPERTY_NAME).importClass(Origin.class);
JavaConstructorCall call = getOnlyElement(javaClass.getMethod("resolvesConstructorCallTargetOwner").getConstructorCallsFromSelf());
assertThat(call.getTargetOwner()).isFullyImported(true);
}
Aggregations