Skip to content

Commit f42955c

Browse files
committed
Polishing
1 parent d6c9c7d commit f42955c

File tree

1 file changed

+37
-74
lines changed

1 file changed

+37
-74
lines changed

spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java

Lines changed: 37 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.core.annotation;
1818

19-
import java.io.Serializable;
2019
import java.lang.annotation.Annotation;
2120
import java.lang.annotation.Inherited;
2221
import java.lang.annotation.Retention;
@@ -53,36 +52,31 @@ void directStrategyOnClassWhenNotAnnotatedScansNone() {
5352
@Test
5453
void directStrategyOnClassScansAnnotations() {
5554
Class<?> source = WithSingleAnnotation.class;
56-
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly(
57-
"0:TestAnnotation1");
55+
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly("0:TestAnnotation1");
5856
}
5957

6058
@Test
6159
void directStrategyOnClassWhenMultipleAnnotationsScansAnnotations() {
6260
Class<?> source = WithMultipleAnnotations.class;
63-
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly(
64-
"0:TestAnnotation1", "0:TestAnnotation2");
61+
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly("0:TestAnnotation1", "0:TestAnnotation2");
6562
}
6663

6764
@Test
6865
void directStrategyOnClassWhenHasSuperclassScansOnlyDirect() {
6966
Class<?> source = WithSingleSuperclass.class;
70-
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly(
71-
"0:TestAnnotation1");
67+
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly("0:TestAnnotation1");
7268
}
7369

7470
@Test
7571
void directStrategyOnClassWhenHasInterfaceScansOnlyDirect() {
7672
Class<?> source = WithSingleInterface.class;
77-
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly(
78-
"0:TestAnnotation1");
73+
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly("0:TestAnnotation1");
7974
}
8075

8176
@Test
8277
void directStrategyOnClassHierarchyScansInCorrectOrder() {
8378
Class<?> source = WithHierarchy.class;
84-
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly(
85-
"0:TestAnnotation1");
79+
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly("0:TestAnnotation1");
8680
}
8781

8882
@Test
@@ -94,8 +88,7 @@ void inheritedAnnotationsStrategyOnClassWhenNotAnnotatedScansNone() {
9488
@Test
9589
void inheritedAnnotationsStrategyOnClassScansAnnotations() {
9690
Class<?> source = WithSingleAnnotation.class;
97-
assertThat(scan(source, SearchStrategy.INHERITED_ANNOTATIONS)).containsExactly(
98-
"0:TestAnnotation1");
91+
assertThat(scan(source, SearchStrategy.INHERITED_ANNOTATIONS)).containsExactly("0:TestAnnotation1");
9992
}
10093

10194
@Test
@@ -115,8 +108,7 @@ void inheritedAnnotationsStrategyOnClassWhenHasSuperclassScansOnlyInherited() {
115108
@Test
116109
void inheritedAnnotationsStrategyOnClassWhenHasInterfaceDoesNotIncludeInterfaces() {
117110
Class<?> source = WithSingleInterface.class;
118-
assertThat(scan(source, SearchStrategy.INHERITED_ANNOTATIONS)).containsExactly(
119-
"0:TestAnnotation1");
111+
assertThat(scan(source, SearchStrategy.INHERITED_ANNOTATIONS)).containsExactly("0:TestAnnotation1");
120112
}
121113

122114
@Test
@@ -132,8 +124,7 @@ void inheritedAnnotationsStrategyOnClassWhenHasAnnotationOnBothClassesIncudesOnl
132124
assertThat(Arrays.stream(source.getAnnotations()).map(
133125
Annotation::annotationType).map(Class::getName)).containsExactly(
134126
TestInheritedAnnotation2.class.getName());
135-
assertThat(scan(source, SearchStrategy.INHERITED_ANNOTATIONS)).containsOnly(
136-
"0:TestInheritedAnnotation2");
127+
assertThat(scan(source, SearchStrategy.INHERITED_ANNOTATIONS)).containsOnly("0:TestInheritedAnnotation2");
137128
}
138129

139130
@Test
@@ -145,15 +136,13 @@ void superclassStrategyOnClassWhenNotAnnotatedScansNone() {
145136
@Test
146137
void superclassStrategyOnClassScansAnnotations() {
147138
Class<?> source = WithSingleAnnotation.class;
148-
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
149-
"0:TestAnnotation1");
139+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly("0:TestAnnotation1");
150140
}
151141

152142
@Test
153143
void superclassStrategyOnClassWhenMultipleAnnotationsScansAnnotations() {
154144
Class<?> source = WithMultipleAnnotations.class;
155-
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
156-
"0:TestAnnotation1", "0:TestAnnotation2");
145+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly("0:TestAnnotation1", "0:TestAnnotation2");
157146
}
158147

159148
@Test
@@ -166,8 +155,7 @@ void superclassStrategyOnClassWhenHasSuperclassScansSuperclass() {
166155
@Test
167156
void superclassStrategyOnClassWhenHasInterfaceDoesNotIncludeInterfaces() {
168157
Class<?> source = WithSingleInterface.class;
169-
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
170-
"0:TestAnnotation1");
158+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly("0:TestAnnotation1");
171159
}
172160

173161
@Test
@@ -187,8 +175,7 @@ void typeHierarchyStrategyOnClassWhenNotAnnotatedScansNone() {
187175
@Test
188176
void typeHierarchyStrategyOnClassScansAnnotations() {
189177
Class<?> source = WithSingleAnnotation.class;
190-
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
191-
"0:TestAnnotation1");
178+
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly("0:TestAnnotation1");
192179
}
193180

194181
@Test
@@ -230,8 +217,7 @@ void directStrategyOnMethodWhenNotAnnotatedScansNone() {
230217
@Test
231218
void directStrategyOnMethodScansAnnotations() {
232219
Method source = methodFrom(WithSingleAnnotation.class);
233-
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly(
234-
"0:TestAnnotation1");
220+
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly("0:TestAnnotation1");
235221
}
236222

237223
@Test
@@ -244,22 +230,19 @@ void directStrategyOnMethodWhenMultipleAnnotationsScansAnnotations() {
244230
@Test
245231
void directStrategyOnMethodWhenHasSuperclassScansOnlyDirect() {
246232
Method source = methodFrom(WithSingleSuperclass.class);
247-
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly(
248-
"0:TestAnnotation1");
233+
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly("0:TestAnnotation1");
249234
}
250235

251236
@Test
252237
void directStrategyOnMethodWhenHasInterfaceScansOnlyDirect() {
253238
Method source = methodFrom(WithSingleInterface.class);
254-
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly(
255-
"0:TestAnnotation1");
239+
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly("0:TestAnnotation1");
256240
}
257241

258242
@Test
259243
void directStrategyOnMethodHierarchyScansInCorrectOrder() {
260244
Method source = methodFrom(WithHierarchy.class);
261-
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly(
262-
"0:TestAnnotation1");
245+
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly("0:TestAnnotation1");
263246
}
264247

265248
@Test
@@ -271,8 +254,7 @@ void inheritedAnnotationsStrategyOnMethodWhenNotAnnotatedScansNone() {
271254
@Test
272255
void inheritedAnnotationsStrategyOnMethodScansAnnotations() {
273256
Method source = methodFrom(WithSingleAnnotation.class);
274-
assertThat(scan(source, SearchStrategy.INHERITED_ANNOTATIONS)).containsExactly(
275-
"0:TestAnnotation1");
257+
assertThat(scan(source, SearchStrategy.INHERITED_ANNOTATIONS)).containsExactly("0:TestAnnotation1");
276258
}
277259

278260
@Test
@@ -285,22 +267,19 @@ void inheritedAnnotationsStrategyOnMethodWhenMultipleAnnotationsScansAnnotations
285267
@Test
286268
void inheritedAnnotationsMethodOnMethodWhenHasSuperclassIgnoresInherited() {
287269
Method source = methodFrom(WithSingleSuperclass.class);
288-
assertThat(scan(source, SearchStrategy.INHERITED_ANNOTATIONS)).containsExactly(
289-
"0:TestAnnotation1");
270+
assertThat(scan(source, SearchStrategy.INHERITED_ANNOTATIONS)).containsExactly("0:TestAnnotation1");
290271
}
291272

292273
@Test
293274
void inheritedAnnotationsStrategyOnMethodWhenHasInterfaceDoesNotIncludeInterfaces() {
294275
Method source = methodFrom(WithSingleInterface.class);
295-
assertThat(scan(source, SearchStrategy.INHERITED_ANNOTATIONS)).containsExactly(
296-
"0:TestAnnotation1");
276+
assertThat(scan(source, SearchStrategy.INHERITED_ANNOTATIONS)).containsExactly("0:TestAnnotation1");
297277
}
298278

299279
@Test
300280
void inheritedAnnotationsStrategyOnMethodHierarchyScansInCorrectOrder() {
301281
Method source = methodFrom(WithHierarchy.class);
302-
assertThat(scan(source, SearchStrategy.INHERITED_ANNOTATIONS)).containsExactly(
303-
"0:TestAnnotation1");
282+
assertThat(scan(source, SearchStrategy.INHERITED_ANNOTATIONS)).containsExactly("0:TestAnnotation1");
304283
}
305284

306285
@Test
@@ -312,8 +291,7 @@ void superclassStrategyOnMethodWhenNotAnnotatedScansNone() {
312291
@Test
313292
void superclassStrategyOnMethodScansAnnotations() {
314293
Method source = methodFrom(WithSingleAnnotation.class);
315-
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
316-
"0:TestAnnotation1");
294+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly("0:TestAnnotation1");
317295
}
318296

319297
@Test
@@ -333,8 +311,7 @@ void superclassStrategyOnMethodWhenHasSuperclassScansSuperclass() {
333311
@Test
334312
void superclassStrategyOnMethodWhenHasInterfaceDoesNotIncludeInterfaces() {
335313
Method source = methodFrom(WithSingleInterface.class);
336-
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
337-
"0:TestAnnotation1");
314+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly("0:TestAnnotation1");
338315
}
339316

340317
@Test
@@ -354,8 +331,7 @@ void typeHierarchyStrategyOnMethodWhenNotAnnotatedScansNone() {
354331
@Test
355332
void typeHierarchyStrategyOnMethodScansAnnotations() {
356333
Method source = methodFrom(WithSingleAnnotation.class);
357-
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
358-
"0:TestAnnotation1");
334+
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly("0:TestAnnotation1");
359335
}
360336

361337
@Test
@@ -408,50 +384,39 @@ void typeHierarchyStrategyOnBridgedMethodScansAnnotations() throws Exception {
408384
void directStrategyOnBridgeMethodScansAnnotations() throws Exception {
409385
Method source = BridgedMethod.class.getDeclaredMethod("method", Object.class);
410386
assertThat(source.isBridge()).isTrue();
411-
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly(
412-
"0:TestAnnotation1");
387+
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly("0:TestAnnotation1");
413388
}
414389

415390
@Test
416-
void dirextStrategyOnBridgedMethodScansAnnotations() throws Exception {
391+
void directStrategyOnBridgedMethodScansAnnotations() throws Exception {
417392
Method source = BridgedMethod.class.getDeclaredMethod("method", String.class);
418393
assertThat(source.isBridge()).isFalse();
419-
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly(
420-
"0:TestAnnotation1");
394+
assertThat(scan(source, SearchStrategy.DIRECT)).containsExactly("0:TestAnnotation1");
421395
}
422396

423397
@Test
424-
void typeHierarchyStrategyOnMethodWithIgnorablesScansAnnotations()
425-
throws Exception {
398+
void typeHierarchyStrategyOnMethodWithIgnorablesScansAnnotations() {
426399
Method source = methodFrom(Ignorable.class);
427-
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
428-
"0:TestAnnotation1");
400+
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly("0:TestAnnotation1");
429401
}
430402

431403
@Test
432-
void typeHierarchyStrategyOnMethodWithMultipleCandidatesScansAnnotations()
433-
throws Exception {
404+
void typeHierarchyStrategyOnMethodWithMultipleCandidatesScansAnnotations() {
434405
Method source = methodFrom(MultipleMethods.class);
435-
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
436-
"0:TestAnnotation1");
406+
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly("0:TestAnnotation1");
437407
}
438408

439409
@Test
440-
void typeHierarchyStrategyOnMethodWithGenericParameterOverrideScansAnnotations()
441-
throws Exception {
442-
Method source = ReflectionUtils.findMethod(GenericOverride.class, "method",
443-
String.class);
410+
void typeHierarchyStrategyOnMethodWithGenericParameterOverrideScansAnnotations() {
411+
Method source = ReflectionUtils.findMethod(GenericOverride.class, "method", String.class);
444412
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
445413
"0:TestAnnotation1", "1:TestAnnotation2");
446414
}
447415

448416
@Test
449-
void typeHierarchyStrategyOnMethodWithGenericParameterNonOverrideScansAnnotations()
450-
throws Exception {
451-
Method source = ReflectionUtils.findMethod(GenericNonOverride.class, "method",
452-
StringBuilder.class);
453-
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
454-
"0:TestAnnotation1");
417+
void typeHierarchyStrategyOnMethodWithGenericParameterNonOverrideScansAnnotations() {
418+
Method source = ReflectionUtils.findMethod(GenericNonOverride.class, "method", StringBuilder.class);
419+
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly("0:TestAnnotation1");
455420
}
456421

457422
@Test
@@ -751,8 +716,7 @@ interface BridgeMethod<T> {
751716
void method(T arg);
752717
}
753718

754-
@SuppressWarnings("serial")
755-
static class Ignorable implements IgnorableOverrideInterface1, IgnorableOverrideInterface2, Serializable {
719+
static class Ignorable implements IgnorableOverrideInterface1, IgnorableOverrideInterface2 {
756720

757721
@Override
758722
@TestAnnotation1
@@ -802,8 +766,7 @@ interface GenericOverrideInterface<T extends CharSequence> {
802766
void method(T argument);
803767
}
804768

805-
static abstract class GenericNonOverride
806-
implements GenericNonOverrideInterface<String> {
769+
static abstract class GenericNonOverride implements GenericNonOverrideInterface<String> {
807770

808771
@TestAnnotation1
809772
public void method(StringBuilder argument) {

0 commit comments

Comments
 (0)