Skip to content

Commit b3a47c7

Browse files
committed
Introduce TestContextAnnotationUtils.hasAnnotation()
1 parent 1292947 commit b3a47c7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClas
179179
}
180180

181181
private static Class<?> resolveDefaultTestContextBootstrapper(Class<?> testClass) throws Exception {
182-
boolean webApp = (TestContextAnnotationUtils.findMergedAnnotation(testClass, webAppConfigurationClass) != null);
182+
boolean webApp = TestContextAnnotationUtils.hasAnnotation(testClass, webAppConfigurationClass);
183183
String bootstrapperClassName = (webApp ? DEFAULT_WEB_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME :
184184
DEFAULT_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME);
185185
return ClassUtils.forName(bootstrapperClassName, BootstrapUtils.class.getClassLoader());

spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ public abstract class TestContextAnnotationUtils {
7878
private static volatile EnclosingConfiguration defaultEnclosingConfigurationMode;
7979

8080

81+
/**
82+
* Determine if an annotation of the specified {@code annotationType} is
83+
* present or meta-present on the supplied {@link Class} according to the
84+
* search algorithm used in {@link #findMergedAnnotation(Class, Class)}.
85+
* <p>If this method returns {@code true}, then {@code findMergedAnnotation(...)}
86+
* will return a non-null value.
87+
* @param clazz the class to look for annotations on
88+
* @param annotationType the type of annotation to look for
89+
* @return {@code true} if a matching annotation is present
90+
* @since 5.3.3
91+
* @see #findMergedAnnotation(Class, Class)
92+
*/
93+
public static boolean hasAnnotation(Class<?> clazz, Class<? extends Annotation> annotationType) {
94+
return (findMergedAnnotation(clazz, annotationType) != null);
95+
}
96+
8197
/**
8298
* Find the first annotation of the specified {@code annotationType} within
8399
* the annotation hierarchy <em>above</em> the supplied class, merge that

0 commit comments

Comments
 (0)