Move convention-based attribute override tests to @Nested class
This commit is contained in:
@@ -38,6 +38,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
@@ -75,6 +76,70 @@ import static org.assertj.core.api.Assertions.entry;
|
|||||||
*/
|
*/
|
||||||
class MergedAnnotationsTests {
|
class MergedAnnotationsTests {
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class ConventionBasedAnnotationAttributeOverrideTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getWithInheritedAnnotationsAttributesWithConventionBasedComposedAnnotation() {
|
||||||
|
MergedAnnotation<?> annotation =
|
||||||
|
MergedAnnotations.from(ConventionBasedComposedContextConfigurationClass.class,
|
||||||
|
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
|
||||||
|
assertThat(annotation.isPresent()).isTrue();
|
||||||
|
assertThat(annotation.getStringArray("locations")).containsExactly("explicitDeclaration");
|
||||||
|
assertThat(annotation.getStringArray("value")).containsExactly("explicitDeclaration");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getWithInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation1() {
|
||||||
|
// SPR-13554: convention mapping mixed with AliasFor annotations
|
||||||
|
// xmlConfigFiles can be used because it has an AliasFor annotation
|
||||||
|
MergedAnnotation<?> annotation =
|
||||||
|
MergedAnnotations.from(HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass1.class,
|
||||||
|
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
|
||||||
|
assertThat(annotation.getStringArray("locations")).containsExactly("explicitDeclaration");
|
||||||
|
assertThat(annotation.getStringArray("value")).containsExactly("explicitDeclaration");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void withInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation2() {
|
||||||
|
// SPR-13554: convention mapping mixed with AliasFor annotations
|
||||||
|
// locations doesn't apply because it has no AliasFor annotation
|
||||||
|
MergedAnnotation<?> annotation =
|
||||||
|
MergedAnnotations.from(HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass2.class,
|
||||||
|
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
|
||||||
|
assertThat(annotation.getStringArray("locations")).isEmpty();
|
||||||
|
assertThat(annotation.getStringArray("value")).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getWithInheritedAnnotationsFromInvalidConventionBasedComposedAnnotation() {
|
||||||
|
assertThatExceptionOfType(AnnotationConfigurationException.class)
|
||||||
|
.isThrownBy(() -> MergedAnnotations.from(InvalidConventionBasedComposedContextConfigurationClass.class,
|
||||||
|
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaConvention() {
|
||||||
|
testGetWithTypeHierarchy(ConventionBasedSinglePackageComponentScanClass.class, "com.example.app.test");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getWithTypeHierarchyWithLocalAliasesThatConflictWithAttributesInMetaAnnotationByConvention() {
|
||||||
|
MergedAnnotation<?> annotation =
|
||||||
|
MergedAnnotations.from(SpringApplicationConfigurationClass.class, SearchStrategy.TYPE_HIERARCHY)
|
||||||
|
.get(ContextConfiguration.class);
|
||||||
|
assertThat(annotation.getStringArray("locations")).isEmpty();
|
||||||
|
assertThat(annotation.getStringArray("value")).isEmpty();
|
||||||
|
assertThat(annotation.getClassArray("classes")).containsExactly(Number.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaConvention() throws Exception {
|
||||||
|
testGetWithTypeHierarchyWebMapping(WebController.class.getMethod("postMappedWithPathAttribute"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void fromPreconditions() {
|
void fromPreconditions() {
|
||||||
SearchStrategy strategy = SearchStrategy.DIRECT;
|
SearchStrategy strategy = SearchStrategy.DIRECT;
|
||||||
@@ -347,41 +412,7 @@ class MergedAnnotationsTests {
|
|||||||
assertThat(annotation.isPresent()).isTrue();
|
assertThat(annotation.isPresent()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void getWithInheritedAnnotationsAttributesWithConventionBasedComposedAnnotation() {
|
|
||||||
MergedAnnotation<?> annotation = MergedAnnotations.from(
|
|
||||||
ConventionBasedComposedContextConfigurationClass.class,
|
|
||||||
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
|
|
||||||
assertThat(annotation.isPresent()).isTrue();
|
|
||||||
assertThat(annotation.getStringArray("locations")).containsExactly(
|
|
||||||
"explicitDeclaration");
|
|
||||||
assertThat(annotation.getStringArray("value")).containsExactly(
|
|
||||||
"explicitDeclaration");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getWithInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation1() {
|
|
||||||
// SPR-13554: convention mapping mixed with AliasFor annotations
|
|
||||||
// xmlConfigFiles can be used because it has an AliasFor annotation
|
|
||||||
MergedAnnotation<?> annotation = MergedAnnotations.from(
|
|
||||||
HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass1.class,
|
|
||||||
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
|
|
||||||
assertThat(annotation.getStringArray("locations")).containsExactly(
|
|
||||||
"explicitDeclaration");
|
|
||||||
assertThat(annotation.getStringArray("value")).containsExactly(
|
|
||||||
"explicitDeclaration");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void withInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation2() {
|
|
||||||
// SPR-13554: convention mapping mixed with AliasFor annotations
|
|
||||||
// locations doesn't apply because it has no AliasFor annotation
|
|
||||||
MergedAnnotation<?> annotation = MergedAnnotations.from(
|
|
||||||
HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass2.class,
|
|
||||||
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
|
|
||||||
assertThat(annotation.getStringArray("locations")).isEmpty();
|
|
||||||
assertThat(annotation.getStringArray("value")).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withInheritedAnnotationsFromAliasedComposedAnnotation() {
|
void withInheritedAnnotationsFromAliasedComposedAnnotation() {
|
||||||
@@ -459,13 +490,6 @@ class MergedAnnotationsTests {
|
|||||||
assertThat(annotation.getClassArray("classes")).isEmpty();
|
assertThat(annotation.getClassArray("classes")).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void getWithInheritedAnnotationsFromInvalidConventionBasedComposedAnnotation() {
|
|
||||||
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
|
|
||||||
MergedAnnotations.from(InvalidConventionBasedComposedContextConfigurationClass.class,
|
|
||||||
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getWithInheritedAnnotationsFromShadowedAliasComposedAnnotation() {
|
void getWithInheritedAnnotationsFromShadowedAliasComposedAnnotation() {
|
||||||
MergedAnnotation<?> annotation = MergedAnnotations.from(
|
MergedAnnotation<?> annotation = MergedAnnotations.from(
|
||||||
@@ -628,11 +652,6 @@ class MergedAnnotationsTests {
|
|||||||
testGetWithTypeHierarchy(ComponentScanWithBasePackagesAndValueAliasClass.class, "com.example.app.test");
|
testGetWithTypeHierarchy(ComponentScanWithBasePackagesAndValueAliasClass.class, "com.example.app.test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaConvention() {
|
|
||||||
testGetWithTypeHierarchy(ConventionBasedSinglePackageComponentScanClass.class, "com.example.app.test");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaAliasFor() {
|
void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaAliasFor() {
|
||||||
testGetWithTypeHierarchy(AliasForBasedSinglePackageComponentScanClass.class, "com.example.app.test");
|
testGetWithTypeHierarchy(AliasForBasedSinglePackageComponentScanClass.class, "com.example.app.test");
|
||||||
@@ -661,22 +680,6 @@ class MergedAnnotationsTests {
|
|||||||
"test.properties");
|
"test.properties");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void getWithTypeHierarchyWithLocalAliasesThatConflictWithAttributesInMetaAnnotationByConvention() {
|
|
||||||
MergedAnnotation<?> annotation = MergedAnnotations.from(
|
|
||||||
SpringApplicationConfigurationClass.class, SearchStrategy.TYPE_HIERARCHY).get(
|
|
||||||
ContextConfiguration.class);
|
|
||||||
assertThat(annotation.getStringArray("locations")).isEmpty();
|
|
||||||
assertThat(annotation.getStringArray("value")).isEmpty();
|
|
||||||
assertThat(annotation.getClassArray("classes")).containsExactly(Number.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaConvention() throws Exception {
|
|
||||||
testGetWithTypeHierarchyWebMapping(
|
|
||||||
WebController.class.getMethod("postMappedWithPathAttribute"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaAliasFor() throws Exception {
|
void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaAliasFor() throws Exception {
|
||||||
testGetWithTypeHierarchyWebMapping(
|
testGetWithTypeHierarchyWebMapping(
|
||||||
|
|||||||
Reference in New Issue
Block a user