@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2014 the original author or authors .
* Copyright 2002 - 2015 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -20,6 +20,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream ;
import java.io.ObjectInputStream ;
import java.io.ObjectOutputStream ;
import java.lang.annotation.Annotation ;
import java.lang.annotation.ElementType ;
import java.lang.annotation.Retention ;
import java.lang.annotation.RetentionPolicy ;
@ -50,6 +51,7 @@ import static org.junit.Assert.*;
* @author Keith Donald
* @author Andy Clement
* @author Phillip Webb
* @author Sam Brannen
* /
@SuppressWarnings ( "rawtypes" )
public class TypeDescriptorTests {
@ -369,22 +371,60 @@ public class TypeDescriptorTests {
@MethodAnnotation3
private Map < List < Integer > , List < Long > > property ;
@Target ( { ElementType . METHOD } )
@Target ( { ElementType . METHOD , ElementType . ANNOTATION_TYPE } )
@Retention ( RetentionPolicy . RUNTIME )
public @interface MethodAnnotation1 {
}
@Target ( { ElementType . METHOD } )
@Retention ( RetentionPolicy . RUNTIME )
public @interface MethodAnnotation2 {
}
@Target ( { ElementType . FIELD } )
@Retention ( RetentionPolicy . RUNTIME )
public @interface MethodAnnotation3 {
}
@MethodAnnotation1
@Target ( { ElementType . METHOD , ElementType . ANNOTATION_TYPE } )
@Retention ( RetentionPolicy . RUNTIME )
public @interface ComposedMethodAnnotation1 { }
@ComposedMethodAnnotation1
@Target ( ElementType . METHOD )
@Retention ( RetentionPolicy . RUNTIME )
public @interface ComposedComposedMethodAnnotation1 { }
@MethodAnnotation1
public void methodWithLocalAnnotation ( ) { }
@ComposedMethodAnnotation1
public void methodWithComposedAnnotation ( ) { }
@ComposedComposedMethodAnnotation1
public void methodWithComposedComposedAnnotation ( ) { }
private void assertAnnotationFoundOnMethod ( Class < ? extends Annotation > annotationType , String methodName ) throws Exception {
TypeDescriptor typeDescriptor = new TypeDescriptor ( new MethodParameter ( getClass ( ) . getMethod ( methodName ) , - 1 ) ) ;
assertNotNull ( "Should have found @" + annotationType . getSimpleName ( ) + " on " + methodName + "." ,
typeDescriptor . getAnnotation ( annotationType ) ) ;
}
@Test
public void getAnnotationOnMethodThatIsLocallyAnnotated ( ) throws Exception {
assertAnnotationFoundOnMethod ( MethodAnnotation1 . class , "methodWithLocalAnnotation" ) ;
}
@Test
public void getAnnotationOnMethodThatIsMetaAnnotated ( ) throws Exception {
assertAnnotationFoundOnMethod ( MethodAnnotation1 . class , "methodWithComposedAnnotation" ) ;
}
@Test
public void getAnnotationOnMethodThatIsMetaMetaAnnotated ( ) throws Exception {
assertAnnotationFoundOnMethod ( MethodAnnotation1 . class , "methodWithComposedComposedAnnotation" ) ;
}
@Test