|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2014 the original author or authors. |
| 2 | + * Copyright 2002-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
20 | 20 | import java.io.ByteArrayOutputStream;
|
21 | 21 | import java.io.ObjectInputStream;
|
22 | 22 | import java.io.ObjectOutputStream;
|
| 23 | +import java.lang.annotation.Annotation; |
23 | 24 | import java.lang.annotation.ElementType;
|
24 | 25 | import java.lang.annotation.Retention;
|
25 | 26 | import java.lang.annotation.RetentionPolicy;
|
|
50 | 51 | * @author Keith Donald
|
51 | 52 | * @author Andy Clement
|
52 | 53 | * @author Phillip Webb
|
| 54 | + * @author Sam Brannen |
53 | 55 | */
|
54 | 56 | @SuppressWarnings("rawtypes")
|
55 | 57 | public class TypeDescriptorTests {
|
@@ -369,22 +371,60 @@ public void setProperty(Map<List<Integer>, List<Long>> property) {
|
369 | 371 | @MethodAnnotation3
|
370 | 372 | private Map<List<Integer>, List<Long>> property;
|
371 | 373 |
|
372 |
| - @Target({ElementType.METHOD}) |
| 374 | + |
| 375 | + @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) |
373 | 376 | @Retention(RetentionPolicy.RUNTIME)
|
374 | 377 | public @interface MethodAnnotation1 {
|
375 |
| - |
376 | 378 | }
|
377 | 379 |
|
378 | 380 | @Target({ElementType.METHOD})
|
379 | 381 | @Retention(RetentionPolicy.RUNTIME)
|
380 | 382 | public @interface MethodAnnotation2 {
|
381 |
| - |
382 | 383 | }
|
383 | 384 |
|
384 | 385 | @Target({ElementType.FIELD})
|
385 | 386 | @Retention(RetentionPolicy.RUNTIME)
|
386 | 387 | public @interface MethodAnnotation3 {
|
| 388 | + } |
| 389 | + |
| 390 | + @MethodAnnotation1 |
| 391 | + @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) |
| 392 | + @Retention(RetentionPolicy.RUNTIME) |
| 393 | + public @interface ComposedMethodAnnotation1 {} |
| 394 | + |
| 395 | + @ComposedMethodAnnotation1 |
| 396 | + @Target(ElementType.METHOD) |
| 397 | + @Retention(RetentionPolicy.RUNTIME) |
| 398 | + public @interface ComposedComposedMethodAnnotation1 {} |
| 399 | + |
| 400 | + @MethodAnnotation1 |
| 401 | + public void methodWithLocalAnnotation() {} |
387 | 402 |
|
| 403 | + @ComposedMethodAnnotation1 |
| 404 | + public void methodWithComposedAnnotation() {} |
| 405 | + |
| 406 | + @ComposedComposedMethodAnnotation1 |
| 407 | + public void methodWithComposedComposedAnnotation() {} |
| 408 | + |
| 409 | + private void assertAnnotationFoundOnMethod(Class<? extends Annotation> annotationType, String methodName) throws Exception { |
| 410 | + TypeDescriptor typeDescriptor = new TypeDescriptor(new MethodParameter(getClass().getMethod(methodName), -1)); |
| 411 | + assertNotNull("Should have found @" + annotationType.getSimpleName() + " on " + methodName + ".", |
| 412 | + typeDescriptor.getAnnotation(annotationType)); |
| 413 | + } |
| 414 | + |
| 415 | + @Test |
| 416 | + public void getAnnotationOnMethodThatIsLocallyAnnotated() throws Exception { |
| 417 | + assertAnnotationFoundOnMethod(MethodAnnotation1.class, "methodWithLocalAnnotation"); |
| 418 | + } |
| 419 | + |
| 420 | + @Test |
| 421 | + public void getAnnotationOnMethodThatIsMetaAnnotated() throws Exception { |
| 422 | + assertAnnotationFoundOnMethod(MethodAnnotation1.class, "methodWithComposedAnnotation"); |
| 423 | + } |
| 424 | + |
| 425 | + @Test |
| 426 | + public void getAnnotationOnMethodThatIsMetaMetaAnnotated() throws Exception { |
| 427 | + assertAnnotationFoundOnMethod(MethodAnnotation1.class, "methodWithComposedComposedAnnotation"); |
388 | 428 | }
|
389 | 429 |
|
390 | 430 | @Test
|
|
0 commit comments