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 a92a7c29a9..ac6087c468 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 @@ -193,6 +193,7 @@ public abstract class TestContextAnnotationUtils { public static AnnotationDescriptor findAnnotationDescriptor( Class clazz, Class annotationType) { + Assert.notNull(annotationType, "Annotation type must not be null"); return findAnnotationDescriptor(clazz, annotationType, TestContextAnnotationUtils::searchEnclosingClass, new HashSet<>()); } @@ -214,7 +215,6 @@ public abstract class TestContextAnnotationUtils { @Nullable Class clazz, Class annotationType, Predicate> searchEnclosingClass, Set visited) { - Assert.notNull(annotationType, "Annotation type must not be null"); if (clazz == null || Object.class == clazz) { return null; } @@ -515,7 +515,7 @@ public abstract class TestContextAnnotationUtils { return this.declaringClass; } - public T getAnnotation() { + T getAnnotation() { return this.annotation; } @@ -533,21 +533,21 @@ public abstract class TestContextAnnotationUtils { } @SuppressWarnings("unchecked") - public Class getAnnotationType() { + Class getAnnotationType() { return (Class) this.annotation.annotationType(); } - public AnnotationAttributes getAnnotationAttributes() { + AnnotationAttributes getAnnotationAttributes() { return this.annotationAttributes; } @Nullable - public Annotation getComposedAnnotation() { + Annotation getComposedAnnotation() { return this.composedAnnotation; } @Nullable - public Class getComposedAnnotationType() { + Class getComposedAnnotationType() { return (this.composedAnnotation != null ? this.composedAnnotation.annotationType() : null); } @@ -633,16 +633,6 @@ public abstract class TestContextAnnotationUtils { this.annotationTypes = annotationTypes; } - /** - * Throws an {@link UnsupportedOperationException} since the type of annotation - * represented by an {@code UntypedAnnotationDescriptor} is unknown. - */ - @Override - public Annotation synthesizeAnnotation() { - throw new UnsupportedOperationException( - "synthesizeAnnotation() is unsupported in UntypedAnnotationDescriptor"); - } - /** * Find the next {@link UntypedAnnotationDescriptor} for the specified * annotation types in the hierarchy above the diff --git a/spring-test/src/main/java/org/springframework/test/context/support/ContextLoaderUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/ContextLoaderUtils.java index db082c4720..d7bf5243dc 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/ContextLoaderUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/ContextLoaderUtils.java @@ -26,7 +26,6 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.core.annotation.AnnotationUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfigurationAttributes; import org.springframework.test.context.ContextHierarchy; @@ -127,8 +126,7 @@ abstract class ContextLoaderUtils { List configAttributesList = new ArrayList<>(); if (contextConfigDeclaredLocally) { - ContextConfiguration contextConfiguration = AnnotationUtils.synthesizeAnnotation( - desc.getAnnotationAttributes(), ContextConfiguration.class, desc.getRootDeclaringClass()); + ContextConfiguration contextConfiguration = (ContextConfiguration) desc.synthesizeAnnotation(); convertContextConfigToConfigAttributesAndAddToList( contextConfiguration, rootDeclaringClass, configAttributesList); }