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.
There are numerous regression/unit tests that have already been integrated with the feature.
There are no existing tests to be deprecated.
# |
Class |
API |
Test Approach |
Notes |
1 |
java/lang/Class.java |
public AnnotatedType getAnnotatedSuperclass() |
Annotate
a super declaration. |
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 |
|
3 |
|
|
Invoke
this method with reflection |
If input Class represents a
class type whose declaration |
4 |
|
|
Invoke
this method with reflection |
If input Class represents
either the Object class, |
5 |
|
|
Test super class with no annotation. |
|
6 |
|
|
Invoke
AnnotatedType.getType() |
|
7 |
|
public AnnotatedType[] getAnnotatedInterfaces() |
Annotate
a class implementation. |
|
8 |
|
|
Check it with repeated annotations. |
|
9 |
|
|
Invoke
this method with reflection |
If input Class represents an
interface, |
10 |
|
|
Invoke
this method with reflection |
If input Class represents a
class or interface whose |
11 |
|
|
Invoke
this method with reflection |
If input Class represents
either the Object class, |
12 |
|
|
Invoke
AnnotatedType.getType() |
|
13 |
|
|
Test super interfaces with no annotation. |
|
14 |
|
public Annotation[] getAnnotations() |
Declare
TYPE_USE annotation on a class, |
return should be an array of 1 element. |
15 |
|
|
Declare
multiple TYPE_USE annotation on a class, |
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, |
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 |
Should get one annotated type. |
18 |
|
|
Invoke
this method with multiple annotations |
Should get multiple annotated type. |
19 |
|
|
Invoke
this method with 0 annotations |
Should get 0-length annotated type array. |
20 |
|
|
Invoke
AnnotatedType.getType() |
|
21 |
Executable.java |
public AnnotatedType getAnnotatedReceiverType() |
Invoke
this method with reflection |
|
22 |
|
|
Check it with repeated annotations. |
|
23 |
|
|
check output if no annotation on receiver |
|
24 |
|
|
Invoke
AnnotatedType.getType() |
|
25 |
|
public AnnotatedType[] getAnnotatedParameterTypes() |
Invoke
this method with reflection |
|
26 |
|
|
Check it with repeated annotations. |
|
27 |
|
|
check output if no parameter |
|
28 |
|
|
Invoke
AnnotatedType.getType() |
|
29 |
|
public AnnotatedType[] getAnnotatedExceptionTypes() |
Invoke
this method with reflection |
|
30 |
|
|
Check it with repeated annotations. |
|
31 |
|
|
check output if no exception |
|
32 |
|
|
check output if no annotation on exception |
|
33 |
|
|
Invoke
AnnotatedType.getType() |
|
34 |
Field.java |
public AnnotatedType getAnnotatedType() |
Invoke
this method with reflection |
|
35 |
|
|
Check
it with repeated annotations for |
|
36 |
|
|
check
output if no annotation on fields of |
|
37 |
|
|
Invoke
AnnotatedType.getType() |
|
38 |
Method.java |
public AnnotatedType getAnnotatedReturnType() |
Invoke
this method with reflection |
|
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() |
|
44 |
TypeVariable.java |
AnnotatedType[] getAnnotatedBounds() |
Invoke
this method with reflection |
|
45 |
|
|
Check it with repeated annotations. |
|
46 |
|
|
type
parameter declares no bounds |
should return an array of length 0 |
47 |
AnnotatedArrayType.java |
AnnotatedType getAnnotatedGenericComponentType() |
Invoke
this method with reflection |
|
48 |
|
|
Check it with repeated annotations. |
|
49 |
|
|
check output if no generic use |
|
50 |
AnnotatedParameterizedType.java |
AnnotatedType[] getAnnotatedActualTypeArguments() |
Invoke
this method with reflection |
|
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 |
|
55 |
|
|
Check it with repeated annotations. |
|
56 |
|
|
the
type parameter declares no bounds |
|
57 |
AnnotatedWildcardType.java |
AnnotatedType[] getAnnotatedLowerBounds() |
Invoke
this method with lower bounds |
|
58 |
|
|
Check it with repeated annotations. |
|
59 |
|
AnnotatedType[] getAnnotatedUpperBounds() |
Invoke
this method with upper bounds |
|
60 |
|
|
Check it with repeated annotations. |
|