Ensure local aliases don't override meta-annotation
This commit introduces an additional test case to ensure that explicit local attribute aliases (configured via @AliasFor) do not accidentally override attributes of the same names in meta-annotations (i.e., by convention). Issue: SPR-13325
This commit is contained in:
parent
4317e76e79
commit
e20b47c3bc
|
@ -530,6 +530,18 @@ public class AnnotatedElementUtilsTests {
|
|||
assertEquals(asList("*Test", "*Tests"), patterns);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findMergedAnnotationWithLocalAliasesThatConflictWithAttributesInMetaAnnotationByConvention() {
|
||||
final String[] EMPTY = new String[] {};
|
||||
Class<?> element = SpringAppConfigClass.class;
|
||||
ContextConfig contextConfig = findMergedAnnotation(element, ContextConfig.class);
|
||||
assertNotNull("Should find @ContextConfig on " + element, contextConfig);
|
||||
assertArrayEquals("locations for " + element, EMPTY, contextConfig.locations());
|
||||
// 'value' in @SpringAppConfig should not override 'value' in @ContextConfig
|
||||
assertArrayEquals("value for " + element, EMPTY, contextConfig.value());
|
||||
assertArrayEquals("classes for " + element, new Class<?>[] { Number.class }, contextConfig.classes());
|
||||
}
|
||||
|
||||
private Set<String> names(Class<?>... classes) {
|
||||
return stream(classes).map(Class::getName).collect(toSet());
|
||||
}
|
||||
|
@ -670,6 +682,8 @@ public class AnnotatedElementUtilsTests {
|
|||
|
||||
@AliasFor(attribute = "value")
|
||||
String[] locations() default {};
|
||||
|
||||
Class<?>[] classes() default {};
|
||||
}
|
||||
|
||||
@ContextConfig
|
||||
|
@ -725,6 +739,23 @@ public class AnnotatedElementUtilsTests {
|
|||
String[] xmlConfigFiles() default "default.xml";
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock of {@code org.springframework.boot.test.SpringApplicationConfiguration}.
|
||||
*/
|
||||
@ContextConfig
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface SpringAppConfig {
|
||||
|
||||
@AliasFor(annotation = ContextConfig.class, attribute = "locations")
|
||||
String[] locations() default {};
|
||||
|
||||
@AliasFor("value")
|
||||
Class<?>[] classes() default {};
|
||||
|
||||
@AliasFor("classes")
|
||||
Class<?>[] value() default {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock of {@code org.springframework.context.annotation.ComponentScan}
|
||||
*/
|
||||
|
@ -909,4 +940,8 @@ public class AnnotatedElementUtilsTests {
|
|||
static class TestComponentScanClass {
|
||||
}
|
||||
|
||||
@SpringAppConfig(Number.class)
|
||||
static class SpringAppConfigClass {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue