Fixed exception message expectation plus formatting

Issue: SPR-13067
This commit is contained in:
Juergen Hoeller 2015-07-17 16:19:11 +02:00
parent cc0a4c1ea0
commit 0cce41eb94
1 changed files with 43 additions and 39 deletions

View File

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