|
|
|
|
@ -59,6 +59,7 @@ public class AnnotationUtilsTests {
@@ -59,6 +59,7 @@ public class AnnotationUtilsTests {
|
|
|
|
|
@Rule |
|
|
|
|
public final ExpectedException exception = ExpectedException.none(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void findMethodAnnotationOnLeaf() throws Exception { |
|
|
|
|
Method m = Leaf.class.getMethod("annotatedOnLeaf"); |
|
|
|
|
@ -373,9 +374,8 @@ public class AnnotationUtilsTests {
@@ -373,9 +374,8 @@ public class AnnotationUtilsTests {
|
|
|
|
|
|
|
|
|
|
// inherited class-level annotation; note: @Transactional is inherited
|
|
|
|
|
assertFalse(isAnnotationInherited(Transactional.class, InheritedAnnotationInterface.class)); |
|
|
|
|
// isAnnotationInherited() does not currently traverse interface
|
|
|
|
|
// hierarchies. Thus the following, though perhaps counter intuitive,
|
|
|
|
|
// must be false:
|
|
|
|
|
// isAnnotationInherited() does not currently traverse interface hierarchies.
|
|
|
|
|
// Thus the following, though perhaps counter intuitive, must be false:
|
|
|
|
|
assertFalse(isAnnotationInherited(Transactional.class, SubInheritedAnnotationInterface.class)); |
|
|
|
|
assertFalse(isAnnotationInherited(Transactional.class, InheritedAnnotationClass.class)); |
|
|
|
|
assertTrue(isAnnotationInherited(Transactional.class, SubInheritedAnnotationClass.class)); |
|
|
|
|
@ -437,7 +437,7 @@ public class AnnotationUtilsTests {
@@ -437,7 +437,7 @@ public class AnnotationUtilsTests {
|
|
|
|
|
method = WebController.class.getMethod("handleMappedWithDifferentPathAndValueAttributes"); |
|
|
|
|
webMapping = method.getAnnotation(WebMapping.class); |
|
|
|
|
exception.expect(AnnotationConfigurationException.class); |
|
|
|
|
exception.expectMessage(containsString("attribute [value] and its alias [path]")); |
|
|
|
|
exception.expectMessage(containsString("attribute 'value' and its alias 'path'")); |
|
|
|
|
exception.expectMessage(containsString("values of [/enigma] and [/test]")); |
|
|
|
|
exception.expectMessage(containsString("but only one is permitted")); |
|
|
|
|
getAnnotationAttributes(webMapping); |
|
|
|
|
@ -716,7 +716,8 @@ public class AnnotationUtilsTests {
@@ -716,7 +716,8 @@ public class AnnotationUtilsTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void synthesizeAnnotationWithAttributeAliasForNonexistentAttribute() throws Exception { |
|
|
|
|
AliasForNonexistentAttribute annotation = AliasForNonexistentAttributeClass.class.getAnnotation(AliasForNonexistentAttribute.class); |
|
|
|
|
AliasForNonexistentAttribute annotation = |
|
|
|
|
AliasForNonexistentAttributeClass.class.getAnnotation(AliasForNonexistentAttribute.class); |
|
|
|
|
exception.expect(AnnotationConfigurationException.class); |
|
|
|
|
exception.expectMessage(containsString("Attribute [foo] in")); |
|
|
|
|
exception.expectMessage(containsString(AliasForNonexistentAttribute.class.getName())); |
|
|
|
|
@ -726,7 +727,8 @@ public class AnnotationUtilsTests {
@@ -726,7 +727,8 @@ public class AnnotationUtilsTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void synthesizeAnnotationWithAttributeAliasWithoutMirroredAliasFor() throws Exception { |
|
|
|
|
AliasForWithoutMirroredAliasFor annotation = AliasForWithoutMirroredAliasForClass.class.getAnnotation(AliasForWithoutMirroredAliasFor.class); |
|
|
|
|
AliasForWithoutMirroredAliasFor annotation = |
|
|
|
|
AliasForWithoutMirroredAliasForClass.class.getAnnotation(AliasForWithoutMirroredAliasFor.class); |
|
|
|
|
exception.expect(AnnotationConfigurationException.class); |
|
|
|
|
exception.expectMessage(containsString("Attribute [bar] in")); |
|
|
|
|
exception.expectMessage(containsString(AliasForWithoutMirroredAliasFor.class.getName())); |
|
|
|
|
@ -736,11 +738,11 @@ public class AnnotationUtilsTests {
@@ -736,11 +738,11 @@ public class AnnotationUtilsTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void synthesizeAnnotationWithAttributeAliasWithMirroredAliasForWrongAttribute() throws Exception { |
|
|
|
|
AliasForWithMirroredAliasForWrongAttribute annotation = AliasForWithMirroredAliasForWrongAttributeClass.class.getAnnotation(AliasForWithMirroredAliasForWrongAttribute.class); |
|
|
|
|
AliasForWithMirroredAliasForWrongAttribute annotation = |
|
|
|
|
AliasForWithMirroredAliasForWrongAttributeClass.class.getAnnotation(AliasForWithMirroredAliasForWrongAttribute.class); |
|
|
|
|
|
|
|
|
|
// Since JDK 7+ does not guarantee consistent ordering of methods returned using
|
|
|
|
|
// reflection, we cannot make the test dependent on any specific ordering.
|
|
|
|
|
//
|
|
|
|
|
// In other words, we can't be certain which type of exception message we'll get,
|
|
|
|
|
// so we allow for both possibilities.
|
|
|
|
|
exception.expect(AnnotationConfigurationException.class); |
|
|
|
|
@ -753,13 +755,14 @@ public class AnnotationUtilsTests {
@@ -753,13 +755,14 @@ public class AnnotationUtilsTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void synthesizeAnnotationWithAttributeAliasForAttributeOfDifferentType() throws Exception { |
|
|
|
|
AliasForAttributeOfDifferentType annotation = AliasForAttributeOfDifferentTypeClass.class.getAnnotation(AliasForAttributeOfDifferentType.class); |
|
|
|
|
AliasForAttributeOfDifferentType annotation = |
|
|
|
|
AliasForAttributeOfDifferentTypeClass.class.getAnnotation(AliasForAttributeOfDifferentType.class); |
|
|
|
|
exception.expect(AnnotationConfigurationException.class); |
|
|
|
|
exception.expectMessage(startsWith("Misconfigured aliases")); |
|
|
|
|
exception.expectMessage(containsString(AliasForAttributeOfDifferentType.class.getName())); |
|
|
|
|
|
|
|
|
|
// Since JDK 7+ does not guarantee consistent ordering of methods returned using
|
|
|
|
|
// reflection, we cannot make the test dependent on any specific ordering.
|
|
|
|
|
//
|
|
|
|
|
// In other words, we don't know if "foo" or "bar" will come first.
|
|
|
|
|
exception.expectMessage(containsString("attribute [foo]")); |
|
|
|
|
exception.expectMessage(containsString("attribute [bar]")); |
|
|
|
|
@ -769,12 +772,13 @@ public class AnnotationUtilsTests {
@@ -769,12 +772,13 @@ public class AnnotationUtilsTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void synthesizeAnnotationWithAttributeAliasForWithMissingDefaultValues() throws Exception { |
|
|
|
|
AliasForWithMissingDefaultValues annotation = AliasForWithMissingDefaultValuesClass.class.getAnnotation(AliasForWithMissingDefaultValues.class); |
|
|
|
|
AliasForWithMissingDefaultValues annotation = |
|
|
|
|
AliasForWithMissingDefaultValuesClass.class.getAnnotation(AliasForWithMissingDefaultValues.class); |
|
|
|
|
exception.expectMessage(startsWith("Misconfigured aliases")); |
|
|
|
|
exception.expectMessage(containsString(AliasForWithMissingDefaultValues.class.getName())); |
|
|
|
|
|
|
|
|
|
// Since JDK 7+ does not guarantee consistent ordering of methods returned using
|
|
|
|
|
// reflection, we cannot make the test dependent on any specific ordering.
|
|
|
|
|
//
|
|
|
|
|
// In other words, we don't know if "foo" or "bar" will come first.
|
|
|
|
|
exception.expectMessage(containsString("attribute [foo]")); |
|
|
|
|
exception.expectMessage(containsString("attribute [bar]")); |
|
|
|
|
@ -784,12 +788,13 @@ public class AnnotationUtilsTests {
@@ -784,12 +788,13 @@ public class AnnotationUtilsTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void synthesizeAnnotationWithAttributeAliasForAttributeWithDifferentDefaultValue() throws Exception { |
|
|
|
|
AliasForAttributeWithDifferentDefaultValue annotation = AliasForAttributeWithDifferentDefaultValueClass.class.getAnnotation(AliasForAttributeWithDifferentDefaultValue.class); |
|
|
|
|
AliasForAttributeWithDifferentDefaultValue annotation = |
|
|
|
|
AliasForAttributeWithDifferentDefaultValueClass.class.getAnnotation(AliasForAttributeWithDifferentDefaultValue.class); |
|
|
|
|
exception.expectMessage(startsWith("Misconfigured aliases")); |
|
|
|
|
exception.expectMessage(containsString(AliasForAttributeWithDifferentDefaultValue.class.getName())); |
|
|
|
|
|
|
|
|
|
// Since JDK 7+ does not guarantee consistent ordering of methods returned using
|
|
|
|
|
// reflection, we cannot make the test dependent on any specific ordering.
|
|
|
|
|
//
|
|
|
|
|
// In other words, we don't know if "foo" or "bar" will come first.
|
|
|
|
|
exception.expectMessage(containsString("attribute [foo]")); |
|
|
|
|
exception.expectMessage(containsString("attribute [bar]")); |
|
|
|
|
@ -1042,7 +1047,6 @@ public class AnnotationUtilsTests {
@@ -1042,7 +1047,6 @@ public class AnnotationUtilsTests {
|
|
|
|
|
@Test |
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
public void synthesizeNonPublicAnnotationWithAttributeAliasesFromDifferentPackage() throws Exception { |
|
|
|
|
|
|
|
|
|
Class<?> clazz = |
|
|
|
|
ClassUtils.forName("org.springframework.core.annotation.subpackage.NonPublicAliasedAnnotatedClass", null); |
|
|
|
|
Class<? extends Annotation> annotationType = (Class<? extends Annotation>) |
|
|
|
|
|