Skip to content

Commit 3b9d1a0

Browse files
committed
Polishing
1 parent c2141e2 commit 3b9d1a0

File tree

3 files changed

+46
-98
lines changed

3 files changed

+46
-98
lines changed

spring-core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ public MergedAnnotations getAnnotations() {
100100
public Set<String> getAnnotationTypes() {
101101
Set<String> annotationTypes = this.annotationTypes;
102102
if (annotationTypes == null) {
103-
annotationTypes = Collections.unmodifiableSet(
104-
AnnotationMetadata.super.getAnnotationTypes());
103+
annotationTypes = Collections.unmodifiableSet(AnnotationMetadata.super.getAnnotationTypes());
105104
this.annotationTypes = annotationTypes;
106105
}
107106
return annotationTypes;

spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadata.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,4 @@ public MergedAnnotations getAnnotations() {
156156
return this.annotations;
157157
}
158158

159-
160-
161159
}

spring-core/src/test/java/org/springframework/core/type/AbstractAnnotationMetadataTests.java

Lines changed: 45 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public abstract class AbstractAnnotationMetadataTests {
3838

3939
@Test
4040
public void getClassNameReturnsClassName() {
41-
assertThat(get(TestClass.class).getClassName()).isEqualTo(
42-
TestClass.class.getName());
41+
assertThat(get(TestClass.class).getClassName()).isEqualTo(TestClass.class.getName());
4342
}
4443

4544
@Test
@@ -93,16 +92,13 @@ public void getEnclosingClassNameWhenHasEnclosingClassReturnsEnclosingClass() {
9392

9493
@Test
9594
public void getEnclosingClassNameWhenHasNoEnclosingClassReturnsNull() {
96-
assertThat(get(
97-
AbstractAnnotationMetadataTests.class).getEnclosingClassName()).isNull();
95+
assertThat(get(AbstractAnnotationMetadataTests.class).getEnclosingClassName()).isNull();
9896
}
9997

10098
@Test
10199
public void getSuperClassNameWhenHasSuperClassReturnsName() {
102-
assertThat(get(TestSubclass.class).getSuperClassName()).isEqualTo(
103-
TestClass.class.getName());
104-
assertThat(get(TestClass.class).getSuperClassName()).isEqualTo(
105-
Object.class.getName());
100+
assertThat(get(TestSubclass.class).getSuperClassName()).isEqualTo(TestClass.class.getName());
101+
assertThat(get(TestClass.class).getSuperClassName()).isEqualTo(Object.class.getName());
106102
}
107103

108104
@Test
@@ -114,11 +110,8 @@ public void getSuperClassNameWhenHasNoSuperClassReturnsNull() {
114110

115111
@Test
116112
public void getInterfaceNamesWhenHasInterfacesReturnsNames() {
117-
assertThat(get(TestSubclass.class).getInterfaceNames()).containsExactlyInAnyOrder(
118-
TestInterface.class.getName());
119-
assertThat(get(
120-
TestSubInterface.class).getInterfaceNames()).containsExactlyInAnyOrder(
121-
TestInterface.class.getName());
113+
assertThat(get(TestSubclass.class).getInterfaceNames()).containsExactlyInAnyOrder(TestInterface.class.getName());
114+
assertThat(get(TestSubInterface.class).getInterfaceNames()).containsExactlyInAnyOrder(TestInterface.class.getName());
122115
}
123116

124117
@Test
@@ -128,10 +121,8 @@ public void getInterfaceNamesWhenHasNoInterfacesReturnsEmptyArray() {
128121

129122
@Test
130123
public void getMemberClassNamesWhenHasMemberClassesReturnsNames() {
131-
assertThat(get(
132-
TestMemberClass.class).getMemberClassNames()).containsExactlyInAnyOrder(
133-
TestMemberClassInnerClass.class.getName(),
134-
TestMemberClassInnerInterface.class.getName());
124+
assertThat(get(TestMemberClass.class).getMemberClassNames()).containsExactlyInAnyOrder(
125+
TestMemberClassInnerClass.class.getName(), TestMemberClassInnerInterface.class.getName());
135126
}
136127

137128
@Test
@@ -141,44 +132,37 @@ public void getMemberClassNamesWhenHasNoMemberClassesReturnsEmptyArray() {
141132

142133
@Test
143134
public void getAnnotationsReturnsDirectAnnotations() {
144-
AnnotationMetadata metadata = get(WithDirectAnnotations.class);
145-
assertThat(metadata.getAnnotations().stream().filter(
146-
MergedAnnotation::isDirectlyPresent).map(
147-
a -> a.getType().getName())).containsExactlyInAnyOrder(
148-
DirectAnnotation1.class.getName(),
149-
DirectAnnotation2.class.getName());
135+
assertThat(get(WithDirectAnnotations.class).getAnnotations().stream())
136+
.filteredOn(MergedAnnotation::isDirectlyPresent)
137+
.extracting(a -> a.getType().getName())
138+
.containsExactlyInAnyOrder(DirectAnnotation1.class.getName(), DirectAnnotation2.class.getName());
150139
}
151140

152141
@Test
153142
public void isAnnotatedWhenMatchesDirectAnnotationReturnsTrue() {
154-
assertThat(get(WithDirectAnnotations.class).isAnnotated(
155-
DirectAnnotation1.class.getName())).isTrue();
143+
assertThat(get(WithDirectAnnotations.class).isAnnotated(DirectAnnotation1.class.getName())).isTrue();
156144
}
157145

158146
@Test
159147
public void isAnnotatedWhenMatchesMetaAnnotationReturnsTrue() {
160-
assertThat(get(WithMetaAnnotations.class).isAnnotated(
161-
MetaAnnotation2.class.getName())).isTrue();
148+
assertThat(get(WithMetaAnnotations.class).isAnnotated(MetaAnnotation2.class.getName())).isTrue();
162149
}
163150

164151
@Test
165152
public void isAnnotatedWhenDoesNotMatchDirectOrMetaAnnotationReturnsFalse() {
166-
assertThat(get(TestClass.class).isAnnotated(
167-
DirectAnnotation1.class.getName())).isFalse();
153+
assertThat(get(TestClass.class).isAnnotated(DirectAnnotation1.class.getName())).isFalse();
168154
}
169155

170156
@Test
171157
public void getAnnotationAttributesReturnsAttributes() {
172-
assertThat(get(WithAnnotationAttributes.class).getAnnotationAttributes(
173-
AnnotationAttributes.class.getName())).containsOnly(entry("name", "test"),
174-
entry("size", 1));
158+
assertThat(get(WithAnnotationAttributes.class).getAnnotationAttributes(AnnotationAttributes.class.getName()))
159+
.containsOnly(entry("name", "test"), entry("size", 1));
175160
}
176161

177162
@Test
178163
public void getAllAnnotationAttributesReturnsAllAttributes() {
179-
MultiValueMap<String, Object> attributes = get(
180-
WithMetaAnnotationAttributes.class).getAllAnnotationAttributes(
181-
AnnotationAttributes.class.getName());
164+
MultiValueMap<String, Object> attributes =
165+
get(WithMetaAnnotationAttributes.class).getAllAnnotationAttributes(AnnotationAttributes.class.getName());
182166
assertThat(attributes).containsOnlyKeys("name", "size");
183167
assertThat(attributes.get("name")).containsExactlyInAnyOrder("m1", "m2");
184168
assertThat(attributes.get("size")).containsExactlyInAnyOrder(1, 2);
@@ -194,155 +178,126 @@ public void getAnnotationTypesReturnsDirectAnnotations() {
194178
@Test
195179
public void getMetaAnnotationTypesReturnsMetaAnnotations() {
196180
AnnotationMetadata metadata = get(WithMetaAnnotations.class);
197-
assertThat(metadata.getMetaAnnotationTypes(
198-
MetaAnnotationRoot.class.getName())).containsExactlyInAnyOrder(
199-
MetaAnnotation1.class.getName(), MetaAnnotation2.class.getName());
181+
assertThat(metadata.getMetaAnnotationTypes(MetaAnnotationRoot.class.getName()))
182+
.containsExactlyInAnyOrder(MetaAnnotation1.class.getName(), MetaAnnotation2.class.getName());
200183
}
201184

202185
@Test
203186
public void hasAnnotationWhenMatchesDirectAnnotationReturnsTrue() {
204-
assertThat(get(WithDirectAnnotations.class).hasAnnotation(
205-
DirectAnnotation1.class.getName())).isTrue();
187+
assertThat(get(WithDirectAnnotations.class).hasAnnotation(DirectAnnotation1.class.getName())).isTrue();
206188
}
207189

208190
@Test
209191
public void hasAnnotationWhenMatchesMetaAnnotationReturnsFalse() {
210-
assertThat(get(WithMetaAnnotations.class).hasAnnotation(
211-
MetaAnnotation1.class.getName())).isFalse();
212-
assertThat(get(WithMetaAnnotations.class).hasAnnotation(
213-
MetaAnnotation2.class.getName())).isFalse();
192+
assertThat(get(WithMetaAnnotations.class).hasAnnotation(MetaAnnotation1.class.getName())).isFalse();
193+
assertThat(get(WithMetaAnnotations.class).hasAnnotation(MetaAnnotation2.class.getName())).isFalse();
214194
}
215195

216196
@Test
217197
public void hasAnnotationWhenDoesNotMatchDirectOrMetaAnnotationReturnsFalse() {
218-
assertThat(get(TestClass.class).hasAnnotation(
219-
DirectAnnotation1.class.getName())).isFalse();
198+
assertThat(get(TestClass.class).hasAnnotation(DirectAnnotation1.class.getName())).isFalse();
220199
}
221200

222201
@Test
223202
public void hasMetaAnnotationWhenMatchesDirectReturnsFalse() {
224-
assertThat(get(WithDirectAnnotations.class).hasMetaAnnotation(
225-
DirectAnnotation1.class.getName())).isFalse();
203+
assertThat(get(WithDirectAnnotations.class).hasMetaAnnotation(DirectAnnotation1.class.getName())).isFalse();
226204
}
227205

228206
@Test
229207
public void hasMetaAnnotationWhenMatchesMetaAnnotationReturnsTrue() {
230-
assertThat(get(WithMetaAnnotations.class).hasMetaAnnotation(
231-
MetaAnnotation1.class.getName())).isTrue();
232-
assertThat(get(WithMetaAnnotations.class).hasMetaAnnotation(
233-
MetaAnnotation2.class.getName())).isTrue();
208+
assertThat(get(WithMetaAnnotations.class).hasMetaAnnotation(MetaAnnotation1.class.getName())).isTrue();
209+
assertThat(get(WithMetaAnnotations.class).hasMetaAnnotation(MetaAnnotation2.class.getName())).isTrue();
234210
}
235211

236212
@Test
237213
public void hasMetaAnnotationWhenDoesNotMatchDirectOrMetaAnnotationReturnsFalse() {
238-
assertThat(get(TestClass.class).hasMetaAnnotation(
239-
MetaAnnotation1.class.getName())).isFalse();
214+
assertThat(get(TestClass.class).hasMetaAnnotation(MetaAnnotation1.class.getName())).isFalse();
240215
}
241216

242217
@Test
243218
public void hasAnnotatedMethodsWhenMatchesDirectAnnotationReturnsTrue() {
244-
assertThat(get(WithAnnotatedMethod.class).hasAnnotatedMethods(
245-
DirectAnnotation1.class.getName())).isTrue();
219+
assertThat(get(WithAnnotatedMethod.class).hasAnnotatedMethods(DirectAnnotation1.class.getName())).isTrue();
246220
}
247221

248222
@Test
249223
public void hasAnnotatedMethodsWhenMatchesMetaAnnotationReturnsTrue() {
250-
assertThat(get(WithMetaAnnotatedMethod.class).hasAnnotatedMethods(
251-
MetaAnnotation2.class.getName())).isTrue();
224+
assertThat(get(WithMetaAnnotatedMethod.class).hasAnnotatedMethods(MetaAnnotation2.class.getName())).isTrue();
252225
}
253226

254227
@Test
255228
public void hasAnnotatedMethodsWhenDoesNotMatchAnyAnnotationReturnsFalse() {
256-
assertThat(get(WithAnnotatedMethod.class).hasAnnotatedMethods(
257-
MetaAnnotation2.class.getName())).isFalse();
258-
assertThat(get(WithNonAnnotatedMethod.class).hasAnnotatedMethods(
259-
DirectAnnotation1.class.getName())).isFalse();
229+
assertThat(get(WithAnnotatedMethod.class).hasAnnotatedMethods(MetaAnnotation2.class.getName())).isFalse();
230+
assertThat(get(WithNonAnnotatedMethod.class).hasAnnotatedMethods(DirectAnnotation1.class.getName())).isFalse();
260231
}
261232

262233
@Test
263234
public void getAnnotatedMethodsReturnsMatchingAnnotatedAndMetaAnnotatedMethods() {
264-
assertThat(get(WithDirectAndMetaAnnotatedMethods.class).getAnnotatedMethods(
265-
MetaAnnotation2.class.getName()).stream().map(
266-
MethodMetadata::getMethodName)).containsExactlyInAnyOrder(
267-
"direct", "meta");
235+
assertThat(get(WithDirectAndMetaAnnotatedMethods.class).getAnnotatedMethods(MetaAnnotation2.class.getName()))
236+
.extracting(MethodMetadata::getMethodName)
237+
.containsExactlyInAnyOrder("direct", "meta");
268238
}
269239

270240
protected abstract AnnotationMetadata get(Class<?> source);
271241

272-
@Retention(RetentionPolicy.RUNTIME)
273-
public static @interface DirectAnnotation1 {
274242

243+
@Retention(RetentionPolicy.RUNTIME)
244+
public @interface DirectAnnotation1 {
275245
}
276246

277247
@Retention(RetentionPolicy.RUNTIME)
278-
public static @interface DirectAnnotation2 {
279-
248+
public @interface DirectAnnotation2 {
280249
}
281250

282251
@Retention(RetentionPolicy.RUNTIME)
283252
@MetaAnnotation1
284-
public static @interface MetaAnnotationRoot {
285-
253+
public @interface MetaAnnotationRoot {
286254
}
287255

288256
@Retention(RetentionPolicy.RUNTIME)
289257
@MetaAnnotation2
290-
public static @interface MetaAnnotation1 {
291-
258+
public @interface MetaAnnotation1 {
292259
}
293260

294261
@Retention(RetentionPolicy.RUNTIME)
295-
public static @interface MetaAnnotation2 {
296-
262+
public @interface MetaAnnotation2 {
297263
}
298264

299265
public static class TestClass {
300-
301266
}
302267

303268
public static interface TestInterface {
304-
305269
}
306270

307271
public static interface TestSubInterface extends TestInterface {
308-
309272
}
310273

311274
public @interface TestAnnotation {
312-
313275
}
314276

315277
public static final class TestFinalClass {
316-
317278
}
318279

319280
public class TestNonStaticInnerClass {
320-
321281
}
322282

323283
public static class TestSubclass extends TestClass implements TestInterface {
324-
325284
}
326285

327286
@DirectAnnotation1
328287
@DirectAnnotation2
329288
public static class WithDirectAnnotations {
330-
331289
}
332290

333291
@MetaAnnotationRoot
334292
public static class WithMetaAnnotations {
335-
336293
}
337294

338295
public static class TestMemberClass {
339296

340297
public static class TestMemberClassInnerClass {
341-
342298
}
343299

344300
interface TestMemberClassInnerInterface {
345-
346301
}
347302

348303
}
@@ -384,29 +339,25 @@ public void meta() {
384339

385340
@AnnotationAttributes(name = "test", size = 1)
386341
public static class WithAnnotationAttributes {
387-
388342
}
389343

390344
@MetaAnnotationAttributes1
391345
@MetaAnnotationAttributes2
392346
public static class WithMetaAnnotationAttributes {
393-
394347
}
395348

396349
@Retention(RetentionPolicy.RUNTIME)
397350
@AnnotationAttributes(name = "m1", size = 1)
398-
public static @interface MetaAnnotationAttributes1 {
399-
351+
public @interface MetaAnnotationAttributes1 {
400352
}
401353

402354
@Retention(RetentionPolicy.RUNTIME)
403355
@AnnotationAttributes(name = "m2", size = 2)
404-
public static @interface MetaAnnotationAttributes2 {
405-
356+
public @interface MetaAnnotationAttributes2 {
406357
}
407358

408359
@Retention(RetentionPolicy.RUNTIME)
409-
public static @interface AnnotationAttributes {
360+
public @interface AnnotationAttributes {
410361

411362
String name();
412363

0 commit comments

Comments
 (0)