Skip to content

Commit 07cfcbc

Browse files
committed
Move convention-based attribute override tests to @nested class
1 parent 2af27d8 commit 07cfcbc

File tree

1 file changed

+65
-62
lines changed

1 file changed

+65
-62
lines changed

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

Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import javax.annotation.Resource;
4040

41+
import org.junit.jupiter.api.Nested;
4142
import org.junit.jupiter.api.Test;
4243

4344
import org.springframework.core.Ordered;
@@ -75,6 +76,70 @@
7576
*/
7677
class MergedAnnotationsTests {
7778

79+
@Nested
80+
class ConventionBasedAnnotationAttributeOverrideTests {
81+
82+
@Test
83+
void getWithInheritedAnnotationsAttributesWithConventionBasedComposedAnnotation() {
84+
MergedAnnotation<?> annotation =
85+
MergedAnnotations.from(ConventionBasedComposedContextConfigurationClass.class,
86+
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
87+
assertThat(annotation.isPresent()).isTrue();
88+
assertThat(annotation.getStringArray("locations")).containsExactly("explicitDeclaration");
89+
assertThat(annotation.getStringArray("value")).containsExactly("explicitDeclaration");
90+
}
91+
92+
@Test
93+
void getWithInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation1() {
94+
// SPR-13554: convention mapping mixed with AliasFor annotations
95+
// xmlConfigFiles can be used because it has an AliasFor annotation
96+
MergedAnnotation<?> annotation =
97+
MergedAnnotations.from(HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass1.class,
98+
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
99+
assertThat(annotation.getStringArray("locations")).containsExactly("explicitDeclaration");
100+
assertThat(annotation.getStringArray("value")).containsExactly("explicitDeclaration");
101+
}
102+
103+
@Test
104+
void withInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation2() {
105+
// SPR-13554: convention mapping mixed with AliasFor annotations
106+
// locations doesn't apply because it has no AliasFor annotation
107+
MergedAnnotation<?> annotation =
108+
MergedAnnotations.from(HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass2.class,
109+
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
110+
assertThat(annotation.getStringArray("locations")).isEmpty();
111+
assertThat(annotation.getStringArray("value")).isEmpty();
112+
}
113+
114+
@Test
115+
void getWithInheritedAnnotationsFromInvalidConventionBasedComposedAnnotation() {
116+
assertThatExceptionOfType(AnnotationConfigurationException.class)
117+
.isThrownBy(() -> MergedAnnotations.from(InvalidConventionBasedComposedContextConfigurationClass.class,
118+
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class));
119+
}
120+
121+
@Test
122+
void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaConvention() {
123+
testGetWithTypeHierarchy(ConventionBasedSinglePackageComponentScanClass.class, "com.example.app.test");
124+
}
125+
126+
@Test
127+
void getWithTypeHierarchyWithLocalAliasesThatConflictWithAttributesInMetaAnnotationByConvention() {
128+
MergedAnnotation<?> annotation =
129+
MergedAnnotations.from(SpringApplicationConfigurationClass.class, SearchStrategy.TYPE_HIERARCHY)
130+
.get(ContextConfiguration.class);
131+
assertThat(annotation.getStringArray("locations")).isEmpty();
132+
assertThat(annotation.getStringArray("value")).isEmpty();
133+
assertThat(annotation.getClassArray("classes")).containsExactly(Number.class);
134+
}
135+
136+
@Test
137+
void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaConvention() throws Exception {
138+
testGetWithTypeHierarchyWebMapping(WebController.class.getMethod("postMappedWithPathAttribute"));
139+
}
140+
141+
}
142+
78143
@Test
79144
void fromPreconditions() {
80145
SearchStrategy strategy = SearchStrategy.DIRECT;
@@ -347,41 +412,7 @@ void getWithInheritedAnnotationsFromNonInheritedAnnotationInterface() {
347412
assertThat(annotation.isPresent()).isTrue();
348413
}
349414

350-
@Test
351-
void getWithInheritedAnnotationsAttributesWithConventionBasedComposedAnnotation() {
352-
MergedAnnotation<?> annotation = MergedAnnotations.from(
353-
ConventionBasedComposedContextConfigurationClass.class,
354-
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
355-
assertThat(annotation.isPresent()).isTrue();
356-
assertThat(annotation.getStringArray("locations")).containsExactly(
357-
"explicitDeclaration");
358-
assertThat(annotation.getStringArray("value")).containsExactly(
359-
"explicitDeclaration");
360-
}
361415

362-
@Test
363-
void getWithInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation1() {
364-
// SPR-13554: convention mapping mixed with AliasFor annotations
365-
// xmlConfigFiles can be used because it has an AliasFor annotation
366-
MergedAnnotation<?> annotation = MergedAnnotations.from(
367-
HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass1.class,
368-
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
369-
assertThat(annotation.getStringArray("locations")).containsExactly(
370-
"explicitDeclaration");
371-
assertThat(annotation.getStringArray("value")).containsExactly(
372-
"explicitDeclaration");
373-
}
374-
375-
@Test
376-
void withInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation2() {
377-
// SPR-13554: convention mapping mixed with AliasFor annotations
378-
// locations doesn't apply because it has no AliasFor annotation
379-
MergedAnnotation<?> annotation = MergedAnnotations.from(
380-
HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass2.class,
381-
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
382-
assertThat(annotation.getStringArray("locations")).isEmpty();
383-
assertThat(annotation.getStringArray("value")).isEmpty();
384-
}
385416

386417
@Test
387418
void withInheritedAnnotationsFromAliasedComposedAnnotation() {
@@ -459,13 +490,6 @@ private void testGetWithInherited(Class<?> element, String... expected) {
459490
assertThat(annotation.getClassArray("classes")).isEmpty();
460491
}
461492

462-
@Test
463-
void getWithInheritedAnnotationsFromInvalidConventionBasedComposedAnnotation() {
464-
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
465-
MergedAnnotations.from(InvalidConventionBasedComposedContextConfigurationClass.class,
466-
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class));
467-
}
468-
469493
@Test
470494
void getWithInheritedAnnotationsFromShadowedAliasComposedAnnotation() {
471495
MergedAnnotation<?> annotation = MergedAnnotations.from(
@@ -628,11 +652,6 @@ void getWithTypeHierarchyFromClassWithBothAttributesOfAnAliasPairDeclared() {
628652
testGetWithTypeHierarchy(ComponentScanWithBasePackagesAndValueAliasClass.class, "com.example.app.test");
629653
}
630654

631-
@Test
632-
void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaConvention() {
633-
testGetWithTypeHierarchy(ConventionBasedSinglePackageComponentScanClass.class, "com.example.app.test");
634-
}
635-
636655
@Test
637656
void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaAliasFor() {
638657
testGetWithTypeHierarchy(AliasForBasedSinglePackageComponentScanClass.class, "com.example.app.test");
@@ -661,22 +680,6 @@ void getWithTypeHierarchyWhenMultipleMetaAnnotationsHaveClashingAttributeNames()
661680
"test.properties");
662681
}
663682

664-
@Test
665-
void getWithTypeHierarchyWithLocalAliasesThatConflictWithAttributesInMetaAnnotationByConvention() {
666-
MergedAnnotation<?> annotation = MergedAnnotations.from(
667-
SpringApplicationConfigurationClass.class, SearchStrategy.TYPE_HIERARCHY).get(
668-
ContextConfiguration.class);
669-
assertThat(annotation.getStringArray("locations")).isEmpty();
670-
assertThat(annotation.getStringArray("value")).isEmpty();
671-
assertThat(annotation.getClassArray("classes")).containsExactly(Number.class);
672-
}
673-
674-
@Test
675-
void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaConvention() throws Exception {
676-
testGetWithTypeHierarchyWebMapping(
677-
WebController.class.getMethod("postMappedWithPathAttribute"));
678-
}
679-
680683
@Test
681684
void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaAliasFor() throws Exception {
682685
testGetWithTypeHierarchyWebMapping(

0 commit comments

Comments
 (0)