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