Browse Source

Introduce TestContextAnnotationUtils.hasAnnotation()

pull/26286/head
Sam Brannen 5 years ago
parent
commit
b3a47c76f8
  1. 2
      spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java
  2. 16
      spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java

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

@ -179,7 +179,7 @@ abstract class BootstrapUtils { @@ -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());

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

@ -78,6 +78,22 @@ public abstract class TestContextAnnotationUtils { @@ -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)}.
* <p>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 <em>above</em> the supplied class, merge that

Loading…
Cancel
Save