diff --git a/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java b/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java index 1469160cc1..ff88ade862 100644 --- a/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java @@ -179,7 +179,7 @@ abstract class BootstrapUtils { } private static Class> resolveDefaultTestContextBootstrapper(Class> testClass) throws Exception { - boolean webApp = (TestContextAnnotationUtils.findMergedAnnotation(testClass, webAppConfigurationClass) != null); + boolean webApp = TestContextAnnotationUtils.hasAnnotation(testClass, webAppConfigurationClass); String bootstrapperClassName = (webApp ? DEFAULT_WEB_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME : DEFAULT_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME); return ClassUtils.forName(bootstrapperClassName, BootstrapUtils.class.getClassLoader()); diff --git a/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java b/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java index 1c01b0a07e..4d8550e6f2 100644 --- a/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java @@ -78,6 +78,22 @@ public abstract class TestContextAnnotationUtils { private static volatile EnclosingConfiguration defaultEnclosingConfigurationMode; + /** + * Determine if an annotation of the specified {@code annotationType} is + * present or meta-present on the supplied {@link Class} according to the + * search algorithm used in {@link #findMergedAnnotation(Class, Class)}. + *
If this method returns {@code true}, then {@code findMergedAnnotation(...)} + * will return a non-null value. + * @param clazz the class to look for annotations on + * @param annotationType the type of annotation to look for + * @return {@code true} if a matching annotation is present + * @since 5.3.3 + * @see #findMergedAnnotation(Class, Class) + */ + public static boolean hasAnnotation(Class> clazz, Class extends Annotation> annotationType) { + return (findMergedAnnotation(clazz, annotationType) != null); + } + /** * Find the first annotation of the specified {@code annotationType} within * the annotation hierarchy above the supplied class, merge that