use of com.tngtech.archunit.core.domain.JavaMethod in project ArchUnit by TNG.
the class ClassFileImporterAccessesTest method resolve.
// only temporary to make sure resolveMember() and resolve() are in sync. Inline again when we throw out resolve()
private JavaMethod resolve(MethodCallTarget target) {
JavaMethod method = target.resolveMember().get();
assertThat(target.resolve()).containsExactly(method);
return method;
}
use of com.tngtech.archunit.core.domain.JavaMethod in project ArchUnit by TNG.
the class ClassFileImporterAccessesTest method imports_own_set_field_access.
@Test
public void imports_own_set_field_access() {
JavaClass classWithOwnFieldAccess = new ClassFileImporter().importUrl(getClass().getResource("testexamples/fieldaccessimport")).get(OwnFieldAccess.class);
JavaMethod setStringValue = classWithOwnFieldAccess.getMethod("setStringValue", String.class);
JavaFieldAccess access = getOnlyElement(setStringValue.getFieldAccesses());
assertThatAccess(access).isOfType(SET).isFrom(setStringValue).isTo(classWithOwnFieldAccess.getField("stringValue")).inLineNumber(12);
}
use of com.tngtech.archunit.core.domain.JavaMethod in project ArchUnit by TNG.
the class ClassFileImporterAnnotationsTest method imports_empty_parameter_annotations_for_method_without_annotated_parameters.
@Test
public void imports_empty_parameter_annotations_for_method_without_annotated_parameters() {
JavaMethod method = new ClassFileImporter().importPackagesOf(ClassWithMethodWithAnnotatedParameters.class).get(ClassWithMethodWithAnnotatedParameters.class).getMethod(ClassWithMethodWithAnnotatedParameters.methodWithTwoUnannotatedParameters, String.class, int.class);
for (JavaParameter parameter : method.getParameters()) {
assertThat(parameter.getAnnotations()).isEmpty();
}
assertThat(method.getParameterAnnotations()).containsExactly(Collections.<JavaAnnotation<JavaParameter>>emptySet(), Collections.<JavaAnnotation<JavaParameter>>emptySet());
}
use of com.tngtech.archunit.core.domain.JavaMethod in project ArchUnit by TNG.
the class ClassFileImporterAnnotationsTest method methods_handle_optional_annotation_correctly.
@Test
public void methods_handle_optional_annotation_correctly() {
JavaMethod method = new ClassFileImporter().importPackagesOf(ClassWithAnnotatedMethods.class).get(ClassWithAnnotatedMethods.class).getMethod(stringAnnotatedMethod);
assertThat(method.tryGetAnnotationOfType(ClassWithAnnotatedMethods.MethodAnnotationWithStringValue.class)).isPresent();
assertThat(method.tryGetAnnotationOfType(ClassWithAnnotatedMethods.MethodAnnotationWithEnumAndArrayValue.class)).isEmpty();
Optional<JavaAnnotation<JavaMethod>> optionalAnnotation = method.tryGetAnnotationOfType(ClassWithAnnotatedMethods.MethodAnnotationWithStringValue.class.getName());
assertThat(optionalAnnotation.get().getOwner()).as("owner of optional annotation").isEqualTo(method);
assertThat(method.tryGetAnnotationOfType(ClassWithAnnotatedMethods.MethodAnnotationWithEnumAndArrayValue.class.getName())).isEmpty();
}
use of com.tngtech.archunit.core.domain.JavaMethod in project ArchUnit by TNG.
the class ClassFileImporterAnnotationsTest method imports_methods_with_one_annotation_correctly.
@Test
public void imports_methods_with_one_annotation_correctly() throws Exception {
JavaMethod method = new ClassFileImporter().importPackagesOf(ClassWithAnnotatedMethods.class).get(ClassWithAnnotatedMethods.class).getMethod(stringAnnotatedMethod);
JavaAnnotation<JavaMethod> annotation = method.getAnnotationOfType(ClassWithAnnotatedMethods.MethodAnnotationWithStringValue.class.getName());
assertThatType(annotation.getRawType()).matches(ClassWithAnnotatedMethods.MethodAnnotationWithStringValue.class);
assertThat(annotation.getOwner()).isEqualTo(method);
assertThat(annotation.get("value").get()).isEqualTo("something");
assertThat(method).isEquivalentTo(ClassWithAnnotatedMethods.class.getMethod(stringAnnotatedMethod));
}
Aggregations