JSR308 - Type-Annotations - Reflection Tests

High Level Feature Description

The JSR308 updates the package java.lang.reflect and java.lang.class to give same access to the type annotations as other annotations.

Reflection - APIs in java.lang.reflect.* and java.lang.Class will be tested to access type annotations.

Existing tests

There are numerous regression/unit tests that have already been integrated with the feature.

Deprecated tests

There are no existing tests to be deprecated.

Tests and test cases

#

Class

API

Test Approach

Notes

1

java/lang/Class.java

public AnnotatedType getAnnotatedSuperclass()

Annotate a super declaration.
Invoke method with reflection
Check the output AnnotatedType.

e.g.

class AnnotationSampleC06
  extends @TypeAnno("extends") Object {}

AnnotatedType a =
  AnnotationSampleC06.class.getAnnotatedSuperclass();
Annotation[] annos = a.getAnnotations();
check(annos.length == 1);
check(annos[0].annotationType().equals(TypeAnno.class));
check(((TypeAnno) annos[0]).value().equals("extends"));

2



repeated annot. on super declaration

Invoke method with reflection
Check the output AnnotatedType.


3



Invoke this method with reflection
Check the output AnnotatedType.

If input Class represents a class type whose declaration
does not denote a superclass, the return value is null.

4



Invoke this method with reflection
Check the output AnnotatedType.

If input Class represents either the Object class,
an interface type, an array type, a primitive type,
or void, the return value is null.

5



Test super class with no annotation.


6



Invoke AnnotatedType.getType()
check if it returns superclass's type.


7


public AnnotatedType[] getAnnotatedInterfaces()

Annotate a class implementation.
invoke this method with reflection
check the output AnnotatedType[].


8



Check it with repeated annotations.


9



Invoke this method with reflection
check the output AnnotatedType[].

If input Class represents an interface,
the return value is an array containing objects
representing the uses of interface types to denote
interfaces directly extended by the interface.
The order of the objects in the array corresponds to
the order of the interface types used in the 'extends'
clause of the declaration of this Class.

10



Invoke this method with reflection
check the output AnnotatedType[].

If input Class represents a class or interface whose
declaration does not denote any superinterfaces,
the return value is an array of length 0.

11



Invoke this method with reflection
check the output AnnotatedType[].

If input Class represents either the Object class,
an array type, a primitive type, or void,
the return value is an array of length 0.

12



Invoke AnnotatedType.getType()
check if it returns interfaces' type.


13



Test super interfaces with no annotation.


14


public Annotation[] getAnnotations()

Declare TYPE_USE annotation on a class,
check the method's output.

return should be an array of 1 element.

15



Declare multiple TYPE_USE annotation on a class,
check the method's output.

return should be an array of multiple element.

@Fruit @Vegetable
public class Apple {
public Apple(){}
public static void test0(){
 Apple apple = new Apple();
 Class cls = apple.getClass();
  System.out.println("annotations: " +
     cls.getAnnotations());
}
@Retention(RUNTIME) @Target(TYPE_USE)
public @interface Fruit {}
@Retention(RUNTIME) @Target(TYPE_USE)
public @interface Vegetable {}
}

16



Declare no annotation on a class,
check the method's output.

Should be an array of 0 element.

-


public < A extends Annotation > A[] getAnnotationsByType(Class <A> annotationClass)

Declare a class with multiiple annotations. Invoke this method with input of one of the annotations' class.

Should get the expected annotation.

-



Declare a class with multiiple annotations. And the class's superclass the same. Invoke this method with input of one of the annotations' class.

Should get the expected annotation.


Files in java/lang/reflect




17

Constructor.java

public AnnotatedType getAnnotatedReturnType()

Invoke this method with one annotation
check the constructor's return type.

Should get one annotated type.

18



Invoke this method with multiple annotations
check the constructor's return type.

Should get multiple annotated type.

19



Invoke this method with 0 annotations
check the constructor's return type.

Should get 0-length annotated type array.

20



Invoke AnnotatedType.getType()
check if it returns the class type.


21

Executable.java

public AnnotatedType getAnnotatedReceiverType()

Invoke this method with reflection
check the receiver type
– constructor/method


22



Check it with repeated annotations.


23



check output if no annotation on receiver


24



Invoke AnnotatedType.getType()
check if it returns receiver's type.


25


public AnnotatedType[] getAnnotatedParameterTypes()

Invoke this method with reflection
check the output – constructor/method,
check the order


26



Check it with repeated annotations.


27



check output if no parameter


28



Invoke AnnotatedType.getType()
check if it returns parameter's type.


29


public AnnotatedType[] getAnnotatedExceptionTypes()

Invoke this method with reflection
check the output


30



Check it with repeated annotations.


31



check output if no exception


32



check output if no annotation on exception


33



Invoke AnnotatedType.getType()
check if it returns exception's type.


34

Field.java

public AnnotatedType getAnnotatedType()

Invoke this method with reflection
check the output
-for reference, primitive, array types.


35



Check it with repeated annotations for
reference, primitive, array types.


36



check output if no annotation on fields of
reference, primitive, array types.


37



Invoke AnnotatedType.getType()
check if it returns field's type.


38

Method.java

public AnnotatedType getAnnotatedReturnType()

Invoke this method with reflection
check the return type – constructor/method


39



Check it with repeated annotations.


40



check output if no annotation on return type


41



Check result if return = void


42



Check result if return = premitive type


43



Invoke AnnotatedType.getType()
check if it returns the returned type.


44

TypeVariable.java

AnnotatedType[] getAnnotatedBounds()

Invoke this method with reflection
check the output


45



Check it with repeated annotations.


46



type parameter declares no bounds
check the output

should return an array of length 0

47

AnnotatedArrayType.java

AnnotatedType getAnnotatedGenericComponentType()

Invoke this method with reflection
check the output

48



Check it with repeated annotations.


49



check output if no generic use

50

AnnotatedParameterizedType.java

AnnotatedType[] getAnnotatedActualTypeArguments()

Invoke this method with reflection
check the output


51



Check it with repeated annotations.


52



check it with no parameterized type


53

AnnotatedType.java

public Type getType()

This method should be covered in other tests


54

AnnotatedTypeVariable.java

AnnotatedType[] getAnnotatedBounds()

Invoke this method with reflection
check the output

55



Check it with repeated annotations.


56



the type parameter declares no bounds
Returns an array of length 0

57

AnnotatedWildcardType.java

AnnotatedType[] getAnnotatedLowerBounds()

Invoke this method with lower bounds
check the output

58



Check it with repeated annotations.


59


AnnotatedType[] getAnnotatedUpperBounds()

Invoke this method with upper bounds
check the output

60



Check it with repeated annotations.


Reference Materials