16
16
17
17
package org .springframework .core .annotation ;
18
18
19
- import static org .junit .Assert .*;
20
- import static org .springframework .core .annotation .AnnotationUtils .*;
21
-
22
19
import java .lang .annotation .Annotation ;
23
20
import java .lang .annotation .Inherited ;
24
21
import java .lang .annotation .Retention ;
25
22
import java .lang .annotation .RetentionPolicy ;
26
23
import java .lang .reflect .Method ;
27
-
28
24
import java .util .Arrays ;
29
25
import java .util .List ;
30
26
33
29
import org .springframework .core .Ordered ;
34
30
import org .springframework .stereotype .Component ;
35
31
32
+ import static org .junit .Assert .*;
33
+ import static org .springframework .core .annotation .AnnotationUtils .*;
34
+
36
35
/**
37
- * Unit tests for {@link AnnotationUtils}.
38
- *
39
36
* @author Rod Johnson
40
37
* @author Juergen Hoeller
41
38
* @author Sam Brannen
@@ -45,47 +42,42 @@ public class AnnotationUtilsTests {
45
42
46
43
@ Test
47
44
public void testFindMethodAnnotationOnLeaf () throws SecurityException , NoSuchMethodException {
48
-
49
- final Method m = Leaf .class .getMethod ("annotatedOnLeaf" , (Class []) null );
45
+ Method m = Leaf .class .getMethod ("annotatedOnLeaf" , (Class []) null );
50
46
assertNotNull (m .getAnnotation (Order .class ));
51
47
assertNotNull (getAnnotation (m , Order .class ));
52
48
assertNotNull (findAnnotation (m , Order .class ));
53
49
}
54
50
55
51
@ Test
56
52
public void testFindMethodAnnotationOnRoot () throws SecurityException , NoSuchMethodException {
57
-
58
- final Method m = Leaf .class .getMethod ("annotatedOnRoot" , (Class []) null );
53
+ Method m = Leaf .class .getMethod ("annotatedOnRoot" , (Class []) null );
59
54
assertNotNull (m .getAnnotation (Order .class ));
60
55
assertNotNull (getAnnotation (m , Order .class ));
61
56
assertNotNull (findAnnotation (m , Order .class ));
62
57
}
63
58
64
59
@ Test
65
60
public void testFindMethodAnnotationOnRootButOverridden () throws SecurityException , NoSuchMethodException {
66
-
67
- final Method m = Leaf .class .getMethod ("overrideWithoutNewAnnotation" , (Class []) null );
61
+ Method m = Leaf .class .getMethod ("overrideWithoutNewAnnotation" , (Class []) null );
68
62
assertNull (m .getAnnotation (Order .class ));
69
63
assertNull (getAnnotation (m , Order .class ));
70
64
assertNotNull (findAnnotation (m , Order .class ));
71
65
}
72
66
73
67
@ Test
74
68
public void testFindMethodAnnotationNotAnnotated () throws SecurityException , NoSuchMethodException {
75
-
76
- final Method m = Leaf .class .getMethod ("notAnnotated" , (Class []) null );
69
+ Method m = Leaf .class .getMethod ("notAnnotated" , (Class []) null );
77
70
assertNull (findAnnotation (m , Order .class ));
78
71
}
79
72
80
73
@ Test
81
74
public void testFindMethodAnnotationOnBridgeMethod () throws Exception {
82
-
83
- final Method m = SimpleFoo .class .getMethod ("something" , Object .class );
75
+ Method m = SimpleFoo .class .getMethod ("something" , Object .class );
84
76
assertTrue (m .isBridge ());
85
77
assertNull (m .getAnnotation (Order .class ));
86
78
assertNull (getAnnotation (m , Order .class ));
87
79
assertNotNull (findAnnotation (m , Order .class ));
88
- assertNull (m .getAnnotation (Transactional .class ));
80
+ // TODO: actually found on OpenJDK 8 b99! assertNull(m.getAnnotation(Transactional.class));
89
81
assertNotNull (getAnnotation (m , Transactional .class ));
90
82
assertNotNull (findAnnotation (m , Transactional .class ));
91
83
}
@@ -101,7 +93,6 @@ public void testFindMethodAnnotationOnBridgeMethod() throws Exception {
101
93
102
94
@ Test
103
95
public void testFindAnnotationDeclaringClass () throws Exception {
104
-
105
96
// no class-level annotation
106
97
assertNull (findAnnotationDeclaringClass (Transactional .class , NonAnnotatedInterface .class ));
107
98
assertNull (findAnnotationDeclaringClass (Transactional .class , NonAnnotatedClass .class ));
@@ -128,7 +119,6 @@ public void testFindAnnotationDeclaringClass() throws Exception {
128
119
129
120
@ Test
130
121
public void findAnnotationDeclaringClassForTypesWithSingleCandidateType () {
131
-
132
122
// no class-level annotation
133
123
List <Class <? extends Annotation >> transactionalCandidateList = Arrays .<Class <? extends Annotation >> asList (Transactional .class );
134
124
assertNull (findAnnotationDeclaringClassForTypes (transactionalCandidateList , NonAnnotatedInterface .class ));
@@ -158,9 +148,7 @@ public void findAnnotationDeclaringClassForTypesWithSingleCandidateType() {
158
148
159
149
@ Test
160
150
public void findAnnotationDeclaringClassForTypesWithMultipleCandidateTypes () {
161
-
162
- List <Class <? extends Annotation >> candidates = Arrays .<Class <? extends Annotation >> asList (Transactional .class ,
163
- Order .class );
151
+ List <Class <? extends Annotation >> candidates = Arrays .<Class <? extends Annotation >> asList (Transactional .class , Order .class );
164
152
165
153
// no class-level annotation
166
154
assertNull (findAnnotationDeclaringClassForTypes (candidates , NonAnnotatedInterface .class ));
@@ -196,7 +184,6 @@ public void findAnnotationDeclaringClassForTypesWithMultipleCandidateTypes() {
196
184
197
185
@ Test
198
186
public void testIsAnnotationDeclaredLocally () throws Exception {
199
-
200
187
// no class-level annotation
201
188
assertFalse (isAnnotationDeclaredLocally (Transactional .class , NonAnnotatedInterface .class ));
202
189
assertFalse (isAnnotationDeclaredLocally (Transactional .class , NonAnnotatedClass .class ));
@@ -216,7 +203,6 @@ public void testIsAnnotationDeclaredLocally() throws Exception {
216
203
217
204
@ Test
218
205
public void testIsAnnotationInherited () throws Exception {
219
-
220
206
// no class-level annotation
221
207
assertFalse (isAnnotationInherited (Transactional .class , NonAnnotatedInterface .class ));
222
208
assertFalse (isAnnotationInherited (Transactional .class , NonAnnotatedClass .class ));
@@ -239,50 +225,44 @@ public void testIsAnnotationInherited() throws Exception {
239
225
240
226
@ Test
241
227
public void testGetValueFromAnnotation () throws Exception {
242
-
243
- final Method method = SimpleFoo .class .getMethod ("something" , Object .class );
244
- final Order order = findAnnotation (method , Order .class );
228
+ Method method = SimpleFoo .class .getMethod ("something" , Object .class );
229
+ Order order = findAnnotation (method , Order .class );
245
230
246
231
assertEquals (1 , AnnotationUtils .getValue (order , AnnotationUtils .VALUE ));
247
232
assertEquals (1 , AnnotationUtils .getValue (order ));
248
233
}
249
234
250
235
@ Test
251
236
public void testGetDefaultValueFromAnnotation () throws Exception {
252
-
253
- final Method method = SimpleFoo .class .getMethod ("something" , Object .class );
254
- final Order order = findAnnotation (method , Order .class );
237
+ Method method = SimpleFoo .class .getMethod ("something" , Object .class );
238
+ Order order = findAnnotation (method , Order .class );
255
239
256
240
assertEquals (Ordered .LOWEST_PRECEDENCE , AnnotationUtils .getDefaultValue (order , AnnotationUtils .VALUE ));
257
241
assertEquals (Ordered .LOWEST_PRECEDENCE , AnnotationUtils .getDefaultValue (order ));
258
242
}
259
243
260
244
@ Test
261
245
public void testGetDefaultValueFromAnnotationType () throws Exception {
262
-
263
246
assertEquals (Ordered .LOWEST_PRECEDENCE , AnnotationUtils .getDefaultValue (Order .class , AnnotationUtils .VALUE ));
264
247
assertEquals (Ordered .LOWEST_PRECEDENCE , AnnotationUtils .getDefaultValue (Order .class ));
265
248
}
266
249
267
250
@ Test
268
251
public void testFindAnnotationFromInterface () throws Exception {
269
-
270
252
Method method = ImplementsInterfaceWithAnnotatedMethod .class .getMethod ("foo" );
271
253
Order order = findAnnotation (method , Order .class );
272
254
assertNotNull (order );
273
255
}
274
256
275
257
@ Test
276
258
public void testFindAnnotationFromInterfaceOnSuper () throws Exception {
277
-
278
259
Method method = SubOfImplementsInterfaceWithAnnotatedMethod .class .getMethod ("foo" );
279
260
Order order = findAnnotation (method , Order .class );
280
261
assertNotNull (order );
281
262
}
282
263
283
264
@ Test
284
265
public void testFindAnnotationFromInterfaceWhenSuperDoesNotImplementMethod () throws Exception {
285
-
286
266
Method method = SubOfAbstractImplementsInterfaceWithAnnotatedMethod .class .getMethod ("foo" );
287
267
Order order = findAnnotation (method , Order .class );
288
268
assertNotNull (order );
0 commit comments