Reduce surface area of public API for AnnotationDescriptor types

This commit is contained in:
Sam Brannen 2020-10-24 22:45:17 +02:00
parent 946e5c9bbf
commit 1c82ba425b
2 changed files with 7 additions and 19 deletions

View File

@ -193,6 +193,7 @@ public abstract class TestContextAnnotationUtils {
public static <T extends Annotation> AnnotationDescriptor<T> findAnnotationDescriptor( public static <T extends Annotation> AnnotationDescriptor<T> findAnnotationDescriptor(
Class<?> clazz, Class<T> annotationType) { Class<?> clazz, Class<T> annotationType) {
Assert.notNull(annotationType, "Annotation type must not be null");
return findAnnotationDescriptor(clazz, annotationType, TestContextAnnotationUtils::searchEnclosingClass, return findAnnotationDescriptor(clazz, annotationType, TestContextAnnotationUtils::searchEnclosingClass,
new HashSet<>()); new HashSet<>());
} }
@ -214,7 +215,6 @@ public abstract class TestContextAnnotationUtils {
@Nullable Class<?> clazz, Class<T> annotationType, Predicate<Class<?>> searchEnclosingClass, @Nullable Class<?> clazz, Class<T> annotationType, Predicate<Class<?>> searchEnclosingClass,
Set<Annotation> visited) { Set<Annotation> visited) {
Assert.notNull(annotationType, "Annotation type must not be null");
if (clazz == null || Object.class == clazz) { if (clazz == null || Object.class == clazz) {
return null; return null;
} }
@ -515,7 +515,7 @@ public abstract class TestContextAnnotationUtils {
return this.declaringClass; return this.declaringClass;
} }
public T getAnnotation() { T getAnnotation() {
return this.annotation; return this.annotation;
} }
@ -533,21 +533,21 @@ public abstract class TestContextAnnotationUtils {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Class<T> getAnnotationType() { Class<T> getAnnotationType() {
return (Class<T>) this.annotation.annotationType(); return (Class<T>) this.annotation.annotationType();
} }
public AnnotationAttributes getAnnotationAttributes() { AnnotationAttributes getAnnotationAttributes() {
return this.annotationAttributes; return this.annotationAttributes;
} }
@Nullable @Nullable
public Annotation getComposedAnnotation() { Annotation getComposedAnnotation() {
return this.composedAnnotation; return this.composedAnnotation;
} }
@Nullable @Nullable
public Class<? extends Annotation> getComposedAnnotationType() { Class<? extends Annotation> getComposedAnnotationType() {
return (this.composedAnnotation != null ? this.composedAnnotation.annotationType() : null); return (this.composedAnnotation != null ? this.composedAnnotation.annotationType() : null);
} }
@ -633,16 +633,6 @@ public abstract class TestContextAnnotationUtils {
this.annotationTypes = annotationTypes; 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 * Find the next {@link UntypedAnnotationDescriptor} for the specified
* annotation types in the hierarchy above the * annotation types in the hierarchy above the

View File

@ -26,7 +26,6 @@ import java.util.Set;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextConfigurationAttributes; import org.springframework.test.context.ContextConfigurationAttributes;
import org.springframework.test.context.ContextHierarchy; import org.springframework.test.context.ContextHierarchy;
@ -127,8 +126,7 @@ abstract class ContextLoaderUtils {
List<ContextConfigurationAttributes> configAttributesList = new ArrayList<>(); List<ContextConfigurationAttributes> configAttributesList = new ArrayList<>();
if (contextConfigDeclaredLocally) { if (contextConfigDeclaredLocally) {
ContextConfiguration contextConfiguration = AnnotationUtils.synthesizeAnnotation( ContextConfiguration contextConfiguration = (ContextConfiguration) desc.synthesizeAnnotation();
desc.getAnnotationAttributes(), ContextConfiguration.class, desc.getRootDeclaringClass());
convertContextConfigToConfigAttributesAndAddToList( convertContextConfigToConfigAttributesAndAddToList(
contextConfiguration, rootDeclaringClass, configAttributesList); contextConfiguration, rootDeclaringClass, configAttributesList);
} }