Skip to content

Commit 4317e76

Browse files
committed
Polish AnnotationUtilsTests
1 parent b5a6707 commit 4317e76

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

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

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ public void getRepeatableAnnotationsDeclaredOnClassWithMissingAttributeAliasDecl
510510
exception.expect(AnnotationConfigurationException.class);
511511
exception.expectMessage(containsString("Attribute [value] in"));
512512
exception.expectMessage(containsString(BrokenContextConfig.class.getName()));
513-
exception.expectMessage(containsString("must be declared as an @AliasFor [locations]"));
513+
exception.expectMessage(containsString("must be declared as an @AliasFor [location]"));
514514
getRepeatableAnnotations(BrokenConfigHierarchyTestCase.class, BrokenContextConfig.class, BrokenHierarchy.class);
515515
}
516516

@@ -525,7 +525,7 @@ public void getRepeatableAnnotationsDeclaredOnClassWithAttributeAliases() throws
525525
annotations = getRepeatableAnnotations(ConfigHierarchyTestCase.class, ContextConfig.class, Hierarchy.class);
526526
assertNotNull(annotations);
527527

528-
List<String> locations = annotations.stream().map(ContextConfig::locations).collect(toList());
528+
List<String> locations = annotations.stream().map(ContextConfig::location).collect(toList());
529529
assertThat(locations, is(expectedLocations));
530530

531531
List<String> values = annotations.stream().map(ContextConfig::value).collect(toList());
@@ -685,7 +685,7 @@ public void getAliasedAttributeNameFromWrongTargetAnnotation() throws Exception
685685
@Test
686686
public void getAliasedAttributeNameFromAliasedComposedAnnotation() throws Exception {
687687
Method attribute = AliasedComposedContextConfig.class.getDeclaredMethod("xmlConfigFile");
688-
assertEquals("locations", getAliasedAttributeName(attribute, ContextConfig.class));
688+
assertEquals("location", getAliasedAttributeName(attribute, ContextConfig.class));
689689
}
690690

691691
@Test
@@ -712,10 +712,9 @@ public void synthesizeAlreadySynthesizedAnnotation() throws Exception {
712712
WebMapping synthesizedWebMapping = synthesizeAnnotation(webMapping);
713713
assertNotSame(webMapping, synthesizedWebMapping);
714714
WebMapping synthesizedAgainWebMapping = synthesizeAnnotation(synthesizedWebMapping);
715-
assertSame(synthesizedWebMapping, synthesizedAgainWebMapping);
716715
assertThat(synthesizedAgainWebMapping, instanceOf(SynthesizedAnnotation.class));
716+
assertSame(synthesizedWebMapping, synthesizedAgainWebMapping);
717717

718-
assertNotNull(synthesizedAgainWebMapping);
719718
assertEquals("name attribute: ", "foo", synthesizedAgainWebMapping.name());
720719
assertEquals("aliased path attribute: ", "/test", synthesizedAgainWebMapping.path());
721720
assertEquals("actual value attribute: ", "/test", synthesizedAgainWebMapping.value());
@@ -837,7 +836,7 @@ public void synthesizeAnnotationWithAttributeAliasForMetaAnnotationThatIsNotMeta
837836
exception.expect(AnnotationConfigurationException.class);
838837
exception.expectMessage(startsWith("@AliasFor declaration on attribute [xmlConfigFile] in annotation"));
839838
exception.expectMessage(containsString(AliasedComposedContextConfigNotMetaPresent.class.getName()));
840-
exception.expectMessage(containsString("declares an alias for attribute [locations] in meta-annotation"));
839+
exception.expectMessage(containsString("declares an alias for attribute [location] in meta-annotation"));
841840
exception.expectMessage(containsString(ContextConfig.class.getName()));
842841
exception.expectMessage(endsWith("which is not meta-present."));
843842
synthesizeAnnotation(annotation);
@@ -850,18 +849,16 @@ public void synthesizeAnnotationWithAttributeAliases() throws Exception {
850849
assertNotNull(webMapping);
851850

852851
WebMapping synthesizedWebMapping1 = synthesizeAnnotation(webMapping);
853-
assertNotNull(synthesizedWebMapping1);
854-
assertNotSame(webMapping, synthesizedWebMapping1);
855852
assertThat(synthesizedWebMapping1, instanceOf(SynthesizedAnnotation.class));
853+
assertNotSame(webMapping, synthesizedWebMapping1);
856854

857855
assertEquals("name attribute: ", "foo", synthesizedWebMapping1.name());
858856
assertEquals("aliased path attribute: ", "/test", synthesizedWebMapping1.path());
859857
assertEquals("actual value attribute: ", "/test", synthesizedWebMapping1.value());
860858

861859
WebMapping synthesizedWebMapping2 = synthesizeAnnotation(webMapping);
862-
assertNotNull(synthesizedWebMapping2);
863-
assertNotSame(webMapping, synthesizedWebMapping2);
864860
assertThat(synthesizedWebMapping2, instanceOf(SynthesizedAnnotation.class));
861+
assertNotSame(webMapping, synthesizedWebMapping2);
865862

866863
assertEquals("name attribute: ", "foo", synthesizedWebMapping2.name());
867864
assertEquals("aliased path attribute: ", "/test", synthesizedWebMapping2.path());
@@ -955,17 +952,17 @@ public void synthesizeAnnotationFromDefaultsWithAttributeAliases() throws Except
955952
ContextConfig contextConfig = synthesizeAnnotation(ContextConfig.class);
956953
assertNotNull(contextConfig);
957954
assertEquals("value: ", "", contextConfig.value());
958-
assertEquals("locations: ", "", contextConfig.locations());
955+
assertEquals("location: ", "", contextConfig.location());
959956
}
960957

961958
@Test
962959
public void synthesizeAnnotationFromMapWithMinimalAttributesWithAttributeAliases() throws Exception {
963960
Map<String, Object> map = new HashMap<String, Object>();
964-
map.put("locations", "test.xml");
961+
map.put("location", "test.xml");
965962
ContextConfig contextConfig = synthesizeAnnotation(map, ContextConfig.class, null);
966963
assertNotNull(contextConfig);
967964
assertEquals("value: ", "test.xml", contextConfig.value());
968-
assertEquals("locations: ", "test.xml", contextConfig.locations());
965+
assertEquals("location: ", "test.xml", contextConfig.location());
969966
}
970967

971968
@Test
@@ -1177,7 +1174,7 @@ public void synthesizeAnnotationWithAttributeAliasesInNestedAnnotations() throws
11771174
assertTrue("nested annotations must be synthesized",
11781175
Arrays.stream(configs).allMatch(c -> c instanceof SynthesizedAnnotation));
11791176

1180-
List<String> locations = Arrays.stream(configs).map(ContextConfig::locations).collect(toList());
1177+
List<String> locations = Arrays.stream(configs).map(ContextConfig::location).collect(toList());
11811178
assertThat(locations, is(expectedLocations));
11821179

11831180
List<String> values = Arrays.stream(configs).map(ContextConfig::value).collect(toList());
@@ -1197,7 +1194,7 @@ public void synthesizeAnnotationWithArrayOfAnnotations() throws Exception {
11971194
assertNotNull(contextConfig);
11981195

11991196
ContextConfig[] configs = synthesizedHierarchy.value();
1200-
List<String> locations = Arrays.stream(configs).map(ContextConfig::locations).collect(toList());
1197+
List<String> locations = Arrays.stream(configs).map(ContextConfig::location).collect(toList());
12011198
assertThat(locations, is(expectedLocations));
12021199

12031200
// Alter array returned from synthesized annotation
@@ -1571,22 +1568,22 @@ public void handleMappedWithDifferentPathAndValueAttributes() {
15711568
@Retention(RetentionPolicy.RUNTIME)
15721569
@interface ContextConfig {
15731570

1574-
@AliasFor("locations")
1571+
@AliasFor("location")
15751572
String value() default "";
15761573

15771574
@AliasFor("value")
1578-
String locations() default "";
1575+
String location() default "";
15791576
}
15801577

15811578
@Retention(RetentionPolicy.RUNTIME)
15821579
@interface BrokenContextConfig {
15831580

15841581
// Intentionally missing:
1585-
// @AliasFor("locations")
1582+
// @AliasFor("location")
15861583
String value() default "";
15871584

15881585
@AliasFor("value")
1589-
String locations() default "";
1586+
String location() default "";
15901587
}
15911588

15921589
/**
@@ -1602,7 +1599,7 @@ public void handleMappedWithDifferentPathAndValueAttributes() {
16021599
BrokenContextConfig[] value();
16031600
}
16041601

1605-
@Hierarchy({ @ContextConfig("A"), @ContextConfig(locations = "B") })
1602+
@Hierarchy({ @ContextConfig("A"), @ContextConfig(location = "B") })
16061603
static class ConfigHierarchyTestCase {
16071604
}
16081605

@@ -1735,7 +1732,7 @@ static class AliasForAttributeWithDifferentDefaultValueClass {
17351732
@Retention(RetentionPolicy.RUNTIME)
17361733
@interface AliasedComposedContextConfigNotMetaPresent {
17371734

1738-
@AliasFor(annotation = ContextConfig.class, attribute = "locations")
1735+
@AliasFor(annotation = ContextConfig.class, attribute = "location")
17391736
String xmlConfigFile();
17401737
}
17411738

@@ -1747,7 +1744,7 @@ static class AliasedComposedContextConfigNotMetaPresentClass {
17471744
@Retention(RetentionPolicy.RUNTIME)
17481745
@interface AliasedComposedContextConfig {
17491746

1750-
@AliasFor(annotation = ContextConfig.class, attribute = "locations")
1747+
@AliasFor(annotation = ContextConfig.class, attribute = "location")
17511748
String xmlConfigFile();
17521749
}
17531750

@@ -1758,7 +1755,7 @@ static class AliasedComposedContextConfigNotMetaPresentClass {
17581755
}
17591756

17601757
/**
1761-
* Mock of {@code org.springframework.context.annotation.ComponentScan}
1758+
* Mock of {@code org.springframework.context.annotation.ComponentScan}.
17621759
*/
17631760
@Retention(RetentionPolicy.RUNTIME)
17641761
@interface ComponentScan {
@@ -1770,7 +1767,7 @@ static class ComponentScanClass {
17701767
}
17711768

17721769
/**
1773-
* Mock of {@code org.springframework.context.annotation.ComponentScan}
1770+
* Mock of {@code org.springframework.context.annotation.ComponentScan}.
17741771
*/
17751772
@Retention(RetentionPolicy.RUNTIME)
17761773
@interface ComponentScanSingleFilter {

0 commit comments

Comments
 (0)