Class AnnotationUtils


  • public final class AnnotationUtils
    extends Object
    Provides utility methods for obtaining annotations on test classes. This class is basically an adaptation of AnnotationSupport altered to include the element which was annotated in the result and filtered out to only contain methods we use.
    • Method Detail

      • findAnnotation

        public static <A extends AnnotationOptional<AnnotationContainer<A>> findAnnotation​(AnnotatedElement element,
                                                                                             Class<A> annotationType)
        Find the first annotation of annotationType that is either directly present, meta-present, or indirectly present on the supplied element.

        If the element is a class and the annotation is neither directly present nor meta-present on the class, this method will additionally search on interfaces implemented by the class before finding an annotation that is indirectly present on the class (meaning that the same process will be repeated for superclasses if Inherited is present on annotationType).

        Type Parameters:
        A - the annotation type
        Parameters:
        element - the element on which to search for the annotation; may be null
        annotationType - the annotation type to search for; never null
        Returns:
        an Optional containing the annotation and the element on which it was present; never null but potentially empty