Skip to content

Commit 0cce41e

Browse files
committed
Fixed exception message expectation plus formatting
Issue: SPR-13067
1 parent cc0a4c1 commit 0cce41e

File tree

1 file changed

+43
-39
lines changed

1 file changed

+43
-39
lines changed

spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class AnnotationUtilsTests {
5959
@Rule
6060
public final ExpectedException exception = ExpectedException.none();
6161

62+
6263
@Test
6364
public void findMethodAnnotationOnLeaf() throws Exception {
6465
Method m = Leaf.class.getMethod("annotatedOnLeaf");
@@ -264,22 +265,22 @@ public void findAnnotationDeclaringClassForAllScenarios() throws Exception {
264265

265266
// inherited class-level annotation; note: @Transactional is inherited
266267
assertEquals(InheritedAnnotationInterface.class,
267-
findAnnotationDeclaringClass(Transactional.class, InheritedAnnotationInterface.class));
268+
findAnnotationDeclaringClass(Transactional.class, InheritedAnnotationInterface.class));
268269
assertNull(findAnnotationDeclaringClass(Transactional.class, SubInheritedAnnotationInterface.class));
269270
assertEquals(InheritedAnnotationClass.class,
270-
findAnnotationDeclaringClass(Transactional.class, InheritedAnnotationClass.class));
271+
findAnnotationDeclaringClass(Transactional.class, InheritedAnnotationClass.class));
271272
assertEquals(InheritedAnnotationClass.class,
272-
findAnnotationDeclaringClass(Transactional.class, SubInheritedAnnotationClass.class));
273+
findAnnotationDeclaringClass(Transactional.class, SubInheritedAnnotationClass.class));
273274

274275
// non-inherited class-level annotation; note: @Order is not inherited,
275276
// but findAnnotationDeclaringClass() should still find it on classes.
276277
assertEquals(NonInheritedAnnotationInterface.class,
277-
findAnnotationDeclaringClass(Order.class, NonInheritedAnnotationInterface.class));
278+
findAnnotationDeclaringClass(Order.class, NonInheritedAnnotationInterface.class));
278279
assertNull(findAnnotationDeclaringClass(Order.class, SubNonInheritedAnnotationInterface.class));
279280
assertEquals(NonInheritedAnnotationClass.class,
280-
findAnnotationDeclaringClass(Order.class, NonInheritedAnnotationClass.class));
281+
findAnnotationDeclaringClass(Order.class, NonInheritedAnnotationClass.class));
281282
assertEquals(NonInheritedAnnotationClass.class,
282-
findAnnotationDeclaringClass(Order.class, SubNonInheritedAnnotationClass.class));
283+
findAnnotationDeclaringClass(Order.class, SubNonInheritedAnnotationClass.class));
283284
}
284285

285286
@Test
@@ -291,23 +292,23 @@ public void findAnnotationDeclaringClassForTypesWithSingleCandidateType() {
291292

292293
// inherited class-level annotation; note: @Transactional is inherited
293294
assertEquals(InheritedAnnotationInterface.class,
294-
findAnnotationDeclaringClassForTypes(transactionalCandidateList, InheritedAnnotationInterface.class));
295+
findAnnotationDeclaringClassForTypes(transactionalCandidateList, InheritedAnnotationInterface.class));
295296
assertNull(findAnnotationDeclaringClassForTypes(transactionalCandidateList, SubInheritedAnnotationInterface.class));
296297
assertEquals(InheritedAnnotationClass.class,
297-
findAnnotationDeclaringClassForTypes(transactionalCandidateList, InheritedAnnotationClass.class));
298+
findAnnotationDeclaringClassForTypes(transactionalCandidateList, InheritedAnnotationClass.class));
298299
assertEquals(InheritedAnnotationClass.class,
299-
findAnnotationDeclaringClassForTypes(transactionalCandidateList, SubInheritedAnnotationClass.class));
300+
findAnnotationDeclaringClassForTypes(transactionalCandidateList, SubInheritedAnnotationClass.class));
300301

301302
// non-inherited class-level annotation; note: @Order is not inherited,
302303
// but findAnnotationDeclaringClassForTypes() should still find it on classes.
303304
List<Class<? extends Annotation>> orderCandidateList = Arrays.<Class<? extends Annotation>> asList(Order.class);
304305
assertEquals(NonInheritedAnnotationInterface.class,
305-
findAnnotationDeclaringClassForTypes(orderCandidateList, NonInheritedAnnotationInterface.class));
306+
findAnnotationDeclaringClassForTypes(orderCandidateList, NonInheritedAnnotationInterface.class));
306307
assertNull(findAnnotationDeclaringClassForTypes(orderCandidateList, SubNonInheritedAnnotationInterface.class));
307308
assertEquals(NonInheritedAnnotationClass.class,
308-
findAnnotationDeclaringClassForTypes(orderCandidateList, NonInheritedAnnotationClass.class));
309+
findAnnotationDeclaringClassForTypes(orderCandidateList, NonInheritedAnnotationClass.class));
309310
assertEquals(NonInheritedAnnotationClass.class,
310-
findAnnotationDeclaringClassForTypes(orderCandidateList, SubNonInheritedAnnotationClass.class));
311+
findAnnotationDeclaringClassForTypes(orderCandidateList, SubNonInheritedAnnotationClass.class));
311312
}
312313

313314
@Test
@@ -320,30 +321,30 @@ public void findAnnotationDeclaringClassForTypesWithMultipleCandidateTypes() {
320321

321322
// inherited class-level annotation; note: @Transactional is inherited
322323
assertEquals(InheritedAnnotationInterface.class,
323-
findAnnotationDeclaringClassForTypes(candidates, InheritedAnnotationInterface.class));
324+
findAnnotationDeclaringClassForTypes(candidates, InheritedAnnotationInterface.class));
324325
assertNull(findAnnotationDeclaringClassForTypes(candidates, SubInheritedAnnotationInterface.class));
325326
assertEquals(InheritedAnnotationClass.class,
326-
findAnnotationDeclaringClassForTypes(candidates, InheritedAnnotationClass.class));
327+
findAnnotationDeclaringClassForTypes(candidates, InheritedAnnotationClass.class));
327328
assertEquals(InheritedAnnotationClass.class,
328-
findAnnotationDeclaringClassForTypes(candidates, SubInheritedAnnotationClass.class));
329+
findAnnotationDeclaringClassForTypes(candidates, SubInheritedAnnotationClass.class));
329330

330331
// non-inherited class-level annotation; note: @Order is not inherited,
331332
// but findAnnotationDeclaringClassForTypes() should still find it on classes.
332333
assertEquals(NonInheritedAnnotationInterface.class,
333-
findAnnotationDeclaringClassForTypes(candidates, NonInheritedAnnotationInterface.class));
334+
findAnnotationDeclaringClassForTypes(candidates, NonInheritedAnnotationInterface.class));
334335
assertNull(findAnnotationDeclaringClassForTypes(candidates, SubNonInheritedAnnotationInterface.class));
335336
assertEquals(NonInheritedAnnotationClass.class,
336-
findAnnotationDeclaringClassForTypes(candidates, NonInheritedAnnotationClass.class));
337+
findAnnotationDeclaringClassForTypes(candidates, NonInheritedAnnotationClass.class));
337338
assertEquals(NonInheritedAnnotationClass.class,
338-
findAnnotationDeclaringClassForTypes(candidates, SubNonInheritedAnnotationClass.class));
339+
findAnnotationDeclaringClassForTypes(candidates, SubNonInheritedAnnotationClass.class));
339340

340341
// class hierarchy mixed with @Transactional and @Order declarations
341342
assertEquals(TransactionalClass.class,
342-
findAnnotationDeclaringClassForTypes(candidates, TransactionalClass.class));
343+
findAnnotationDeclaringClassForTypes(candidates, TransactionalClass.class));
343344
assertEquals(TransactionalAndOrderedClass.class,
344-
findAnnotationDeclaringClassForTypes(candidates, TransactionalAndOrderedClass.class));
345+
findAnnotationDeclaringClassForTypes(candidates, TransactionalAndOrderedClass.class));
345346
assertEquals(TransactionalAndOrderedClass.class,
346-
findAnnotationDeclaringClassForTypes(candidates, SubTransactionalAndOrderedClass.class));
347+
findAnnotationDeclaringClassForTypes(candidates, SubTransactionalAndOrderedClass.class));
347348
}
348349

349350
@Test
@@ -373,9 +374,8 @@ public void isAnnotationInheritedForAllScenarios() throws Exception {
373374

374375
// inherited class-level annotation; note: @Transactional is inherited
375376
assertFalse(isAnnotationInherited(Transactional.class, InheritedAnnotationInterface.class));
376-
// isAnnotationInherited() does not currently traverse interface
377-
// hierarchies. Thus the following, though perhaps counter intuitive,
378-
// must be false:
377+
// isAnnotationInherited() does not currently traverse interface hierarchies.
378+
// Thus the following, though perhaps counter intuitive, must be false:
379379
assertFalse(isAnnotationInherited(Transactional.class, SubInheritedAnnotationInterface.class));
380380
assertFalse(isAnnotationInherited(Transactional.class, InheritedAnnotationClass.class));
381381
assertTrue(isAnnotationInherited(Transactional.class, SubInheritedAnnotationClass.class));
@@ -437,7 +437,7 @@ public void getAnnotationAttributesWithAttributeAliases() throws Exception {
437437
method = WebController.class.getMethod("handleMappedWithDifferentPathAndValueAttributes");
438438
webMapping = method.getAnnotation(WebMapping.class);
439439
exception.expect(AnnotationConfigurationException.class);
440-
exception.expectMessage(containsString("attribute [value] and its alias [path]"));
440+
exception.expectMessage(containsString("attribute 'value' and its alias 'path'"));
441441
exception.expectMessage(containsString("values of [/enigma] and [/test]"));
442442
exception.expectMessage(containsString("but only one is permitted"));
443443
getAnnotationAttributes(webMapping);
@@ -716,7 +716,8 @@ public void synthesizeAlreadySynthesizedAnnotation() throws Exception {
716716

717717
@Test
718718
public void synthesizeAnnotationWithAttributeAliasForNonexistentAttribute() throws Exception {
719-
AliasForNonexistentAttribute annotation = AliasForNonexistentAttributeClass.class.getAnnotation(AliasForNonexistentAttribute.class);
719+
AliasForNonexistentAttribute annotation =
720+
AliasForNonexistentAttributeClass.class.getAnnotation(AliasForNonexistentAttribute.class);
720721
exception.expect(AnnotationConfigurationException.class);
721722
exception.expectMessage(containsString("Attribute [foo] in"));
722723
exception.expectMessage(containsString(AliasForNonexistentAttribute.class.getName()));
@@ -726,7 +727,8 @@ public void synthesizeAnnotationWithAttributeAliasForNonexistentAttribute() thro
726727

727728
@Test
728729
public void synthesizeAnnotationWithAttributeAliasWithoutMirroredAliasFor() throws Exception {
729-
AliasForWithoutMirroredAliasFor annotation = AliasForWithoutMirroredAliasForClass.class.getAnnotation(AliasForWithoutMirroredAliasFor.class);
730+
AliasForWithoutMirroredAliasFor annotation =
731+
AliasForWithoutMirroredAliasForClass.class.getAnnotation(AliasForWithoutMirroredAliasFor.class);
730732
exception.expect(AnnotationConfigurationException.class);
731733
exception.expectMessage(containsString("Attribute [bar] in"));
732734
exception.expectMessage(containsString(AliasForWithoutMirroredAliasFor.class.getName()));
@@ -736,11 +738,11 @@ public void synthesizeAnnotationWithAttributeAliasWithoutMirroredAliasFor() thro
736738

737739
@Test
738740
public void synthesizeAnnotationWithAttributeAliasWithMirroredAliasForWrongAttribute() throws Exception {
739-
AliasForWithMirroredAliasForWrongAttribute annotation = AliasForWithMirroredAliasForWrongAttributeClass.class.getAnnotation(AliasForWithMirroredAliasForWrongAttribute.class);
741+
AliasForWithMirroredAliasForWrongAttribute annotation =
742+
AliasForWithMirroredAliasForWrongAttributeClass.class.getAnnotation(AliasForWithMirroredAliasForWrongAttribute.class);
740743

741744
// Since JDK 7+ does not guarantee consistent ordering of methods returned using
742745
// reflection, we cannot make the test dependent on any specific ordering.
743-
//
744746
// In other words, we can't be certain which type of exception message we'll get,
745747
// so we allow for both possibilities.
746748
exception.expect(AnnotationConfigurationException.class);
@@ -753,13 +755,14 @@ public void synthesizeAnnotationWithAttributeAliasWithMirroredAliasForWrongAttri
753755

754756
@Test
755757
public void synthesizeAnnotationWithAttributeAliasForAttributeOfDifferentType() throws Exception {
756-
AliasForAttributeOfDifferentType annotation = AliasForAttributeOfDifferentTypeClass.class.getAnnotation(AliasForAttributeOfDifferentType.class);
758+
AliasForAttributeOfDifferentType annotation =
759+
AliasForAttributeOfDifferentTypeClass.class.getAnnotation(AliasForAttributeOfDifferentType.class);
757760
exception.expect(AnnotationConfigurationException.class);
758761
exception.expectMessage(startsWith("Misconfigured aliases"));
759762
exception.expectMessage(containsString(AliasForAttributeOfDifferentType.class.getName()));
763+
760764
// Since JDK 7+ does not guarantee consistent ordering of methods returned using
761765
// reflection, we cannot make the test dependent on any specific ordering.
762-
//
763766
// In other words, we don't know if "foo" or "bar" will come first.
764767
exception.expectMessage(containsString("attribute [foo]"));
765768
exception.expectMessage(containsString("attribute [bar]"));
@@ -769,12 +772,13 @@ public void synthesizeAnnotationWithAttributeAliasForAttributeOfDifferentType()
769772

770773
@Test
771774
public void synthesizeAnnotationWithAttributeAliasForWithMissingDefaultValues() throws Exception {
772-
AliasForWithMissingDefaultValues annotation = AliasForWithMissingDefaultValuesClass.class.getAnnotation(AliasForWithMissingDefaultValues.class);
775+
AliasForWithMissingDefaultValues annotation =
776+
AliasForWithMissingDefaultValuesClass.class.getAnnotation(AliasForWithMissingDefaultValues.class);
773777
exception.expectMessage(startsWith("Misconfigured aliases"));
774778
exception.expectMessage(containsString(AliasForWithMissingDefaultValues.class.getName()));
779+
775780
// Since JDK 7+ does not guarantee consistent ordering of methods returned using
776781
// reflection, we cannot make the test dependent on any specific ordering.
777-
//
778782
// In other words, we don't know if "foo" or "bar" will come first.
779783
exception.expectMessage(containsString("attribute [foo]"));
780784
exception.expectMessage(containsString("attribute [bar]"));
@@ -784,12 +788,13 @@ public void synthesizeAnnotationWithAttributeAliasForWithMissingDefaultValues()
784788

785789
@Test
786790
public void synthesizeAnnotationWithAttributeAliasForAttributeWithDifferentDefaultValue() throws Exception {
787-
AliasForAttributeWithDifferentDefaultValue annotation = AliasForAttributeWithDifferentDefaultValueClass.class.getAnnotation(AliasForAttributeWithDifferentDefaultValue.class);
791+
AliasForAttributeWithDifferentDefaultValue annotation =
792+
AliasForAttributeWithDifferentDefaultValueClass.class.getAnnotation(AliasForAttributeWithDifferentDefaultValue.class);
788793
exception.expectMessage(startsWith("Misconfigured aliases"));
789794
exception.expectMessage(containsString(AliasForAttributeWithDifferentDefaultValue.class.getName()));
795+
790796
// Since JDK 7+ does not guarantee consistent ordering of methods returned using
791797
// reflection, we cannot make the test dependent on any specific ordering.
792-
//
793798
// In other words, we don't know if "foo" or "bar" will come first.
794799
exception.expectMessage(containsString("attribute [foo]"));
795800
exception.expectMessage(containsString("attribute [bar]"));
@@ -1042,11 +1047,10 @@ public void hashCodeForSynthesizedAnnotations() throws Exception {
10421047
@Test
10431048
@SuppressWarnings("unchecked")
10441049
public void synthesizeNonPublicAnnotationWithAttributeAliasesFromDifferentPackage() throws Exception {
1045-
10461050
Class<?> clazz =
1047-
ClassUtils.forName("org.springframework.core.annotation.subpackage.NonPublicAliasedAnnotatedClass", null);
1051+
ClassUtils.forName("org.springframework.core.annotation.subpackage.NonPublicAliasedAnnotatedClass", null);
10481052
Class<? extends Annotation> annotationType = (Class<? extends Annotation>)
1049-
ClassUtils.forName("org.springframework.core.annotation.subpackage.NonPublicAliasedAnnotation", null);
1053+
ClassUtils.forName("org.springframework.core.annotation.subpackage.NonPublicAliasedAnnotation", null);
10501054

10511055
Annotation annotation = clazz.getAnnotation(annotationType);
10521056
assertNotNull(annotation);
@@ -1072,7 +1076,7 @@ public void synthesizeAnnotationWithAttributeAliasesInNestedAnnotations() throws
10721076
ContextConfig[] configs = synthesizedHierarchy.value();
10731077
assertNotNull(configs);
10741078
assertTrue("nested annotations must be synthesized",
1075-
Arrays.stream(configs).allMatch(c -> c instanceof SynthesizedAnnotation));
1079+
Arrays.stream(configs).allMatch(c -> c instanceof SynthesizedAnnotation));
10761080

10771081
List<String> locations = Arrays.stream(configs).map(ContextConfig::locations).collect(toList());
10781082
assertThat(locations, is(expectedLocations));

0 commit comments

Comments
 (0)