1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.bean.html5;
18
19 import static org.apache.juneau.bean.html5.HtmlBuilder.*;
20 import static org.apache.juneau.commons.utils.CollectionUtils.*;
21 import static org.apache.juneau.junit.bct.BctAssertions.*;
22 import static org.junit.jupiter.api.Assertions.*;
23
24 import org.apache.juneau.*;
25 import org.junit.jupiter.api.*;
26
27 class HtmlElementMixed_Test extends TestBase {
28
29 @Test void a01_getChild_nullChildren() {
30 P x = new P();
31 assertNull(x.getChild(0));
32 }
33
34 @Test void a02_getChild_outOfBounds() {
35 P x = p("child1");
36 assertNull(x.getChild(5));
37 assertNull(x.getChild(-1));
38 }
39
40 @Test void a03_getChild_valid() {
41 P x = p("child1", "child2");
42 assertString("child1", x.getChild(0));
43 assertString("child2", x.getChild(1));
44 }
45
46 @Test void a04_getChild_typed_nullChildren() {
47 P x = new P();
48 assertNull(x.getChild(String.class, 0));
49 }
50
51 @Test void a05_getChild_typed_outOfBounds() {
52 P x = p("child1");
53 assertNull(x.getChild(String.class, 5));
54 assertNull(x.getChild(String.class, -1));
55 }
56
57 @Test void a06_getChild_typed_valid() {
58 P x = p("child1", "child2");
59 assertString("child1", x.getChild(String.class, 0));
60 assertString("child2", x.getChild(String.class, 1));
61 }
62
63 @Test void a07_child_withCollection() {
64 P x = new P();
65 x.child(l("text1", "text2"));
66 assertString("<p>text1text2</p>", x);
67 }
68
69 @Test void a08_child_withSingleValue() {
70 P x = new P();
71 x.child("text1");
72 assertString("<p>text1</p>", x);
73 }
74
75 @Test void a09_getChildren() {
76 P x1 = new P();
77 assertNull(x1.getChildren());
78
79 P x2 = p("child1", "child2");
80 assertString("[child1,child2]", x2.getChildren());
81 }
82
83 @Test void a10_children_emptyArray() {
84 P x = new P();
85 x.children();
86 assertNull(x.getChildren());
87 }
88
89 @Test void a11_children_withValues() {
90 P x = new P();
91 x.children("child1", "child2");
92 assertString("[child1,child2]", x.getChildren());
93 }
94
95 @Test void a12_getChild_varargs_emptyArray() {
96 P x = p("child1");
97 assertNull(x.getChild(ints()));
98 }
99
100 @Test void a13_getChild_varargs_singleIndex() {
101 P x = p("child1", "child2");
102 assertString("child1", x.getChild(ints(0)));
103 }
104
105 @Test void a14_getChild_varargs_multipleIndices() {
106
107 P x = p(
108 span(
109 strong("text1"),
110 strong("text2")
111 ),
112 span("text3")
113 );
114
115
116 assertString("text1", x.getChild(0, 0, 0));
117 assertString("text2", x.getChild(0, 1, 0));
118 assertString("text3", x.getChild(1, 0));
119 }
120
121 @Test void a15_getChild_varargs_invalidPath() {
122 P x = p("text");
123
124 assertNull(x.getChild(0, 0));
125 }
126
127 @Test void a16_getChild_varargs_throughContainer() {
128
129 P x = p(
130 div(
131 span("nested")
132 )
133 );
134
135 assertString("nested", x.getChild(0, 0, 0));
136 }
137
138 @Test void a17_setChildren() {
139 P x = new P();
140 java.util.List<Object> children = l("child1", "child2");
141 x.setChildren(children);
142 assertString("[child1,child2]", x.getChildren());
143 }
144
145 @Test void a18_child_withCollection_existingChildren() {
146
147 P x = new P();
148 x.child("existing");
149 x.child(l("new1", "new2"));
150 assertString("<p>existingnew1new2</p>", x);
151 }
152 }