1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.http.annotation;
18
19 import static org.apache.juneau.TestUtils.*;
20 import static org.junit.jupiter.api.Assertions.*;
21
22 import org.apache.juneau.*;
23 import org.junit.jupiter.api.*;
24
25 class ResponseStatusAnnotation_Test extends TestBase {
26
27 private static final String CNAME = ResponseStatusAnnotation_Test.class.getName();
28
29 public static class X1 {}
30
31
32
33
34
35 StatusCode a1 = StatusCodeAnnotation.create()
36 .description("a")
37 .on("b")
38 .onClass(X1.class)
39 .value(1)
40 .build();
41
42 StatusCode a2 = StatusCodeAnnotation.create()
43 .description("a")
44 .on("b")
45 .onClass(X1.class)
46 .value(1)
47 .build();
48
49 @Test void a01_basic() {
50 assertBean(a1, "description,on,onClass,value", "[a],[b],[X1],[1]");
51 }
52
53 @Test void a02_testEquivalency() {
54 assertEquals(a2, a1);
55 assertNotEqualsAny(a1.hashCode(), 0, -1);
56 assertEquals(a1.hashCode(), a2.hashCode());
57 }
58
59
60
61
62
63 @Test void b01_testEquivalencyInPropertyStores() {
64 var bc1 = BeanContext.create().annotations(a1).build();
65 var bc2 = BeanContext.create().annotations(a2).build();
66 assertSame(bc1, bc2);
67 }
68
69
70
71
72
73 public static class C1 {
74 public int f1;
75 public void m1() {}
76 }
77 public static class C2 {
78 public int f2;
79 public void m2() {}
80 }
81
82 @Test void c01_otherMethods() throws Exception {
83 var c1 = StatusCodeAnnotation.create(C1.class).on(C2.class).build();
84 var c2 = StatusCodeAnnotation.create("a").on("b").build();
85 var c4 = StatusCodeAnnotation.create().on(C1.class.getMethod("m1")).on(C2.class.getMethod("m2")).build();
86
87 assertBean(c1, "on", "["+CNAME+"$C1,"+CNAME+"$C2]");
88 assertBean(c2, "on", "[a,b]");
89 assertBean(c4, "on", "["+CNAME+"$C1.m1(),"+CNAME+"$C2.m2()]");
90 }
91
92
93
94
95
96 @StatusCode(
97 description={ "a" },
98 on="b",
99 onClass=X1.class,
100 value=1
101 )
102 public static class D1 {}
103 StatusCode d1 = D1.class.getAnnotationsByType(StatusCode.class)[0];
104
105 @StatusCode(
106 description={ "a" },
107 on="b",
108 onClass=X1.class,
109 value=1
110 )
111 public static class D2 {}
112 StatusCode d2 = D2.class.getAnnotationsByType(StatusCode.class)[0];
113
114 @Test void d01_comparisonWithDeclarativeAnnotations() {
115 assertEqualsAll(a1, d1, d2);
116 assertNotEqualsAny(a1.hashCode(), 0, -1);
117 assertEqualsAll(a1.hashCode(), d1.hashCode(), d2.hashCode());
118 }
119 }