28
28
import java .util .Set ;
29
29
30
30
import org .junit .Test ;
31
+
31
32
import org .springframework .core .Ordered ;
32
33
import org .springframework .core .annotation .subpackage .NonPublicAnnotatedClass ;
33
34
import org .springframework .stereotype .Component ;
37
38
import static org .springframework .core .annotation .AnnotationUtils .*;
38
39
39
40
/**
41
+ * Unit tests for {@link AnnotationUtils}.
42
+ *
40
43
* @author Rod Johnson
41
44
* @author Juergen Hoeller
42
45
* @author Sam Brannen
@@ -97,9 +100,9 @@ public void findMethodAnnotationOnBridgeMethod() throws Exception {
97
100
// }
98
101
99
102
@ Test
100
- public void findAnnotationPrefersInteracesOverLocalMetaAnnotations () {
103
+ public void findAnnotationPrefersInterfacesOverLocalMetaAnnotations () {
101
104
Component component = AnnotationUtils .findAnnotation (
102
- ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface .class , Component .class );
105
+ ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface .class , Component .class );
103
106
104
107
// By inspecting ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface, one
105
108
// might expect that "meta2" should be found; however, with the current
@@ -144,8 +147,7 @@ public void findAnnotationDeclaringClassForTypesWithSingleCandidateType() {
144
147
// inherited class-level annotation; note: @Transactional is inherited
145
148
assertEquals (InheritedAnnotationInterface .class ,
146
149
findAnnotationDeclaringClassForTypes (transactionalCandidateList , InheritedAnnotationInterface .class ));
147
- assertNull (findAnnotationDeclaringClassForTypes (transactionalCandidateList ,
148
- SubInheritedAnnotationInterface .class ));
150
+ assertNull (findAnnotationDeclaringClassForTypes (transactionalCandidateList , SubInheritedAnnotationInterface .class ));
149
151
assertEquals (InheritedAnnotationClass .class ,
150
152
findAnnotationDeclaringClassForTypes (transactionalCandidateList , InheritedAnnotationClass .class ));
151
153
assertEquals (InheritedAnnotationClass .class ,
@@ -301,8 +303,7 @@ public void findAnnotationFromInterfaceOnSuper() throws Exception {
301
303
}
302
304
303
305
@ Test
304
- public void findAnnotationFromInterfaceWhenSuperDoesNotImplementMethod ()
305
- throws Exception {
306
+ public void findAnnotationFromInterfaceWhenSuperDoesNotImplementMethod () throws Exception {
306
307
Method method = SubOfAbstractImplementsInterfaceWithAnnotatedMethod .class .getMethod ("foo" );
307
308
Order order = findAnnotation (method , Order .class );
308
309
assertNotNull (order );
@@ -322,13 +323,13 @@ public void getRepeatableFromMethod() throws Exception {
322
323
}
323
324
324
325
325
- @ Component (value = "meta1" )
326
+ @ Component (value = "meta1" )
326
327
@ Order
327
328
@ Retention (RetentionPolicy .RUNTIME )
328
329
@interface Meta1 {
329
330
}
330
331
331
- @ Component (value = "meta2" )
332
+ @ Component (value = "meta2" )
332
333
@ Transactional
333
334
@ Retention (RetentionPolicy .RUNTIME )
334
335
@interface Meta2 {
@@ -353,47 +354,44 @@ public static class Root implements AnnotatedInterface {
353
354
354
355
@ Order (27 )
355
356
public void annotatedOnRoot () {
356
-
357
357
}
358
358
359
359
public void overrideToAnnotate () {
360
-
361
360
}
362
361
363
362
@ Order (27 )
364
363
public void overrideWithoutNewAnnotation () {
365
-
366
364
}
367
365
368
366
public void notAnnotated () {
369
-
370
367
}
371
368
372
369
@ Override
373
370
public void fromInterfaceImplementedByRoot () {
374
-
375
371
}
376
372
}
377
373
378
374
public static class Leaf extends Root {
379
375
380
376
@ Order (25 )
381
377
public void annotatedOnLeaf () {
382
-
383
378
}
384
379
385
380
@ Override
386
381
@ Order (1 )
387
382
public void overrideToAnnotate () {
388
-
389
383
}
390
384
391
385
@ Override
392
386
public void overrideWithoutNewAnnotation () {
393
-
394
387
}
395
388
}
396
389
390
+ @ Retention (RetentionPolicy .RUNTIME )
391
+ @ Inherited
392
+ @interface Transactional {
393
+ }
394
+
397
395
public static abstract class Foo <T > {
398
396
399
397
@ Order (1 )
@@ -405,7 +403,6 @@ public static class SimpleFoo extends Foo<String> {
405
403
@ Override
406
404
@ Transactional
407
405
public void something (final String arg ) {
408
-
409
406
}
410
407
}
411
408
@@ -474,58 +471,45 @@ public void foo() {
474
471
}
475
472
}
476
473
477
- public abstract static class AbstractDoesNotImplementInterfaceWithAnnotatedMethod implements
478
- InterfaceWithAnnotatedMethod {
474
+ public abstract static class AbstractDoesNotImplementInterfaceWithAnnotatedMethod
475
+ implements InterfaceWithAnnotatedMethod {
479
476
}
480
477
481
- public static class SubOfAbstractImplementsInterfaceWithAnnotatedMethod extends
482
- AbstractDoesNotImplementInterfaceWithAnnotatedMethod {
478
+ public static class SubOfAbstractImplementsInterfaceWithAnnotatedMethod
479
+ extends AbstractDoesNotImplementInterfaceWithAnnotatedMethod {
483
480
484
481
@ Override
485
482
public void foo () {
486
483
}
487
484
}
488
485
489
- public static interface InterfaceWithRepeated {
490
-
491
- @ MyRepeatable ("a" )
492
- @ MyRepeatableContainer ({ @ MyRepeatable ("b" ), @ MyRepeatable ("c" ) })
493
- @ MyRepeatableMeta
494
- void foo ();
486
+ @ Retention (RetentionPolicy .RUNTIME )
487
+ @ Inherited
488
+ @interface MyRepeatableContainer {
495
489
490
+ MyRepeatable [] value ();
496
491
}
497
492
498
- }
499
-
500
-
501
- @ Retention (RetentionPolicy .RUNTIME )
502
- @ Inherited
503
- @interface Transactional {
504
-
505
- }
506
-
507
-
508
- @ Retention (RetentionPolicy .RUNTIME )
509
- @ Inherited
510
- @interface MyRepeatableContainer {
511
-
512
- MyRepeatable [] value ();
513
-
514
- }
515
-
493
+ @ Retention (RetentionPolicy .RUNTIME )
494
+ @ Inherited
495
+ @ Repeatable (MyRepeatableContainer .class )
496
+ @interface MyRepeatable {
516
497
517
- @ Retention (RetentionPolicy .RUNTIME )
518
- @ Inherited
519
- @ Repeatable (MyRepeatableContainer .class )
520
- @interface MyRepeatable {
498
+ String value ();
499
+ }
521
500
522
- String value ();
501
+ @ Retention (RetentionPolicy .RUNTIME )
502
+ @ Inherited
503
+ @ MyRepeatable ("meta" )
504
+ @interface MyRepeatableMeta {
505
+ }
523
506
524
- }
507
+ public static interface InterfaceWithRepeated {
525
508
509
+ @ MyRepeatable ("a" )
510
+ @ MyRepeatableContainer ({ @ MyRepeatable ("b" ), @ MyRepeatable ("c" ) })
511
+ @ MyRepeatableMeta
512
+ void foo ();
513
+ }
526
514
527
- @ Retention (RetentionPolicy .RUNTIME )
528
- @ Inherited
529
- @ MyRepeatable ("meta" )
530
- @interface MyRepeatableMeta {
531
515
}
0 commit comments