attributes,
@@ -1275,6 +1277,26 @@ public abstract class AnnotationUtils {
return synthesizedAnnotation;
}
+ /**
+ * Synthesize an annotation from its default attributes values.
+ * This method simply delegates to
+ * {@link #synthesizeAnnotation(Map, Class, AnnotatedElement)},
+ * supplying an empty map for the source attribute values and {@code null}
+ * for the {@link AnnotatedElement}.
+ *
+ * @param annotationType the type of annotation to synthesize; never {@code null}
+ * @return the synthesized annotation
+ * @throws IllegalArgumentException if a required attribute is missing
+ * @throws AnnotationConfigurationException if invalid configuration of
+ * {@code @AliasFor} is detected
+ * @since 4.2
+ * @see #synthesizeAnnotation(Map, Class, AnnotatedElement)
+ * @see #synthesizeAnnotation(Annotation, AnnotatedElement)
+ */
+ public static A synthesizeAnnotation(Class annotationType) {
+ return synthesizeAnnotation(Collections. emptyMap(), annotationType, null);
+ }
+
/**
* Synthesize the supplied array of {@code annotations} by
* creating a new array of the same size and type and populating it
diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java
index 4c363e7159..416f43d04c 100644
--- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java
+++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java
@@ -56,8 +56,6 @@ import static org.springframework.core.annotation.AnnotationUtils.*;
*/
public class AnnotationUtilsTests {
- private static final Map EMPTY_ATTRS = Collections.emptyMap();
-
@Rule
public final ExpectedException exception = ExpectedException.none();
@@ -840,8 +838,8 @@ public class AnnotationUtilsTests {
}
@Test
- public void synthesizeAnnotationFromMapWithEmptyAttributesWithDefaultsWithoutAttributeAliases() throws Exception {
- AnnotationWithDefaults annotationWithDefaults = synthesizeAnnotation(EMPTY_ATTRS, AnnotationWithDefaults.class, null);
+ public void synthesizeAnnotationFromDefaultsWithoutAttributeAliases() throws Exception {
+ AnnotationWithDefaults annotationWithDefaults = synthesizeAnnotation(AnnotationWithDefaults.class);
assertNotNull(annotationWithDefaults);
assertEquals("text: ", "enigma", annotationWithDefaults.text());
assertTrue("predicate: ", annotationWithDefaults.predicate());
@@ -849,8 +847,8 @@ public class AnnotationUtilsTests {
}
@Test
- public void synthesizeAnnotationFromMapWithEmptyAttributesWithDefaultsWithAttributeAliases() throws Exception {
- ContextConfig contextConfig = synthesizeAnnotation(EMPTY_ATTRS, ContextConfig.class, null);
+ public void synthesizeAnnotationFromDefaultsWithAttributeAliases() throws Exception {
+ ContextConfig contextConfig = synthesizeAnnotation(ContextConfig.class);
assertNotNull(contextConfig);
assertEquals("value: ", "", contextConfig.value());
assertEquals("locations: ", "", contextConfig.locations());
@@ -868,7 +866,7 @@ public class AnnotationUtilsTests {
@Test
public void synthesizeAnnotationFromMapWithMissingAttributeValue() throws Exception {
- assertMissingTextAttribute(EMPTY_ATTRS);
+ assertMissingTextAttribute(Collections.emptyMap());
}
@Test
diff --git a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java
index 1e6c5eb853..e108393363 100644
--- a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java
+++ b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java
@@ -135,7 +135,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
private static final Log logger = LogFactory.getLog(TransactionalTestExecutionListener.class);
private static final TransactionConfiguration defaultTransactionConfiguration =
- AnnotationUtils.synthesizeAnnotation(Collections. emptyMap(), TransactionConfiguration.class, null);
+ AnnotationUtils.synthesizeAnnotation(TransactionConfiguration.class);
protected final TransactionAttributeSource attributeSource = new AnnotationTransactionAttributeSource();