From 38b67c9a8f1cce88c0e7182ac9cac3ccf7b8d816 Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Sun, 12 Jan 2025 20:06:10 +0900 Subject: [PATCH] Update document Issue: #4058 --- .../src/docs/asciidoc/user-guide/extensions.adoc | 8 ++++++-- .../jupiter/api/extension/AnnotatedElementContext.java | 4 ++++ .../platform/commons/support/AnnotationSupport.java | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/documentation/src/docs/asciidoc/user-guide/extensions.adoc b/documentation/src/docs/asciidoc/user-guide/extensions.adoc index 7ccbf96c4df2..52a257141ea8 100644 --- a/documentation/src/docs/asciidoc/user-guide/extensions.adoc +++ b/documentation/src/docs/asciidoc/user-guide/extensions.adoc @@ -868,8 +868,12 @@ order to align with the behavior of the JUnit Platform and JUnit Jupiter. These include methods to check whether an element is annotated or meta-annotated with a particular annotation, to search for specific annotations, and to find annotated methods and fields in a class or interface. Some of these methods search on implemented -interfaces and within class hierarchies to find annotations. Consult the Javadoc for -`{AnnotationSupport}` for further details. +interfaces and within class hierarchies to find annotations. + +**Note:** `isAnnotated` method does not find repeatable annotations. To check for repeatable annotations, +use the `findRepeatableAnnotations` method and verify that the returned list is not empty. + +Consult the Javadoc for `{AnnotationSupport}` for further details. NOTE: See also: <> diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/AnnotatedElementContext.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/AnnotatedElementContext.java index 0c12f33c1765..74280f445c0f 100644 --- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/AnnotatedElementContext.java +++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/AnnotatedElementContext.java @@ -55,6 +55,10 @@ public interface AnnotatedElementContext { * present or meta-present on the {@link AnnotatedElement} for * this context. * + *

Note: This method does not find repeatable annotations. + * To check for repeatable annotations, use {@link #findRepeatableAnnotations(Class)} + * and verify that the returned list is not empty. + * *

WARNING

*

Favor the use of this method over directly invoking * {@link AnnotatedElement#isAnnotationPresent(Class)} due to a bug in {@code javac} diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/support/AnnotationSupport.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/support/AnnotationSupport.java index 2ef21ac9d0c3..4555bb4c0ba2 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/support/AnnotationSupport.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/support/AnnotationSupport.java @@ -54,6 +54,10 @@ private AnnotationSupport() { * present or meta-present on the supplied optional * {@code element}. * + *

Note: This method does not find repeatable annotations. + * To check for repeatable annotations, use {@link #findRepeatableAnnotations(Optional, Class)} + * and verify that the returned list is not empty. + * * @param element an {@link Optional} containing the element on which to * search for the annotation; may be {@code null} or empty * @param annotationType the annotation type to search for; never {@code null} @@ -61,6 +65,7 @@ private AnnotationSupport() { * @since 1.3 * @see #isAnnotated(AnnotatedElement, Class) * @see #findAnnotation(Optional, Class) + * @see #findRepeatableAnnotations(Optional, Class) */ @API(status = MAINTAINED, since = "1.3") public static boolean isAnnotated(Optional element, @@ -74,12 +79,17 @@ public static boolean isAnnotated(Optional element, * present or meta-present on the supplied * {@code element}. * + *

Note: This method does not find repeatable annotations. + * To check for repeatable annotations, use {@link #findRepeatableAnnotations(Optional, Class)} + * and verify that the returned list is not empty. + * * @param element the element on which to search for the annotation; may be * {@code null} * @param annotationType the annotation type to search for; never {@code null} * @return {@code true} if the annotation is present or meta-present * @see #isAnnotated(Optional, Class) * @see #findAnnotation(AnnotatedElement, Class) + * @see #findRepeatableAnnotations(Optional, Class) */ public static boolean isAnnotated(AnnotatedElement element, Class annotationType) { return AnnotationUtils.isAnnotated(element, annotationType);