@@ -38,8 +38,7 @@ public abstract class AbstractAnnotationMetadataTests {
38
38
39
39
@ Test
40
40
public void getClassNameReturnsClassName () {
41
- assertThat (get (TestClass .class ).getClassName ()).isEqualTo (
42
- TestClass .class .getName ());
41
+ assertThat (get (TestClass .class ).getClassName ()).isEqualTo (TestClass .class .getName ());
43
42
}
44
43
45
44
@ Test
@@ -93,16 +92,13 @@ public void getEnclosingClassNameWhenHasEnclosingClassReturnsEnclosingClass() {
93
92
94
93
@ Test
95
94
public void getEnclosingClassNameWhenHasNoEnclosingClassReturnsNull () {
96
- assertThat (get (
97
- AbstractAnnotationMetadataTests .class ).getEnclosingClassName ()).isNull ();
95
+ assertThat (get (AbstractAnnotationMetadataTests .class ).getEnclosingClassName ()).isNull ();
98
96
}
99
97
100
98
@ Test
101
99
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 ());
106
102
}
107
103
108
104
@ Test
@@ -114,11 +110,8 @@ public void getSuperClassNameWhenHasNoSuperClassReturnsNull() {
114
110
115
111
@ Test
116
112
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 ());
122
115
}
123
116
124
117
@ Test
@@ -128,10 +121,8 @@ public void getInterfaceNamesWhenHasNoInterfacesReturnsEmptyArray() {
128
121
129
122
@ Test
130
123
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 ());
135
126
}
136
127
137
128
@ Test
@@ -141,44 +132,37 @@ public void getMemberClassNamesWhenHasNoMemberClassesReturnsEmptyArray() {
141
132
142
133
@ Test
143
134
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 ());
150
139
}
151
140
152
141
@ Test
153
142
public void isAnnotatedWhenMatchesDirectAnnotationReturnsTrue () {
154
- assertThat (get (WithDirectAnnotations .class ).isAnnotated (
155
- DirectAnnotation1 .class .getName ())).isTrue ();
143
+ assertThat (get (WithDirectAnnotations .class ).isAnnotated (DirectAnnotation1 .class .getName ())).isTrue ();
156
144
}
157
145
158
146
@ Test
159
147
public void isAnnotatedWhenMatchesMetaAnnotationReturnsTrue () {
160
- assertThat (get (WithMetaAnnotations .class ).isAnnotated (
161
- MetaAnnotation2 .class .getName ())).isTrue ();
148
+ assertThat (get (WithMetaAnnotations .class ).isAnnotated (MetaAnnotation2 .class .getName ())).isTrue ();
162
149
}
163
150
164
151
@ Test
165
152
public void isAnnotatedWhenDoesNotMatchDirectOrMetaAnnotationReturnsFalse () {
166
- assertThat (get (TestClass .class ).isAnnotated (
167
- DirectAnnotation1 .class .getName ())).isFalse ();
153
+ assertThat (get (TestClass .class ).isAnnotated (DirectAnnotation1 .class .getName ())).isFalse ();
168
154
}
169
155
170
156
@ Test
171
157
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 ));
175
160
}
176
161
177
162
@ Test
178
163
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 ());
182
166
assertThat (attributes ).containsOnlyKeys ("name" , "size" );
183
167
assertThat (attributes .get ("name" )).containsExactlyInAnyOrder ("m1" , "m2" );
184
168
assertThat (attributes .get ("size" )).containsExactlyInAnyOrder (1 , 2 );
@@ -194,155 +178,126 @@ public void getAnnotationTypesReturnsDirectAnnotations() {
194
178
@ Test
195
179
public void getMetaAnnotationTypesReturnsMetaAnnotations () {
196
180
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 ());
200
183
}
201
184
202
185
@ Test
203
186
public void hasAnnotationWhenMatchesDirectAnnotationReturnsTrue () {
204
- assertThat (get (WithDirectAnnotations .class ).hasAnnotation (
205
- DirectAnnotation1 .class .getName ())).isTrue ();
187
+ assertThat (get (WithDirectAnnotations .class ).hasAnnotation (DirectAnnotation1 .class .getName ())).isTrue ();
206
188
}
207
189
208
190
@ Test
209
191
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 ();
214
194
}
215
195
216
196
@ Test
217
197
public void hasAnnotationWhenDoesNotMatchDirectOrMetaAnnotationReturnsFalse () {
218
- assertThat (get (TestClass .class ).hasAnnotation (
219
- DirectAnnotation1 .class .getName ())).isFalse ();
198
+ assertThat (get (TestClass .class ).hasAnnotation (DirectAnnotation1 .class .getName ())).isFalse ();
220
199
}
221
200
222
201
@ Test
223
202
public void hasMetaAnnotationWhenMatchesDirectReturnsFalse () {
224
- assertThat (get (WithDirectAnnotations .class ).hasMetaAnnotation (
225
- DirectAnnotation1 .class .getName ())).isFalse ();
203
+ assertThat (get (WithDirectAnnotations .class ).hasMetaAnnotation (DirectAnnotation1 .class .getName ())).isFalse ();
226
204
}
227
205
228
206
@ Test
229
207
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 ();
234
210
}
235
211
236
212
@ Test
237
213
public void hasMetaAnnotationWhenDoesNotMatchDirectOrMetaAnnotationReturnsFalse () {
238
- assertThat (get (TestClass .class ).hasMetaAnnotation (
239
- MetaAnnotation1 .class .getName ())).isFalse ();
214
+ assertThat (get (TestClass .class ).hasMetaAnnotation (MetaAnnotation1 .class .getName ())).isFalse ();
240
215
}
241
216
242
217
@ Test
243
218
public void hasAnnotatedMethodsWhenMatchesDirectAnnotationReturnsTrue () {
244
- assertThat (get (WithAnnotatedMethod .class ).hasAnnotatedMethods (
245
- DirectAnnotation1 .class .getName ())).isTrue ();
219
+ assertThat (get (WithAnnotatedMethod .class ).hasAnnotatedMethods (DirectAnnotation1 .class .getName ())).isTrue ();
246
220
}
247
221
248
222
@ Test
249
223
public void hasAnnotatedMethodsWhenMatchesMetaAnnotationReturnsTrue () {
250
- assertThat (get (WithMetaAnnotatedMethod .class ).hasAnnotatedMethods (
251
- MetaAnnotation2 .class .getName ())).isTrue ();
224
+ assertThat (get (WithMetaAnnotatedMethod .class ).hasAnnotatedMethods (MetaAnnotation2 .class .getName ())).isTrue ();
252
225
}
253
226
254
227
@ Test
255
228
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 ();
260
231
}
261
232
262
233
@ Test
263
234
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" );
268
238
}
269
239
270
240
protected abstract AnnotationMetadata get (Class <?> source );
271
241
272
- @ Retention (RetentionPolicy .RUNTIME )
273
- public static @interface DirectAnnotation1 {
274
242
243
+ @ Retention (RetentionPolicy .RUNTIME )
244
+ public @interface DirectAnnotation1 {
275
245
}
276
246
277
247
@ Retention (RetentionPolicy .RUNTIME )
278
- public static @interface DirectAnnotation2 {
279
-
248
+ public @interface DirectAnnotation2 {
280
249
}
281
250
282
251
@ Retention (RetentionPolicy .RUNTIME )
283
252
@ MetaAnnotation1
284
- public static @interface MetaAnnotationRoot {
285
-
253
+ public @interface MetaAnnotationRoot {
286
254
}
287
255
288
256
@ Retention (RetentionPolicy .RUNTIME )
289
257
@ MetaAnnotation2
290
- public static @interface MetaAnnotation1 {
291
-
258
+ public @interface MetaAnnotation1 {
292
259
}
293
260
294
261
@ Retention (RetentionPolicy .RUNTIME )
295
- public static @interface MetaAnnotation2 {
296
-
262
+ public @interface MetaAnnotation2 {
297
263
}
298
264
299
265
public static class TestClass {
300
-
301
266
}
302
267
303
268
public static interface TestInterface {
304
-
305
269
}
306
270
307
271
public static interface TestSubInterface extends TestInterface {
308
-
309
272
}
310
273
311
274
public @interface TestAnnotation {
312
-
313
275
}
314
276
315
277
public static final class TestFinalClass {
316
-
317
278
}
318
279
319
280
public class TestNonStaticInnerClass {
320
-
321
281
}
322
282
323
283
public static class TestSubclass extends TestClass implements TestInterface {
324
-
325
284
}
326
285
327
286
@ DirectAnnotation1
328
287
@ DirectAnnotation2
329
288
public static class WithDirectAnnotations {
330
-
331
289
}
332
290
333
291
@ MetaAnnotationRoot
334
292
public static class WithMetaAnnotations {
335
-
336
293
}
337
294
338
295
public static class TestMemberClass {
339
296
340
297
public static class TestMemberClassInnerClass {
341
-
342
298
}
343
299
344
300
interface TestMemberClassInnerInterface {
345
-
346
301
}
347
302
348
303
}
@@ -384,29 +339,25 @@ public void meta() {
384
339
385
340
@ AnnotationAttributes (name = "test" , size = 1 )
386
341
public static class WithAnnotationAttributes {
387
-
388
342
}
389
343
390
344
@ MetaAnnotationAttributes1
391
345
@ MetaAnnotationAttributes2
392
346
public static class WithMetaAnnotationAttributes {
393
-
394
347
}
395
348
396
349
@ Retention (RetentionPolicy .RUNTIME )
397
350
@ AnnotationAttributes (name = "m1" , size = 1 )
398
- public static @interface MetaAnnotationAttributes1 {
399
-
351
+ public @interface MetaAnnotationAttributes1 {
400
352
}
401
353
402
354
@ Retention (RetentionPolicy .RUNTIME )
403
355
@ AnnotationAttributes (name = "m2" , size = 2 )
404
- public static @interface MetaAnnotationAttributes2 {
405
-
356
+ public @interface MetaAnnotationAttributes2 {
406
357
}
407
358
408
359
@ Retention (RetentionPolicy .RUNTIME )
409
- public static @interface AnnotationAttributes {
360
+ public @interface AnnotationAttributes {
410
361
411
362
String name ();
412
363
0 commit comments