Skip to content

Commit 3188c0f

Browse files
committed
Ensure fix for gh-28012 is actually tested
In 3ec612a, I accidentally removed tests that verified support for non-synthesizable merged annotations for recursive annotations in Kotlin. This commit reinstates those non-synthesizable tests while retaining the synthesizable tests.
1 parent 3ea540a commit 3188c0f

File tree

6 files changed

+166
-9
lines changed

6 files changed

+166
-9
lines changed

spring-core/src/test/kotlin/org/springframework/core/annotation/Filter.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@ package org.springframework.core.annotation
2424
@Retention(AnnotationRetention.RUNTIME)
2525
public annotation class Filter(
2626

27-
@get:AliasFor("name")
2827
val value: String = "",
2928

30-
@get:AliasFor("value")
31-
val name: String = "",
32-
3329
val and: Filters = Filters()
3430

3531
)

spring-core/src/test/kotlin/org/springframework/core/annotation/KotlinMergedAnnotationsTests.kt

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,34 @@ class KotlinMergedAnnotationsTests {
4141
val mergedAnnotation = MergedAnnotation.from(method.getAnnotation(Person::class.java))
4242
assertThat(mergedAnnotation).isNotNull();
4343

44+
// NON-Synthesized Annotations
45+
val jane = mergedAnnotation.synthesize()
46+
assertThat(jane).isNotInstanceOf(SynthesizedAnnotation::class.java)
47+
assertThat(jane.name).isEqualTo("jane")
48+
val synthesizedFriends = jane.friends
49+
assertThat(synthesizedFriends).hasSize(2)
50+
51+
val john = synthesizedFriends[0]
52+
assertThat(john).isNotInstanceOf(SynthesizedAnnotation::class.java)
53+
assertThat(john.name).isEqualTo("john")
54+
55+
val sally = synthesizedFriends[1]
56+
assertThat(sally).isNotInstanceOf(SynthesizedAnnotation::class.java)
57+
assertThat(sally.name).isEqualTo("sally")
58+
}
59+
60+
@Test // gh-28012
61+
fun recursiveAnnotationWithAttributeAliases() {
62+
val method = javaClass.getMethod("synthesizablePersonMethod")
63+
64+
// MergedAnnotations
65+
val mergedAnnotations = MergedAnnotations.from(method)
66+
assertThat(mergedAnnotations.isPresent(SynthesizablePerson::class.java)).isTrue();
67+
68+
// MergedAnnotation
69+
val mergedAnnotation = MergedAnnotation.from(method.getAnnotation(SynthesizablePerson::class.java))
70+
assertThat(mergedAnnotation).isNotNull();
71+
4472
// Synthesized Annotations
4573
val jane = mergedAnnotation.synthesize()
4674
assertThat(jane).isInstanceOf(SynthesizedAnnotation::class.java)
@@ -72,6 +100,36 @@ class KotlinMergedAnnotationsTests {
72100
val mergedAnnotation = MergedAnnotation.from(method.getAnnotation(Filter::class.java))
73101
assertThat(mergedAnnotation).isNotNull();
74102

103+
// NON-Synthesized Annotations
104+
val fooFilter = mergedAnnotation.synthesize()
105+
assertThat(fooFilter).isNotInstanceOf(SynthesizedAnnotation::class.java)
106+
assertThat(fooFilter.value).isEqualTo("foo")
107+
val filters = fooFilter.and
108+
assertThat(filters.value).hasSize(2)
109+
110+
val barFilter = filters.value[0]
111+
assertThat(barFilter).isNotInstanceOf(SynthesizedAnnotation::class.java)
112+
assertThat(barFilter.value).isEqualTo("bar")
113+
assertThat(barFilter.and.value).isEmpty()
114+
115+
val bazFilter = filters.value[1]
116+
assertThat(bazFilter).isNotInstanceOf(SynthesizedAnnotation::class.java)
117+
assertThat(bazFilter.value).isEqualTo("baz")
118+
assertThat(bazFilter.and.value).isEmpty()
119+
}
120+
121+
@Test // gh-28012
122+
fun recursiveNestedAnnotationWithAttributeAliases() {
123+
val method = javaClass.getMethod("synthesizableFilterMethod")
124+
125+
// MergedAnnotations
126+
val mergedAnnotations = MergedAnnotations.from(method)
127+
assertThat(mergedAnnotations.isPresent(SynthesizableFilter::class.java)).isTrue();
128+
129+
// MergedAnnotation
130+
val mergedAnnotation = MergedAnnotation.from(method.getAnnotation(SynthesizableFilter::class.java))
131+
assertThat(mergedAnnotation).isNotNull();
132+
75133
// Synthesized Annotations
76134
val fooFilter = mergedAnnotation.synthesize()
77135
assertThat(fooFilter).isInstanceOf(SynthesizedAnnotation::class.java)
@@ -94,12 +152,20 @@ class KotlinMergedAnnotationsTests {
94152
}
95153

96154

97-
@Person("jane", friends = [Person("john"), Person("sally")])
155+
@Person(name = "jane", friends = [Person(name = "john"), Person(name = "sally")])
98156
fun personMethod() {
99157
}
100158

159+
@SynthesizablePerson(name = "jane", friends = [SynthesizablePerson(name = "john"), SynthesizablePerson(name = "sally")])
160+
fun synthesizablePersonMethod() {
161+
}
162+
101163
@Filter("foo", and = Filters(Filter("bar"), Filter("baz")))
102164
fun filterMethod() {
103165
}
104166

167+
@SynthesizableFilter("foo", and = SynthesizableFilters(SynthesizableFilter("bar"), SynthesizableFilter("baz")))
168+
fun synthesizableFilterMethod() {
169+
}
170+
105171
}

spring-core/src/test/kotlin/org/springframework/core/annotation/Person.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ package org.springframework.core.annotation
2424
@Retention(AnnotationRetention.RUNTIME)
2525
public annotation class Person(
2626

27-
@get:AliasFor("name")
28-
val value: String = "",
29-
30-
@get:AliasFor("value")
3127
val name: String = "",
3228

3329
vararg val friends: Person = []
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2002-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.core.annotation
18+
19+
/**
20+
* @author Sam Brannen
21+
* @since 5.3.16
22+
*/
23+
@Target(AnnotationTarget.FUNCTION)
24+
@Retention(AnnotationRetention.RUNTIME)
25+
public annotation class SynthesizableFilter(
26+
27+
@get:AliasFor("name")
28+
val value: String = "",
29+
30+
@get:AliasFor("value")
31+
val name: String = "",
32+
33+
val and: SynthesizableFilters = SynthesizableFilters()
34+
35+
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2002-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.core.annotation
18+
19+
/**
20+
* @author Sam Brannen
21+
* @since 5.3.16
22+
*/
23+
@Target(AnnotationTarget.FUNCTION)
24+
@Retention(AnnotationRetention.RUNTIME)
25+
public annotation class SynthesizableFilters(
26+
27+
vararg val value: SynthesizableFilter
28+
29+
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2002-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.core.annotation
18+
19+
/**
20+
* @author Sam Brannen
21+
* @since 5.3.16
22+
*/
23+
@Target(AnnotationTarget.FUNCTION)
24+
@Retention(AnnotationRetention.RUNTIME)
25+
public annotation class SynthesizablePerson(
26+
27+
@get:AliasFor("name")
28+
val value: String = "",
29+
30+
@get:AliasFor("value")
31+
val name: String = "",
32+
33+
vararg val friends: SynthesizablePerson = []
34+
35+
)

0 commit comments

Comments
 (0)