This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new b9f305a3f Unit tests.
b9f305a3f is described below
commit b9f305a3f545b8431471809f8deb954332cf7381
Author: James Bognar <[email protected]>
AuthorDate: Sat Oct 11 13:32:29 2025 -0400
Unit tests.
---
.../apache/juneau/bean/html5/HtmlBuilder_Test.java | 181 +++++++++++++++++++++
.../bean/html5/HtmlElementContainer_Test.java | 87 ++++++++++
.../juneau/bean/html5/HtmlElementMixed_Test.java | 93 +++++++++++
.../apache/juneau/bean/html5/HtmlElement_Test.java | 69 ++++++++
.../apache/juneau/bean/html5/HtmlText_Test.java | 36 ++++
.../org/apache/juneau/bean/html5/Select_Test.java | 38 +++++
6 files changed, 504 insertions(+)
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/bean/html5/HtmlBuilder_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/bean/html5/HtmlBuilder_Test.java
new file mode 100644
index 000000000..b1dcc3829
--- /dev/null
+++
b/juneau-utest/src/test/java/org/apache/juneau/bean/html5/HtmlBuilder_Test.java
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.juneau.bean.html5;
+
+import static org.apache.juneau.bean.html5.HtmlBuilder.*;
+import static org.apache.juneau.junit.bct.BctAssertions.*;
+
+import org.apache.juneau.*;
+import org.junit.jupiter.api.*;
+
+class HtmlBuilder_Test extends TestBase {
+
+ @Test void a01_allStaticMethods() {
+ assertString("<a></a>", a());
+ assertString("<abbr></abbr>", abbr());
+ assertString("<address></address>", address());
+ assertString("<area/>", area());
+ assertString("<article></article>", article());
+ assertString("<aside></aside>", aside());
+ assertString("<audio></audio>", audio());
+ assertString("<b></b>", b());
+ assertString("<base/>", base());
+ assertString("<bdi></bdi>", bdi());
+ assertString("<bdo></bdo>", bdo());
+ assertString("<blockquote></blockquote>", blockquote());
+ assertString("<body></body>", body());
+ assertString("<br/>", br());
+ assertString("<button></button>", button());
+ assertString("<canvas></canvas>", canvas());
+ assertString("<caption></caption>", caption());
+ assertString("<cite></cite>", cite());
+ assertString("<code></code>", code());
+ assertString("<col/>", col());
+ assertString("<colgroup></colgroup>", colgroup());
+ assertString("<data></data>", data());
+ assertString("<datalist></datalist>", datalist());
+ assertString("<dd></dd>", dd());
+ assertString("<del></del>", del());
+ assertString("<dfn></dfn>", dfn());
+ assertString("<div></div>", div());
+ assertString("<dl></dl>", dl());
+ assertString("<dt></dt>", dt());
+ assertString("<em></em>", em());
+ assertString("<embed/>", embed());
+ assertString("<fieldset></fieldset>", fieldset());
+ assertString("<figcaption></figcaption>", figcaption());
+ assertString("<figure></figure>", figure());
+ assertString("<footer></footer>", footer());
+ assertString("<form></form>", form());
+ assertString("<h1></h1>", h1());
+ assertString("<h2></h2>", h2());
+ assertString("<h3></h3>", h3());
+ assertString("<h4></h4>", h4());
+ assertString("<h5></h5>", h5());
+ assertString("<h6></h6>", h6());
+ assertString("<head></head>", head());
+ assertString("<header></header>", header());
+ assertString("<hr/>", hr());
+ assertString("<html></html>", html());
+ assertString("<i></i>", i());
+ assertString("<iframe></iframe>", iframe());
+ assertString("<img/>", img());
+ assertString("<input/>", input());
+ assertString("<ins></ins>", ins());
+ assertString("<kbd></kbd>", kbd());
+ assertString("<keygen/>", keygen());
+ assertString("<label></label>", label());
+ assertString("<legend></legend>", legend());
+ assertString("<li></li>", li());
+ assertString("<link/>", link());
+ assertString("<main></main>", main());
+ assertString("<map></map>", map());
+ assertString("<mark></mark>", mark());
+ assertString("<meta/>", meta());
+ assertString("<meter></meter>", meter());
+ assertString("<nav></nav>", nav());
+ assertString("<noscript></noscript>", noscript());
+ assertString("<object></object>", object());
+ assertString("<ol></ol>", ol());
+ assertString("<optgroup></optgroup>", optgroup());
+ assertString("<option></option>", option());
+ assertString("<output></output>", output());
+ assertString("<p></p>", p());
+ assertString("<param/>", param());
+ assertString("<pre></pre>", pre());
+ assertString("<progress></progress>", progress());
+ assertString("<q></q>", q());
+ assertString("<rb></rb>", rb());
+ assertString("<rp></rp>", rp());
+ assertString("<rt></rt>", rt());
+ assertString("<rtc></rtc>", rtc());
+ assertString("<ruby></ruby>", ruby());
+ assertString("<s></s>", s());
+ assertString("<samp></samp>", samp());
+ assertString("<script></script>", script());
+ assertString("<section></section>", section());
+ assertString("<select></select>", select());
+ assertString("<small></small>", small());
+ assertString("<source/>", source());
+ assertString("<span></span>", span());
+ assertString("<strong></strong>", strong());
+ assertString("<style></style>", style());
+ assertString("<sub></sub>", sub());
+ assertString("<sup></sup>", sup());
+ assertString("<table></table>", table());
+ assertString("<tbody></tbody>", tbody());
+ assertString("<td></td>", td());
+ assertString("<template></template>", template());
+ assertString("<textarea></textarea>", textarea());
+ assertString("<tfoot></tfoot>", tfoot());
+ assertString("<th></th>", th());
+ assertString("<thead></thead>", thead());
+ assertString("<time></time>", time());
+ assertString("<title></title>", title());
+ assertString("<tr></tr>", tr());
+ assertString("<track/>", track());
+ assertString("<u></u>", u());
+ assertString("<ul></ul>", ul());
+ assertString("<var></var>", var());
+ assertString("<video></video>", video());
+ assertString("<wbr/>", wbr());
+ }
+
+ @Test void a02_parametrizedMethods() {
+ assertString("<a href='url'>text</a>", a("url", "text"));
+ assertString("<form action='submit'><input/></form>",
form("submit", input()));
+ assertString("<button type='submit'>Click</button>",
button("submit", "Click"));
+ assertString("<input type='text'/>", input("text"));
+ assertString("<option value='v'>text</option>", option("v",
"text"));
+ assertString("<select name='test'><option></option></select>",
select("test", option()));
+ assertString("<textarea name='test'>content</textarea>",
textarea("test", "content"));
+ assertString("<canvas width='100' height='100'></canvas>",
canvas(100, 100));
+ assertString("<audio src='test.mp3'></audio>",
audio("test.mp3"));
+ assertString("<colgroup><col/></colgroup>", colgroup(col()));
+ assertString("<datalist
id='test'><option></option></datalist>", datalist("test", option()));
+ assertString("<dl><dt></dt></dl>", dl(dt()));
+ assertString("<figure><img/></figure>", figure(img()));
+ assertString("<html>en</html>", html("en"));
+ assertString("<main><p></p></main>", main(p()));
+ assertString("<map>test</map>", map("test"));
+ assertString("<ol><li></li></ol>", ol(li()));
+ assertString("<optgroup>test<option></option></optgroup>",
optgroup("test", option()));
+ assertString("<tbody><tr></tr></tbody>", tbody(tr()));
+ assertString("<tfoot><tr></tr></tfoot>", tfoot(tr()));
+ assertString("<thead><tr></tr></thead>", thead(tr()));
+ assertString("<tr><td></td></tr>", tr(td()));
+ assertString("<ul><li></li></ul>", ul(li()));
+ assertString("<video src='test.mp4'></video>",
video("test.mp4"));
+ }
+
+ @Test void a03_additionalParametrizedMethods() {
+ assertString("<abbr title='test'>content</abbr>", abbr("test",
"content"));
+ assertString("<area shape='rect' coords='0,0,100,100'
href='url'/>", area("rect", "0,0,100,100", "url"));
+ assertString("<bdo dir='rtl'>text</bdo>", bdo("rtl", "text"));
+ assertString("<data value='12345'>Product</data>",
data("12345", "Product"));
+ assertString("<param name='autoplay' value='true'/>",
param("autoplay", "true"));
+ assertString("<script
type='text/javascript'>alert('test');</script>", script("text/javascript",
"alert('test');"));
+ assertString("<source src='video.mp4' type='video/mp4'/>",
source("video.mp4", "video/mp4"));
+ assertString("<template id='test'><p></p></template>",
template("test", p()));
+ assertString("<track src='captions.vtt' kind='captions'/>",
track("captions.vtt", "captions"));
+ }
+
+ @Test void a04_varargsChildren() {
+ assertString("<address>text<strong>bold</strong></address>",
address("text", strong("bold")));
+ assertString("<time>10:00<span>AM</span></time>", time("10:00",
span("AM")));
+ }
+}
\ No newline at end of file
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/bean/html5/HtmlElementContainer_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/bean/html5/HtmlElementContainer_Test.java
new file mode 100644
index 000000000..b8ee9b1dd
--- /dev/null
+++
b/juneau-utest/src/test/java/org/apache/juneau/bean/html5/HtmlElementContainer_Test.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.juneau.bean.html5;
+
+import static org.apache.juneau.bean.html5.HtmlBuilder.*;
+import static org.apache.juneau.junit.bct.BctAssertions.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.apache.juneau.*;
+import org.junit.jupiter.api.*;
+
+class HtmlElementContainer_Test extends TestBase {
+
+ @Test void a01_getChild_nullChildren() {
+ Div x = new Div();
+ assertNull(x.getChild(0));
+ }
+
+ @Test void a02_getChild_outOfBounds() {
+ Div x = div("child1");
+ assertNull(x.getChild(5));
+ assertNull(x.getChild(-1));
+ }
+
+ @Test void a03_getChild_valid() {
+ Div x = div("child1", "child2");
+ assertString("child1", x.getChild(0));
+ assertString("child2", x.getChild(1));
+ }
+
+ @Test void a04_getChild_typed_nullChildren() {
+ Div x = new Div();
+ assertNull(x.getChild(String.class, 0));
+ }
+
+ @Test void a05_getChild_typed_outOfBounds() {
+ Div x = div("child1");
+ assertNull(x.getChild(String.class, 5));
+ assertNull(x.getChild(String.class, -1));
+ }
+
+ @Test void a06_getChild_typed_valid() {
+ Div x = div("child1", "child2");
+ assertString("child1", x.getChild(String.class, 0));
+ assertString("child2", x.getChild(String.class, 1));
+ }
+
+ @Test void a07_getChildren() {
+ Div x1 = new Div();
+ assertNull(x1.getChildren());
+
+ Div x2 = div("child1", "child2");
+ assertString("[child1,child2]", x2.getChildren());
+ }
+
+ @Test void a08_children_emptyArray() {
+ Div x = new Div();
+ x.children();
+ assertNull(x.getChildren());
+ }
+
+ @Test void a09_children_withValues() {
+ Div x = new Div();
+ x.children("child1", "child2");
+ assertString("[child1,child2]", x.getChildren());
+ }
+
+ @Test void a10_child_singleValue() {
+ Div x = new Div();
+ x.child("child1");
+ assertString("[child1]", x.getChildren());
+ }
+}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/bean/html5/HtmlElementMixed_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/bean/html5/HtmlElementMixed_Test.java
new file mode 100644
index 000000000..86062b72b
--- /dev/null
+++
b/juneau-utest/src/test/java/org/apache/juneau/bean/html5/HtmlElementMixed_Test.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.juneau.bean.html5;
+
+import static org.apache.juneau.bean.html5.HtmlBuilder.*;
+import static org.apache.juneau.junit.bct.BctAssertions.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.apache.juneau.*;
+import org.junit.jupiter.api.*;
+
+class HtmlElementMixed_Test extends TestBase {
+
+ @Test void a01_getChild_nullChildren() {
+ P x = new P();
+ assertNull(x.getChild(0));
+ }
+
+ @Test void a02_getChild_outOfBounds() {
+ P x = p("child1");
+ assertNull(x.getChild(5));
+ assertNull(x.getChild(-1));
+ }
+
+ @Test void a03_getChild_valid() {
+ P x = p("child1", "child2");
+ assertString("child1", x.getChild(0));
+ assertString("child2", x.getChild(1));
+ }
+
+ @Test void a04_getChild_typed_nullChildren() {
+ P x = new P();
+ assertNull(x.getChild(String.class, 0));
+ }
+
+ @Test void a05_getChild_typed_outOfBounds() {
+ P x = p("child1");
+ assertNull(x.getChild(String.class, 5));
+ assertNull(x.getChild(String.class, -1));
+ }
+
+ @Test void a06_getChild_typed_valid() {
+ P x = p("child1", "child2");
+ assertString("child1", x.getChild(String.class, 0));
+ assertString("child2", x.getChild(String.class, 1));
+ }
+
+ @Test void a07_child_withCollection() {
+ P x = new P();
+ x.child(java.util.Arrays.asList("text1", "text2"));
+ assertString("<p>text1text2</p>", x);
+ }
+
+ @Test void a08_child_withSingleValue() {
+ P x = new P();
+ x.child("text1");
+ assertString("<p>text1</p>", x);
+ }
+
+ @Test void a09_getChildren() {
+ P x1 = new P();
+ assertNull(x1.getChildren());
+
+ P x2 = p("child1", "child2");
+ assertString("[child1,child2]", x2.getChildren());
+ }
+
+ @Test void a10_children_emptyArray() {
+ P x = new P();
+ x.children();
+ assertNull(x.getChildren());
+ }
+
+ @Test void a11_children_withValues() {
+ P x = new P();
+ x.children("child1", "child2");
+ assertString("[child1,child2]", x.getChildren());
+ }
+}
\ No newline at end of file
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/bean/html5/HtmlElement_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/bean/html5/HtmlElement_Test.java
new file mode 100644
index 000000000..908291c5d
--- /dev/null
+++
b/juneau-utest/src/test/java/org/apache/juneau/bean/html5/HtmlElement_Test.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.juneau.bean.html5;
+
+import static org.apache.juneau.bean.html5.HtmlBuilder.*;
+import static org.apache.juneau.junit.bct.BctAssertions.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.apache.juneau.*;
+import org.junit.jupiter.api.*;
+
+class HtmlElement_Test extends TestBase {
+
+ @Test void a01_getAttr_withNull() {
+ A x = a();
+ assertNull(x.getAttr(String.class, "nonexistent"));
+ }
+
+ @Test void a02_getAttr_withValue() {
+ A x = a().href("test");
+ assertString("test", x.getAttr(String.class, "href"));
+ }
+
+ @Test void a03_deminimize() {
+ Button x1 = button().disabled(true);
+ assertString("<button disabled='disabled'></button>", x1);
+
+ Button x2 = button().disabled(false);
+ assertString("<button></button>", x2);
+
+ Button x3 = button().disabled("custom");
+ assertString("<button disabled='custom'></button>", x3);
+ }
+
+ @Test void a04_attr_withNull() {
+ A x = a().href("test");
+ assertString("<a href='test'></a>", x);
+ x.attr("href", null);
+ assertString("<a></a>", x);
+ }
+
+ @Test void a05_attr_urlConversion() {
+ A x = a();
+ x.attr("url", "http://example.com");
+ assertString("http://example.com", x.getAttr(String.class,
"url"));
+
+ A x2 = a();
+ x2.attr("href", "http://example.com");
+ assertString("http://example.com", x2.getAttr(String.class,
"href"));
+
+ Form x3 = form();
+ x3.attr("action", "http://example.com");
+ assertString("http://example.com", x3.getAttr(String.class,
"action"));
+ }
+}
\ No newline at end of file
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/bean/html5/HtmlText_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/bean/html5/HtmlText_Test.java
new file mode 100644
index 000000000..37e1cb9a9
--- /dev/null
+++ b/juneau-utest/src/test/java/org/apache/juneau/bean/html5/HtmlText_Test.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.juneau.bean.html5;
+
+import static org.apache.juneau.junit.bct.BctAssertions.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.apache.juneau.*;
+import org.junit.jupiter.api.*;
+
+class HtmlText_Test extends TestBase {
+
+ @Test void a01_basic() {
+ HtmlText x = new HtmlText("test content");
+ assertString("test content", x);
+ }
+
+ @Test void a02_null() {
+ HtmlText x = new HtmlText(null);
+ assertNull(x.toString());
+ }
+}
\ No newline at end of file
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/bean/html5/Select_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/bean/html5/Select_Test.java
index a62466afc..6cad39940 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/bean/html5/Select_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/bean/html5/Select_Test.java
@@ -112,4 +112,42 @@ class Select_Test extends TestBase {
assertString("<select name='a'>b1<strong>b2</strong></select>",
x1);
}
+
+ @Test void a04_choose_withValue() {
+ Select x = select("test",
+ option("val1", "Option 1"),
+ option("val2", "Option 2"),
+ option("val3", "Option 3")
+ ).choose("val2");
+
+ assertString("<select name='test'><option value='val1'>Option
1</option><option value='val2' selected='selected'>Option 2</option><option
value='val3'>Option 3</option></select>", x);
+ }
+
+ @Test void a04_choose_withNull() {
+ Select x = select("test",
+ option("val1", "Option 1"),
+ option("val2", "Option 2")
+ ).choose(null);
+
+ assertString("<select name='test'><option value='val1'>Option
1</option><option value='val2'>Option 2</option></select>", x);
+ }
+
+ @Test void a04_choose_withNonMatchingValue() {
+ Select x = select("test",
+ option("val1", "Option 1"),
+ option("val2", "Option 2")
+ ).choose("val3");
+
+ assertString("<select name='test'><option value='val1'>Option
1</option><option value='val2'>Option 2</option></select>", x);
+ }
+
+ @Test void a04_choose_withNonOptionChildren() {
+ Select x = select("test",
+ option("val1", "Option 1"),
+ "plain text",
+ div("not an option")
+ ).choose("val1");
+
+ assertString("<select name='test'><option value='val1'
selected='selected'>Option 1</option>plain text<div>not an
option</div></select>", x);
+ }
}
\ No newline at end of file