Skip to content

Commit 1c82ba4

Browse files
committed
Reduce surface area of public API for AnnotationDescriptor types
1 parent 946e5c9 commit 1c82ba4

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ public static <T extends Annotation> Set<T> getMergedRepeatableAnnotations(
193193
public static <T extends Annotation> AnnotationDescriptor<T> findAnnotationDescriptor(
194194
Class<?> clazz, Class<T> annotationType) {
195195

196+
Assert.notNull(annotationType, "Annotation type must not be null");
196197
return findAnnotationDescriptor(clazz, annotationType, TestContextAnnotationUtils::searchEnclosingClass,
197198
new HashSet<>());
198199
}
@@ -214,7 +215,6 @@ private static <T extends Annotation> AnnotationDescriptor<T> findAnnotationDesc
214215
@Nullable Class<?> clazz, Class<T> annotationType, Predicate<Class<?>> searchEnclosingClass,
215216
Set<Annotation> visited) {
216217

217-
Assert.notNull(annotationType, "Annotation type must not be null");
218218
if (clazz == null || Object.class == clazz) {
219219
return null;
220220
}
@@ -515,7 +515,7 @@ public Class<?> getDeclaringClass() {
515515
return this.declaringClass;
516516
}
517517

518-
public T getAnnotation() {
518+
T getAnnotation() {
519519
return this.annotation;
520520
}
521521

@@ -533,21 +533,21 @@ public T synthesizeAnnotation() {
533533
}
534534

535535
@SuppressWarnings("unchecked")
536-
public Class<T> getAnnotationType() {
536+
Class<T> getAnnotationType() {
537537
return (Class<T>) this.annotation.annotationType();
538538
}
539539

540-
public AnnotationAttributes getAnnotationAttributes() {
540+
AnnotationAttributes getAnnotationAttributes() {
541541
return this.annotationAttributes;
542542
}
543543

544544
@Nullable
545-
public Annotation getComposedAnnotation() {
545+
Annotation getComposedAnnotation() {
546546
return this.composedAnnotation;
547547
}
548548

549549
@Nullable
550-
public Class<? extends Annotation> getComposedAnnotationType() {
550+
Class<? extends Annotation> getComposedAnnotationType() {
551551
return (this.composedAnnotation != null ? this.composedAnnotation.annotationType() : null);
552552
}
553553

@@ -633,16 +633,6 @@ public static class UntypedAnnotationDescriptor extends AnnotationDescriptor<Ann
633633
this.annotationTypes = annotationTypes;
634634
}
635635

636-
/**
637-
* Throws an {@link UnsupportedOperationException} since the type of annotation
638-
* represented by an {@code UntypedAnnotationDescriptor} is unknown.
639-
*/
640-
@Override
641-
public Annotation synthesizeAnnotation() {
642-
throw new UnsupportedOperationException(
643-
"synthesizeAnnotation() is unsupported in UntypedAnnotationDescriptor");
644-
}
645-
646636
/**
647637
* Find the next {@link UntypedAnnotationDescriptor} for the specified
648638
* annotation types in the hierarchy above the

spring-test/src/main/java/org/springframework/test/context/support/ContextLoaderUtils.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.commons.logging.Log;
2727
import org.apache.commons.logging.LogFactory;
2828

29-
import org.springframework.core.annotation.AnnotationUtils;
3029
import org.springframework.test.context.ContextConfiguration;
3130
import org.springframework.test.context.ContextConfigurationAttributes;
3231
import org.springframework.test.context.ContextHierarchy;
@@ -127,8 +126,7 @@ static List<List<ContextConfigurationAttributes>> resolveContextHierarchyAttribu
127126
List<ContextConfigurationAttributes> configAttributesList = new ArrayList<>();
128127

129128
if (contextConfigDeclaredLocally) {
130-
ContextConfiguration contextConfiguration = AnnotationUtils.synthesizeAnnotation(
131-
desc.getAnnotationAttributes(), ContextConfiguration.class, desc.getRootDeclaringClass());
129+
ContextConfiguration contextConfiguration = (ContextConfiguration) desc.synthesizeAnnotation();
132130
convertContextConfigToConfigAttributesAndAddToList(
133131
contextConfiguration, rootDeclaringClass, configAttributesList);
134132
}

0 commit comments

Comments
 (0)