1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.test;
17
18 import org.junit.Assert;
19 import org.junit.Test;
20
21 import java.lang.annotation.*;
22 import java.lang.reflect.Method;
23
24
25
26
27
28
29 public class AnnotationOrderTest {
30 @Target({ElementType.TYPE, ElementType.METHOD})
31 @Retention(RetentionPolicy.RUNTIME)
32 @interface TestAnnotation {
33 String value();
34 }
35
36 @Target({ElementType.TYPE, ElementType.METHOD})
37 @Retention(RetentionPolicy.RUNTIME)
38 @interface TestAnnotation1 {
39 String value();
40 }
41
42 @Target({ElementType.TYPE, ElementType.METHOD})
43 @Retention(RetentionPolicy.RUNTIME)
44 @interface TestAnnotation2 {
45 String value();
46 }
47
48 @Target({ElementType.TYPE, ElementType.METHOD})
49 @Retention(RetentionPolicy.RUNTIME)
50 @interface TestAnnotationHolder {
51 TestAnnotation[] value();
52 }
53
54
55 @Test
56 @TestAnnotation1("11")
57 @TestAnnotationHolder({
58 @TestAnnotation("1"),
59 @TestAnnotation("2"),
60 @TestAnnotation("3"),
61 @TestAnnotation("4"),
62 @TestAnnotation("5"),
63 @TestAnnotation("6")
64 })
65 @TestAnnotation2("22")
66 public void testAnnotationOrder() throws Exception {
67 Method me = getClass().getMethod("testAnnotationOrder");
68 Annotation[] annotations = me.getAnnotations();
69 Assert.assertEquals(4, annotations.length);
70 Assert.assertEquals(Test.class, annotations[0].annotationType());
71 Assert.assertEquals(TestAnnotation1.class, annotations[1].annotationType());
72 Assert.assertEquals(TestAnnotationHolder.class, annotations[2].annotationType());
73 Assert.assertEquals(TestAnnotation2.class, annotations[3].annotationType());
74
75 TestAnnotationHolder holder = me.getAnnotation(TestAnnotationHolder.class);
76 TestAnnotation[] children = holder.value();
77 Assert.assertEquals(6, children.length);
78 Assert.assertEquals("1", children[0].value());
79 Assert.assertEquals("2", children[1].value());
80 Assert.assertEquals("3", children[2].value());
81 Assert.assertEquals("4", children[3].value());
82 Assert.assertEquals("5", children[4].value());
83 Assert.assertEquals("6", children[5].value());
84 }
85 }