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