Allow for a single element overriding an array attribute in a meta-annotation
Includes refinements for consistent quoting of names in exception messages. Issue: SPR-13972
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -959,7 +959,7 @@ public class AnnotatedElementUtilsTests {
|
||||
@interface TestComponentScan {
|
||||
|
||||
@AliasFor(attribute = "basePackages", annotation = ComponentScan.class)
|
||||
String[] packages();
|
||||
String pkg();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -1152,7 +1152,7 @@ public class AnnotatedElementUtilsTests {
|
||||
static class ComponentScanWithBasePackagesAndValueAliasClass {
|
||||
}
|
||||
|
||||
@TestComponentScan(packages = "com.example.app.test")
|
||||
@TestComponentScan(pkg = "com.example.app.test")
|
||||
static class TestComponentScanClass {
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -210,8 +210,7 @@ public class AnnotationUtilsTests {
|
||||
/** @since 4.1.2 */
|
||||
@Test
|
||||
public void findClassAnnotationFavorsMoreLocallyDeclaredComposedAnnotationsOverAnnotationsOnInterfaces() {
|
||||
Component component = findAnnotation(ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class,
|
||||
Component.class);
|
||||
Component component = findAnnotation(ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, Component.class);
|
||||
assertNotNull(component);
|
||||
assertEquals("meta2", component.value());
|
||||
}
|
||||
@@ -552,7 +551,7 @@ public class AnnotationUtilsTests {
|
||||
@Test
|
||||
public void getRepeatableAnnotationsDeclaredOnClassWithMissingAttributeAliasDeclaration() throws Exception {
|
||||
exception.expect(AnnotationConfigurationException.class);
|
||||
exception.expectMessage(startsWith("Attribute [value] in"));
|
||||
exception.expectMessage(startsWith("Attribute 'value' in"));
|
||||
exception.expectMessage(containsString(BrokenContextConfig.class.getName()));
|
||||
exception.expectMessage(containsString("@AliasFor [location]"));
|
||||
|
||||
@@ -844,7 +843,7 @@ public class AnnotationUtilsTests {
|
||||
public void synthesizeAnnotationWhereAliasForIsMissingAttributeDeclaration() throws Exception {
|
||||
AliasForWithMissingAttributeDeclaration annotation = AliasForWithMissingAttributeDeclarationClass.class.getAnnotation(AliasForWithMissingAttributeDeclaration.class);
|
||||
exception.expect(AnnotationConfigurationException.class);
|
||||
exception.expectMessage(startsWith("@AliasFor declaration on attribute [foo] in annotation"));
|
||||
exception.expectMessage(startsWith("@AliasFor declaration on attribute 'foo' in annotation"));
|
||||
exception.expectMessage(containsString(AliasForWithMissingAttributeDeclaration.class.getName()));
|
||||
exception.expectMessage(containsString("points to itself"));
|
||||
synthesizeAnnotation(annotation);
|
||||
@@ -854,7 +853,7 @@ public class AnnotationUtilsTests {
|
||||
public void synthesizeAnnotationWhereAliasForHasDuplicateAttributeDeclaration() throws Exception {
|
||||
AliasForWithDuplicateAttributeDeclaration annotation = AliasForWithDuplicateAttributeDeclarationClass.class.getAnnotation(AliasForWithDuplicateAttributeDeclaration.class);
|
||||
exception.expect(AnnotationConfigurationException.class);
|
||||
exception.expectMessage(startsWith("In @AliasFor declared on attribute [foo] in annotation"));
|
||||
exception.expectMessage(startsWith("In @AliasFor declared on attribute 'foo' in annotation"));
|
||||
exception.expectMessage(containsString(AliasForWithDuplicateAttributeDeclaration.class.getName()));
|
||||
exception.expectMessage(containsString("attribute 'attribute' and its alias 'value' are present with values of [baz] and [bar]"));
|
||||
synthesizeAnnotation(annotation);
|
||||
@@ -864,9 +863,9 @@ public class AnnotationUtilsTests {
|
||||
public void synthesizeAnnotationWithAttributeAliasForNonexistentAttribute() throws Exception {
|
||||
AliasForNonexistentAttribute annotation = AliasForNonexistentAttributeClass.class.getAnnotation(AliasForNonexistentAttribute.class);
|
||||
exception.expect(AnnotationConfigurationException.class);
|
||||
exception.expectMessage(startsWith("Attribute [foo] in"));
|
||||
exception.expectMessage(startsWith("Attribute 'foo' in"));
|
||||
exception.expectMessage(containsString(AliasForNonexistentAttribute.class.getName()));
|
||||
exception.expectMessage(containsString("is declared as an @AliasFor nonexistent attribute [bar]"));
|
||||
exception.expectMessage(containsString("is declared as an @AliasFor nonexistent attribute 'bar'"));
|
||||
synthesizeAnnotation(annotation);
|
||||
}
|
||||
|
||||
@@ -875,7 +874,7 @@ public class AnnotationUtilsTests {
|
||||
AliasForWithoutMirroredAliasFor annotation =
|
||||
AliasForWithoutMirroredAliasForClass.class.getAnnotation(AliasForWithoutMirroredAliasFor.class);
|
||||
exception.expect(AnnotationConfigurationException.class);
|
||||
exception.expectMessage(startsWith("Attribute [bar] in"));
|
||||
exception.expectMessage(startsWith("Attribute 'bar' in"));
|
||||
exception.expectMessage(containsString(AliasForWithoutMirroredAliasFor.class.getName()));
|
||||
exception.expectMessage(containsString("@AliasFor [foo]"));
|
||||
synthesizeAnnotation(annotation);
|
||||
@@ -887,10 +886,10 @@ public class AnnotationUtilsTests {
|
||||
AliasForWithMirroredAliasForWrongAttributeClass.class.getAnnotation(AliasForWithMirroredAliasForWrongAttribute.class);
|
||||
|
||||
exception.expect(AnnotationConfigurationException.class);
|
||||
exception.expectMessage(startsWith("Attribute [bar] in"));
|
||||
exception.expectMessage(startsWith("Attribute 'bar' in"));
|
||||
exception.expectMessage(containsString(AliasForWithMirroredAliasForWrongAttribute.class.getName()));
|
||||
exception.expectMessage(either(containsString("must be declared as an @AliasFor [foo], not [quux]")).
|
||||
or(containsString("is declared as an @AliasFor nonexistent attribute [quux]")));
|
||||
or(containsString("is declared as an @AliasFor nonexistent attribute 'quux'")));
|
||||
synthesizeAnnotation(annotation);
|
||||
}
|
||||
|
||||
@@ -901,8 +900,8 @@ public class AnnotationUtilsTests {
|
||||
exception.expect(AnnotationConfigurationException.class);
|
||||
exception.expectMessage(startsWith("Misconfigured aliases"));
|
||||
exception.expectMessage(containsString(AliasForAttributeOfDifferentType.class.getName()));
|
||||
exception.expectMessage(containsString("attribute [foo]"));
|
||||
exception.expectMessage(containsString("attribute [bar]"));
|
||||
exception.expectMessage(containsString("attribute 'foo'"));
|
||||
exception.expectMessage(containsString("attribute 'bar'"));
|
||||
exception.expectMessage(containsString("same return type"));
|
||||
synthesizeAnnotation(annotation);
|
||||
}
|
||||
@@ -914,8 +913,8 @@ public class AnnotationUtilsTests {
|
||||
exception.expect(AnnotationConfigurationException.class);
|
||||
exception.expectMessage(startsWith("Misconfigured aliases"));
|
||||
exception.expectMessage(containsString(AliasForWithMissingDefaultValues.class.getName()));
|
||||
exception.expectMessage(containsString("attribute [foo] in annotation"));
|
||||
exception.expectMessage(containsString("attribute [bar] in annotation"));
|
||||
exception.expectMessage(containsString("attribute 'foo' in annotation"));
|
||||
exception.expectMessage(containsString("attribute 'bar' in annotation"));
|
||||
exception.expectMessage(containsString("default values"));
|
||||
synthesizeAnnotation(annotation);
|
||||
}
|
||||
@@ -927,8 +926,8 @@ public class AnnotationUtilsTests {
|
||||
exception.expect(AnnotationConfigurationException.class);
|
||||
exception.expectMessage(startsWith("Misconfigured aliases"));
|
||||
exception.expectMessage(containsString(AliasForAttributeWithDifferentDefaultValue.class.getName()));
|
||||
exception.expectMessage(containsString("attribute [foo] in annotation"));
|
||||
exception.expectMessage(containsString("attribute [bar] in annotation"));
|
||||
exception.expectMessage(containsString("attribute 'foo' in annotation"));
|
||||
exception.expectMessage(containsString("attribute 'bar' in annotation"));
|
||||
exception.expectMessage(containsString("same default value"));
|
||||
synthesizeAnnotation(annotation);
|
||||
}
|
||||
@@ -938,9 +937,9 @@ public class AnnotationUtilsTests {
|
||||
AliasedComposedContextConfigNotMetaPresent annotation =
|
||||
AliasedComposedContextConfigNotMetaPresentClass.class.getAnnotation(AliasedComposedContextConfigNotMetaPresent.class);
|
||||
exception.expect(AnnotationConfigurationException.class);
|
||||
exception.expectMessage(startsWith("@AliasFor declaration on attribute [xmlConfigFile] in annotation"));
|
||||
exception.expectMessage(startsWith("@AliasFor declaration on attribute 'xmlConfigFile' in annotation"));
|
||||
exception.expectMessage(containsString(AliasedComposedContextConfigNotMetaPresent.class.getName()));
|
||||
exception.expectMessage(containsString("declares an alias for attribute [location] in meta-annotation"));
|
||||
exception.expectMessage(containsString("declares an alias for attribute 'location' in meta-annotation"));
|
||||
exception.expectMessage(containsString(ContextConfig.class.getName()));
|
||||
exception.expectMessage(containsString("not meta-present"));
|
||||
synthesizeAnnotation(annotation);
|
||||
@@ -1038,8 +1037,8 @@ public class AnnotationUtilsTests {
|
||||
|
||||
exception.expect(AnnotationConfigurationException.class);
|
||||
exception.expectMessage(startsWith("Misconfigured aliases:"));
|
||||
exception.expectMessage(containsString("attribute [location1] in annotation [" + annotationType.getName() + "]"));
|
||||
exception.expectMessage(containsString("attribute [location2] in annotation [" + annotationType.getName() + "]"));
|
||||
exception.expectMessage(containsString("attribute 'location1' in annotation [" + annotationType.getName() + "]"));
|
||||
exception.expectMessage(containsString("attribute 'location2' in annotation [" + annotationType.getName() + "]"));
|
||||
exception.expectMessage(containsString("default values"));
|
||||
|
||||
synthesizeAnnotation(config, clazz);
|
||||
@@ -1054,8 +1053,8 @@ public class AnnotationUtilsTests {
|
||||
|
||||
exception.expect(AnnotationConfigurationException.class);
|
||||
exception.expectMessage(startsWith("Misconfigured aliases:"));
|
||||
exception.expectMessage(containsString("attribute [location1] in annotation [" + annotationType.getName() + "]"));
|
||||
exception.expectMessage(containsString("attribute [location2] in annotation [" + annotationType.getName() + "]"));
|
||||
exception.expectMessage(containsString("attribute 'location1' in annotation [" + annotationType.getName() + "]"));
|
||||
exception.expectMessage(containsString("attribute 'location2' in annotation [" + annotationType.getName() + "]"));
|
||||
exception.expectMessage(containsString("same default value"));
|
||||
|
||||
synthesizeAnnotation(config, clazz);
|
||||
@@ -1220,7 +1219,7 @@ public class AnnotationUtilsTests {
|
||||
private void assertMissingTextAttribute(Map<String, Object> attributes) {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage(startsWith("Attributes map"));
|
||||
exception.expectMessage(containsString("returned null for required attribute [text]"));
|
||||
exception.expectMessage(containsString("returned null for required attribute 'text'"));
|
||||
exception.expectMessage(containsString("defined by annotation type [" + AnnotationWithoutDefaults.class.getName() + "]"));
|
||||
synthesizeAnnotation(attributes, AnnotationWithoutDefaults.class, null);
|
||||
}
|
||||
@@ -1232,7 +1231,7 @@ public class AnnotationUtilsTests {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage(startsWith("Attributes map"));
|
||||
exception.expectMessage(containsString("returned a value of type [java.lang.Long]"));
|
||||
exception.expectMessage(containsString("for attribute [value]"));
|
||||
exception.expectMessage(containsString("for attribute 'value'"));
|
||||
exception.expectMessage(containsString("but a value of type [java.lang.String] is required"));
|
||||
exception.expectMessage(containsString("as defined by annotation type [" + Component.class.getName() + "]"));
|
||||
|
||||
@@ -1241,7 +1240,6 @@ public class AnnotationUtilsTests {
|
||||
|
||||
@Test
|
||||
public void synthesizeAnnotationFromAnnotationAttributesWithoutAttributeAliases() throws Exception {
|
||||
|
||||
// 1) Get an annotation
|
||||
Component component = WebController.class.getAnnotation(Component.class);
|
||||
assertNotNull(component);
|
||||
|
||||
Reference in New Issue
Block a user