mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-10-01 03:39:05 +00:00
Test single-value to primitive array adaptation via @AliasFor
This commit adds a test to MergedAnnotationsTests that verifies a single primitive attribute in a composed annotation can be aliased via @AliasFor to a primitive array attribute in a meta-annotation. See gh-37349
This commit is contained in:
+51
@@ -596,6 +596,19 @@ class MergedAnnotationsTests {
|
||||
assertThat(annotation.getClassArray("classes")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithSingleValuePrimitiveAttributesOverridingPrimitiveArraysViaAliasFor() {
|
||||
MergedAnnotation<PrimitiveArrays> annotation = MergedAnnotations.from(ComposedPrimitiveSingleValuesClass.class)
|
||||
.get(PrimitiveArrays.class);
|
||||
assertThat(annotation.isPresent()).isTrue();
|
||||
assertThat(annotation.getIntArray("ints")).containsExactly(42);
|
||||
assertThat(annotation.getLongArray("longs")).containsExactly(42L);
|
||||
assertThat(annotation.getBooleanArray("booleans")).containsExactly(true);
|
||||
assertThat(annotation.getCharArray("chars")).containsExactly('c');
|
||||
assertThat(annotation.getDoubleArray("doubles")).containsExactly(4.2d);
|
||||
assertThat(annotation.synthesize().ints()).containsExactly(42);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithInheritedAnnotationsFromShadowedAliasComposedAnnotation() {
|
||||
MergedAnnotation<?> annotation = MergedAnnotations.from(
|
||||
@@ -2274,6 +2287,44 @@ class MergedAnnotationsTests {
|
||||
@interface ComposedTransactionalComponent {
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface PrimitiveArrays {
|
||||
|
||||
int[] ints() default {};
|
||||
|
||||
long[] longs() default {};
|
||||
|
||||
boolean[] booleans() default {};
|
||||
|
||||
char[] chars() default {};
|
||||
|
||||
double[] doubles() default {};
|
||||
}
|
||||
|
||||
@PrimitiveArrays
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface ComposedPrimitiveSingleValues {
|
||||
|
||||
@AliasFor(annotation = PrimitiveArrays.class, attribute = "ints")
|
||||
int anInt() default 0;
|
||||
|
||||
@AliasFor(annotation = PrimitiveArrays.class, attribute = "longs")
|
||||
long aLong() default 0L;
|
||||
|
||||
@AliasFor(annotation = PrimitiveArrays.class, attribute = "booleans")
|
||||
boolean aBoolean() default false;
|
||||
|
||||
@AliasFor(annotation = PrimitiveArrays.class, attribute = "chars")
|
||||
char aChar() default 'x';
|
||||
|
||||
@AliasFor(annotation = PrimitiveArrays.class, attribute = "doubles")
|
||||
double aDouble() default 0.0d;
|
||||
}
|
||||
|
||||
@ComposedPrimitiveSingleValues(anInt = 42, aLong = 42L, aBoolean = true, aChar = 'c', aDouble = 4.2d)
|
||||
static class ComposedPrimitiveSingleValuesClass {
|
||||
}
|
||||
|
||||
static class NonAnnotatedClass {
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user