|
38 | 38 |
|
39 | 39 | import javax.annotation.Resource;
|
40 | 40 |
|
| 41 | +import org.junit.jupiter.api.Nested; |
41 | 42 | import org.junit.jupiter.api.Test;
|
42 | 43 |
|
43 | 44 | import org.springframework.core.Ordered;
|
|
75 | 76 | */
|
76 | 77 | class MergedAnnotationsTests {
|
77 | 78 |
|
| 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 | + |
78 | 143 | @Test
|
79 | 144 | void fromPreconditions() {
|
80 | 145 | SearchStrategy strategy = SearchStrategy.DIRECT;
|
@@ -347,41 +412,7 @@ void getWithInheritedAnnotationsFromNonInheritedAnnotationInterface() {
|
347 | 412 | assertThat(annotation.isPresent()).isTrue();
|
348 | 413 | }
|
349 | 414 |
|
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 |
| - } |
361 | 415 |
|
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 |
| - } |
385 | 416 |
|
386 | 417 | @Test
|
387 | 418 | void withInheritedAnnotationsFromAliasedComposedAnnotation() {
|
@@ -459,13 +490,6 @@ private void testGetWithInherited(Class<?> element, String... expected) {
|
459 | 490 | assertThat(annotation.getClassArray("classes")).isEmpty();
|
460 | 491 | }
|
461 | 492 |
|
462 |
| - @Test |
463 |
| - void getWithInheritedAnnotationsFromInvalidConventionBasedComposedAnnotation() { |
464 |
| - assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() -> |
465 |
| - MergedAnnotations.from(InvalidConventionBasedComposedContextConfigurationClass.class, |
466 |
| - SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class)); |
467 |
| - } |
468 |
| - |
469 | 493 | @Test
|
470 | 494 | void getWithInheritedAnnotationsFromShadowedAliasComposedAnnotation() {
|
471 | 495 | MergedAnnotation<?> annotation = MergedAnnotations.from(
|
@@ -628,11 +652,6 @@ void getWithTypeHierarchyFromClassWithBothAttributesOfAnAliasPairDeclared() {
|
628 | 652 | testGetWithTypeHierarchy(ComponentScanWithBasePackagesAndValueAliasClass.class, "com.example.app.test");
|
629 | 653 | }
|
630 | 654 |
|
631 |
| - @Test |
632 |
| - void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaConvention() { |
633 |
| - testGetWithTypeHierarchy(ConventionBasedSinglePackageComponentScanClass.class, "com.example.app.test"); |
634 |
| - } |
635 |
| - |
636 | 655 | @Test
|
637 | 656 | void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaAliasFor() {
|
638 | 657 | testGetWithTypeHierarchy(AliasForBasedSinglePackageComponentScanClass.class, "com.example.app.test");
|
@@ -661,22 +680,6 @@ void getWithTypeHierarchyWhenMultipleMetaAnnotationsHaveClashingAttributeNames()
|
661 | 680 | "test.properties");
|
662 | 681 | }
|
663 | 682 |
|
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 |
| - |
680 | 683 | @Test
|
681 | 684 | void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaAliasFor() throws Exception {
|
682 | 685 | testGetWithTypeHierarchyWebMapping(
|
|
0 commit comments