Skip to content

Commit b7a9bee

Browse files
committed
Polishing
1 parent 58246ec commit b7a9bee

File tree

2 files changed

+35
-36
lines changed

2 files changed

+35
-36
lines changed

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

+32-33
Original file line numberDiff line numberDiff line change
@@ -1300,8 +1300,8 @@ void getDirectWithAttributeAliases2() throws Exception {
13001300
@Test
13011301
void getDirectWithAttributeAliasesWithDifferentValues() throws Exception {
13021302
Method method = WebController.class.getMethod("handleMappedWithDifferentPathAndValueAttributes");
1303-
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
1304-
MergedAnnotations.from(method).get(RequestMapping.class))
1303+
assertThatExceptionOfType(AnnotationConfigurationException.class)
1304+
.isThrownBy(() -> MergedAnnotations.from(method).get(RequestMapping.class))
13051305
.withMessageContaining("attribute 'path' and its alias 'value'")
13061306
.withMessageContaining("values of [{/test}] and [{/enigma}]");
13071307
}
@@ -1363,16 +1363,16 @@ void streamRepeatableDeclaredOnMethod() throws Exception {
13631363
@Test
13641364
@SuppressWarnings("deprecation")
13651365
void streamRepeatableDeclaredOnClassWithAttributeAliases() {
1366-
assertThat(MergedAnnotations.from(HierarchyClass.class).stream(
1367-
TestConfiguration.class)).isEmpty();
1368-
RepeatableContainers containers = RepeatableContainers.of(TestConfiguration.class,
1369-
Hierarchy.class);
1366+
assertThat(MergedAnnotations.from(HierarchyClass.class).stream(TestConfiguration.class)).isEmpty();
1367+
RepeatableContainers containers = RepeatableContainers.of(TestConfiguration.class, Hierarchy.class);
13701368
MergedAnnotations annotations = MergedAnnotations.from(HierarchyClass.class,
13711369
SearchStrategy.DIRECT, containers, AnnotationFilter.NONE);
1372-
assertThat(annotations.stream(TestConfiguration.class).map(
1373-
annotation -> annotation.getString("location"))).containsExactly("A", "B");
1374-
assertThat(annotations.stream(TestConfiguration.class).map(
1375-
annotation -> annotation.getString("value"))).containsExactly("A", "B");
1370+
assertThat(annotations.stream(TestConfiguration.class)
1371+
.map(annotation -> annotation.getString("location")))
1372+
.containsExactly("A", "B");
1373+
assertThat(annotations.stream(TestConfiguration.class)
1374+
.map(annotation -> annotation.getString("value")))
1375+
.containsExactly("A", "B");
13761376
}
13771377

13781378
@Test
@@ -1435,14 +1435,12 @@ private void testJavaRepeatables(SearchStrategy searchStrategy, Class<?> element
14351435
MyRepeatable[] annotations = searchStrategy == SearchStrategy.DIRECT ?
14361436
element.getDeclaredAnnotationsByType(MyRepeatable.class) :
14371437
element.getAnnotationsByType(MyRepeatable.class);
1438-
assertThat(Arrays.stream(annotations).map(MyRepeatable::value)).containsExactly(
1439-
expected);
1438+
assertThat(annotations).extracting(MyRepeatable::value).containsExactly(expected);
14401439
}
14411440

14421441
private void testExplicitRepeatables(SearchStrategy searchStrategy, Class<?> element, String[] expected) {
14431442
MergedAnnotations annotations = MergedAnnotations.from(element, searchStrategy,
1444-
RepeatableContainers.of(MyRepeatable.class, MyRepeatableContainer.class),
1445-
AnnotationFilter.PLAIN);
1443+
RepeatableContainers.of(MyRepeatable.class, MyRepeatableContainer.class));
14461444
Stream<String> values = annotations.stream(MyRepeatable.class)
14471445
.filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex))
14481446
.map(annotation -> annotation.getString("value"));
@@ -1594,8 +1592,8 @@ void synthesizeWhenAliasForIsMissingAttributeDeclaration() {
15941592
AliasForWithMissingAttributeDeclarationClass.class.getAnnotation(
15951593
AliasForWithMissingAttributeDeclaration.class);
15961594

1597-
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
1598-
() -> MergedAnnotation.from(annotation))
1595+
assertThatExceptionOfType(AnnotationConfigurationException.class)
1596+
.isThrownBy(() -> MergedAnnotation.from(annotation))
15991597
.withMessageStartingWith("@AliasFor declaration on attribute 'foo' in annotation")
16001598
.withMessageContaining(AliasForWithMissingAttributeDeclaration.class.getName())
16011599
.withMessageContaining("points to itself");
@@ -1607,8 +1605,8 @@ void synthesizeWhenAliasForHasDuplicateAttributeDeclaration() {
16071605
AliasForWithDuplicateAttributeDeclarationClass.class.getAnnotation(
16081606
AliasForWithDuplicateAttributeDeclaration.class);
16091607

1610-
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
1611-
() -> MergedAnnotation.from(annotation))
1608+
assertThatExceptionOfType(AnnotationConfigurationException.class)
1609+
.isThrownBy(() -> MergedAnnotation.from(annotation))
16121610
.withMessageStartingWith("In @AliasFor declared on attribute 'foo' in annotation")
16131611
.withMessageContaining(AliasForWithDuplicateAttributeDeclaration.class.getName())
16141612
.withMessageContaining("attribute 'attribute' and its alias 'value' are present with values of 'baz' and 'bar'");
@@ -1619,8 +1617,8 @@ void synthesizeWhenAttributeAliasForNonexistentAttribute() {
16191617
AliasForNonexistentAttribute annotation = AliasForNonexistentAttributeClass.class.getAnnotation(
16201618
AliasForNonexistentAttribute.class);
16211619

1622-
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
1623-
() -> MergedAnnotation.from(annotation))
1620+
assertThatExceptionOfType(AnnotationConfigurationException.class)
1621+
.isThrownBy(() -> MergedAnnotation.from(annotation))
16241622
.withMessageStartingWith("@AliasFor declaration on attribute 'foo' in annotation")
16251623
.withMessageContaining(AliasForNonexistentAttribute.class.getName())
16261624
.withMessageContaining("declares an alias for 'bar' which is not present");
@@ -1632,8 +1630,8 @@ void synthesizeWhenAttributeAliasWithMirroredAliasForWrongAttribute() {
16321630
AliasForWithMirroredAliasForWrongAttributeClass.class.getAnnotation(
16331631
AliasForWithMirroredAliasForWrongAttribute.class);
16341632

1635-
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
1636-
() -> MergedAnnotation.from(annotation))
1633+
assertThatExceptionOfType(AnnotationConfigurationException.class)
1634+
.isThrownBy(() -> MergedAnnotation.from(annotation))
16371635
.withMessage("@AliasFor declaration on attribute 'bar' in annotation [" +
16381636
AliasForWithMirroredAliasForWrongAttribute.class.getName() +
16391637
"] declares an alias for 'quux' which is not present.");
@@ -1688,8 +1686,8 @@ void synthesizeWhenAttributeAliasForMetaAnnotationThatIsNotMetaPresent() {
16881686
AliasedComposedTestConfigurationNotMetaPresentClass.class.getAnnotation(
16891687
AliasedComposedTestConfigurationNotMetaPresent.class);
16901688

1691-
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
1692-
() -> MergedAnnotation.from(annotation))
1689+
assertThatExceptionOfType(AnnotationConfigurationException.class)
1690+
.isThrownBy(() -> MergedAnnotation.from(annotation))
16931691
.withMessageStartingWith("@AliasFor declaration on attribute 'xmlConfigFile' in annotation")
16941692
.withMessageContaining(AliasedComposedTestConfigurationNotMetaPresent.class.getName())
16951693
.withMessageContaining("declares an alias for attribute 'location' in annotation")
@@ -1781,8 +1779,8 @@ void synthesizeWithImplicitAliasesWithMissingDefaultValues() {
17811779
ImplicitAliasesWithMissingDefaultValuesTestConfiguration.class;
17821780
ImplicitAliasesWithMissingDefaultValuesTestConfiguration config = clazz.getAnnotation(annotationType);
17831781

1784-
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
1785-
() -> MergedAnnotation.from(clazz, config))
1782+
assertThatExceptionOfType(AnnotationConfigurationException.class)
1783+
.isThrownBy(() -> MergedAnnotation.from(clazz, config))
17861784
.withMessageStartingWith("Misconfigured aliases:")
17871785
.withMessageContaining("attribute 'location1' in annotation [" + annotationType.getName() + "]")
17881786
.withMessageContaining("attribute 'location2' in annotation [" + annotationType.getName() + "]")
@@ -1796,8 +1794,8 @@ void synthesizeWithImplicitAliasesWithDifferentDefaultValues() {
17961794
ImplicitAliasesWithDifferentDefaultValuesTestConfiguration.class;
17971795
ImplicitAliasesWithDifferentDefaultValuesTestConfiguration config = clazz.getAnnotation(annotationType);
17981796

1799-
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
1800-
() -> MergedAnnotation.from(clazz, config))
1797+
assertThatExceptionOfType(AnnotationConfigurationException.class)
1798+
.isThrownBy(() -> MergedAnnotation.from(clazz, config))
18011799
.withMessageStartingWith("Misconfigured aliases:")
18021800
.withMessageContaining("attribute 'location1' in annotation [" + annotationType.getName() + "]")
18031801
.withMessageContaining("attribute 'location2' in annotation [" + annotationType.getName() + "]")
@@ -1893,8 +1891,8 @@ void synthesizeFromDefaultsWithAttributeAliases() {
18931891

18941892
@Test
18951893
void synthesizeWhenAttributeAliasesWithDifferentValues() {
1896-
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
1897-
MergedAnnotation.from(TestConfigurationMismatch.class.getAnnotation(TestConfiguration.class)).synthesize());
1894+
assertThatExceptionOfType(AnnotationConfigurationException.class)
1895+
.isThrownBy(() -> MergedAnnotation.from(TestConfigurationMismatch.class.getAnnotation(TestConfiguration.class)));
18981896
}
18991897

19001898
@Test
@@ -1958,8 +1956,8 @@ void synthesizeFromMapWithNullAttributeValue() {
19581956
}
19591957

19601958
private void testMissingTextAttribute(Map<String, Object> attributes) {
1961-
assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(() ->
1962-
MergedAnnotation.of(AnnotationWithoutDefaults.class, attributes).synthesize().text())
1959+
assertThatExceptionOfType(NoSuchElementException.class)
1960+
.isThrownBy(() -> MergedAnnotation.of(AnnotationWithoutDefaults.class, attributes).synthesize().text())
19631961
.withMessage("No value found for attribute named 'text' in merged annotation " +
19641962
AnnotationWithoutDefaults.class.getCanonicalName());
19651963
}
@@ -1968,7 +1966,8 @@ private void testMissingTextAttribute(Map<String, Object> attributes) {
19681966
void synthesizeFromMapWithAttributeOfIncorrectType() {
19691967
Map<String, Object> map = Collections.singletonMap("value", 42L);
19701968
MergedAnnotation<Component> annotation = MergedAnnotation.of(Component.class, map);
1971-
assertThatIllegalStateException().isThrownBy(() -> annotation.synthesize().value())
1969+
assertThatIllegalStateException()
1970+
.isThrownBy(() -> annotation.synthesize().value())
19721971
.withMessage("Attribute 'value' in annotation " +
19731972
"org.springframework.core.testfixture.stereotype.Component should be " +
19741973
"compatible with java.lang.String but a java.lang.Long value was returned");

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -161,9 +161,9 @@ void standardAndExplicitReturnsRepeats() {
161161
RepeatableContainers repeatableContainers = RepeatableContainers.standardRepeatables()
162162
.and(ExplicitContainer.class, ExplicitRepeatable.class);
163163
assertThat(findRepeatedAnnotationValues(repeatableContainers, StandardRepeatablesTestCase.class, StandardContainer.class))
164-
.containsExactly("a", "b");
164+
.containsExactly("a", "b");
165165
assertThat(findRepeatedAnnotationValues(repeatableContainers, ExplicitRepeatablesTestCase.class, ExplicitContainer.class))
166-
.containsExactly("a", "b");
166+
.containsExactly("a", "b");
167167
}
168168

169169
@Test

0 commit comments

Comments
 (0)