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 16b7cf046 Unit test modernization.
16b7cf046 is described below

commit 16b7cf046ee32f10519753752bd0cd88b9fb0a26
Author: James Bognar <[email protected]>
AuthorDate: Thu Jul 31 17:12:26 2025 -0400

    Unit test modernization.
---
 .../java/org/apache/juneau/config/ConfigTest.java   | 14 +++++++-------
 .../java/org/apache/juneau/html/Common_Test.java    |  3 ++-
 .../java/org/apache/juneau/json/CommonTest.java     |  4 ++--
 .../rest/client/RestClient_BasicCalls_Test.java     | 21 +++++++++++----------
 .../java/org/apache/juneau/uon/Common_UonTest.java  |  4 ++--
 .../juneau/urlencoding/Common_UrlEncodingTest.java  |  4 ++--
 .../java/org/apache/juneau/utest/utils/Utils.java   |  8 ++++++++
 .../java/org/apache/juneau/xml/CommonXmlTest.java   |  7 ++++---
 .../test/java/org/apache/juneau/xml/XmlTest.java    | 10 +++++-----
 9 files changed, 43 insertions(+), 32 deletions(-)

diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/config/ConfigTest.java 
b/juneau-utest/src/test/java/org/apache/juneau/config/ConfigTest.java
index e25aed905..d27c60f70 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/config/ConfigTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/config/ConfigTest.java
@@ -13,9 +13,9 @@
 package org.apache.juneau.config;
 
 import static org.apache.juneau.assertions.Assertions.*;
-import static org.apache.juneau.internal.CollectionUtils.*;
 import static org.apache.juneau.utest.utils.Utils.*;
 import static org.junit.Assert.*;
+import static org.apache.juneau.utest.utils.Utils.*;
 
 import java.io.*;
 import java.net.*;
@@ -1030,12 +1030,12 @@ public class ConfigTest {
                assertInteger(cf.get("key3").as(int[].class).get()[2]).is(3);
                assertInteger(cf.get("xkey3").as(int[].class).orElse(new 
int[]{4,5,6})[2]).is(6);
                assertInteger(cf.get("X/key3").as(int[].class).orElse(new 
int[]{4,5,6})[2]).is(6);
-               assertEquals(new URL("http://foo";).toString(), 
cf.get("key4").as(URL.class).get().toString());
+               assertEquals(url("http://foo";).toString(), 
cf.get("key4").as(URL.class).get().toString());
 
                assertInteger(cf.get("section1/key1").asInteger().get()).is(2);
                
assertBoolean(cf.get("section1/key2").asBoolean().get()).isFalse();
                
assertInteger(cf.get("section1/key3").as(int[].class).get()[2]).is(6);
-               assertEquals(new URL("http://bar";).toString(), 
cf.get("section1/key4").as(URL.class).get().toString());
+               assertEquals(url("http://bar";).toString(), 
cf.get("section1/key4").as(URL.class).get().toString());
 
                cf = init(
                        "# Default section",
@@ -1045,23 +1045,23 @@ public class ConfigTest {
                cf.set("key1", 1);
                cf.set("key2", true);
                cf.set("key3", new int[]{1,2,3});
-               cf.set("key4", new URL("http://foo";));
+               cf.set("key4", url("http://foo";));
                cf.set("section1/key1", 2);
                cf.set("section1/key2", false);
                cf.set("section1/key3", new int[]{4,5,6});
-               cf.set("section1/key4", new URL("http://bar";));
+               cf.set("section1/key4", url("http://bar";));
 
                cf.commit();
 
                assertInteger(cf.get("key1").asInteger().get()).is(1);
                assertBoolean(cf.get("key2").asBoolean().get()).isTrue();
                assertInteger(cf.get("key3").as(int[].class).get()[2]).is(3);
-               assertEquals(new URL("http://foo";).toString(), 
cf.get("key4").as(URL.class).get().toString());
+               assertEquals(url("http://foo";).toString(), 
cf.get("key4").as(URL.class).get().toString());
 
                assertInteger(cf.get("section1/key1").asInteger().get()).is(2);
                
assertBoolean(cf.get("section1/key2").asBoolean().get()).isFalse();
                
assertInteger(cf.get("section1/key3").as(int[].class).get()[2]).is(6);
-               assertEquals(new URL("http://bar";).toString(), 
cf.get("section1/key4").as(URL.class).get().toString());
+               assertEquals(url("http://bar";).toString(), 
cf.get("section1/key4").as(URL.class).get().toString());
        }
 
        
//====================================================================================================
diff --git a/juneau-utest/src/test/java/org/apache/juneau/html/Common_Test.java 
b/juneau-utest/src/test/java/org/apache/juneau/html/Common_Test.java
index 968109ab3..223748b0b 100755
--- a/juneau-utest/src/test/java/org/apache/juneau/html/Common_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/html/Common_Test.java
@@ -16,6 +16,7 @@ import static org.apache.juneau.assertions.Assertions.*;
 import static org.apache.juneau.internal.CollectionUtils.*;
 import static org.junit.Assert.*;
 import static org.junit.runners.MethodSorters.*;
+import static org.apache.juneau.utest.utils.Utils.*;
 
 import java.net.*;
 import java.util.*;
@@ -326,7 +327,7 @@ public class Common_Test {
                G t = new G();
                t.uri = new URI("http://uri";);
                t.f1 = new URI("http://f1";);
-               t.f2 = new URL("http://f2";);
+               t.f2 = url("http://f2";);
 
                String html = s.serialize(t);
                t = p.parse(html, G.class);
diff --git a/juneau-utest/src/test/java/org/apache/juneau/json/CommonTest.java 
b/juneau-utest/src/test/java/org/apache/juneau/json/CommonTest.java
index d55318744..f504c5324 100755
--- a/juneau-utest/src/test/java/org/apache/juneau/json/CommonTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/json/CommonTest.java
@@ -13,9 +13,9 @@
 package org.apache.juneau.json;
 
 import static org.apache.juneau.assertions.Assertions.*;
-import static org.apache.juneau.internal.CollectionUtils.*;
 import static org.junit.Assert.*;
 import static org.junit.runners.MethodSorters.*;
+import static org.apache.juneau.utest.utils.Utils.*;
 
 import java.net.*;
 import java.util.*;
@@ -217,7 +217,7 @@ public class CommonTest {
                G t = new G();
                t.uri = new URI("http://uri";);
                t.f1 = new URI("http://f1";);
-               t.f2 = new URL("http://f2";);
+               t.f2 = url("http://f2";);
 
                String json = s.serialize(t);
                t = p.parse(json, G.class);
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_BasicCalls_Test.java
 
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_BasicCalls_Test.java
index a6dab4c8c..01f8e0952 100644
--- 
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_BasicCalls_Test.java
+++ 
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_BasicCalls_Test.java
@@ -21,6 +21,7 @@ import static org.apache.juneau.internal.CollectionUtils.*;
 import static org.apache.juneau.internal.CollectionUtils.list;
 import static org.apache.juneau.utest.utils.Utils.*;
 import static org.junit.runners.MethodSorters.*;
+import static org.apache.juneau.utest.utils.Utils.*;
 
 import java.io.*;
 import java.net.*;
@@ -122,7 +123,7 @@ public class RestClient_BasicCalls_Test {
                List<Object> urls = list(
                        new URIBuilder("http://localhost/bean";),
                        java.net.URI.create("http://localhost/bean";),
-                       new URL("http://localhost/bean";),
+                       url("http://localhost/bean";),
                        "/bean",
                        new StringBuilder("/bean")
                );
@@ -153,7 +154,7 @@ public class RestClient_BasicCalls_Test {
                List<Object> urls = list(
                        new URIBuilder("http://localhost/bean";),
                        java.net.URI.create("http://localhost/bean";),
-                       new URL("http://localhost/bean";),
+                       url("http://localhost/bean";),
                        "/bean",
                        new StringBuilder("/bean")
                );
@@ -196,7 +197,7 @@ public class RestClient_BasicCalls_Test {
                List<Object> urls = list(
                        new URIBuilder("http://localhost/bean";),
                        java.net.URI.create("http://localhost/bean";),
-                       new URL("http://localhost/bean";),
+                       url("http://localhost/bean";),
                        "/bean",
                        new StringBuilder("/bean")
                );
@@ -233,7 +234,7 @@ public class RestClient_BasicCalls_Test {
                List<Object> urls = list(
                        new URIBuilder("http://localhost/bean";),
                        java.net.URI.create("http://localhost/bean";),
-                       new URL("http://localhost/bean";),
+                       url("http://localhost/bean";),
                        "/bean",
                        new StringBuilder("/bean")
                );
@@ -253,7 +254,7 @@ public class RestClient_BasicCalls_Test {
                List<Object> urls = list(
                        new URIBuilder("http://localhost/bean";),
                        java.net.URI.create("http://localhost/bean";),
-                       new URL("http://localhost/bean";),
+                       url("http://localhost/bean";),
                        "/bean",
                        new StringBuilder("/bean")
                );
@@ -273,7 +274,7 @@ public class RestClient_BasicCalls_Test {
                List<Object> urls = list(
                        new URIBuilder("http://localhost/bean";),
                        java.net.URI.create("http://localhost/bean";),
-                       new URL("http://localhost/bean";),
+                       url("http://localhost/bean";),
                        "/bean",
                        new StringBuilder("/bean")
                );
@@ -297,7 +298,7 @@ public class RestClient_BasicCalls_Test {
                List<Object> urls = list(
                        new URIBuilder("http://localhost/bean";),
                        java.net.URI.create("http://localhost/bean";),
-                       new URL("http://localhost/bean";),
+                       url("http://localhost/bean";),
                        "/bean",
                        new StringBuilder("/bean")
                );
@@ -369,7 +370,7 @@ public class RestClient_BasicCalls_Test {
                List<Object> urls = list(
                        new URIBuilder("http://localhost/bean";),
                        java.net.URI.create("http://localhost/bean";),
-                       new URL("http://localhost/bean";),
+                       url("http://localhost/bean";),
                        "/bean",
                        new StringBuilder("/bean")
                );
@@ -406,7 +407,7 @@ public class RestClient_BasicCalls_Test {
                List<Object> urls = list(
                        new URIBuilder("http://localhost/bean";),
                        java.net.URI.create("http://localhost/bean";),
-                       new URL("http://localhost/bean";),
+                       url("http://localhost/bean";),
                        "/bean",
                        new StringBuilder("/bean")
                );
@@ -426,7 +427,7 @@ public class RestClient_BasicCalls_Test {
                List<Object> urls = list(
                        new URIBuilder("http://localhost/bean";),
                        java.net.URI.create("http://localhost/bean";),
-                       new URL("http://localhost/bean";),
+                       url("http://localhost/bean";),
                        "/bean",
                        new StringBuilder("/bean")
                );
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/uon/Common_UonTest.java 
b/juneau-utest/src/test/java/org/apache/juneau/uon/Common_UonTest.java
index 27d643cb7..79892df7c 100755
--- a/juneau-utest/src/test/java/org/apache/juneau/uon/Common_UonTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/uon/Common_UonTest.java
@@ -13,9 +13,9 @@
 package org.apache.juneau.uon;
 
 import static org.apache.juneau.assertions.Assertions.*;
-import static org.apache.juneau.internal.CollectionUtils.*;
 import static org.junit.Assert.*;
 import static org.junit.runners.MethodSorters.*;
+import static org.apache.juneau.utest.utils.Utils.*;
 
 import java.net.*;
 import java.util.*;
@@ -210,7 +210,7 @@ public class Common_UonTest {
                G t = new G();
                t.uri = new URI("http://uri";);
                t.f1 = new URI("http://f1";);
-               t.f2 = new URL("http://f2";);
+               t.f2 = url("http://f2";);
 
                String r = s.serialize(t);
                t = p2.parse(r, G.class);
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/urlencoding/Common_UrlEncodingTest.java
 
b/juneau-utest/src/test/java/org/apache/juneau/urlencoding/Common_UrlEncodingTest.java
index 2def2f69f..31e8308d5 100755
--- 
a/juneau-utest/src/test/java/org/apache/juneau/urlencoding/Common_UrlEncodingTest.java
+++ 
b/juneau-utest/src/test/java/org/apache/juneau/urlencoding/Common_UrlEncodingTest.java
@@ -13,9 +13,9 @@
 package org.apache.juneau.urlencoding;
 
 import static org.apache.juneau.assertions.Assertions.*;
-import static org.apache.juneau.internal.CollectionUtils.*;
 import static org.junit.Assert.*;
 import static org.junit.runners.MethodSorters.*;
+import static org.apache.juneau.utest.utils.Utils.*;
 
 import java.net.*;
 import java.util.*;
@@ -212,7 +212,7 @@ public class Common_UrlEncodingTest {
                G t = new G();
                t.uri = new URI("http://uri";);
                t.f1 = new URI("http://f1";);
-               t.f2 = new URL("http://f2";);
+               t.f2 = url("http://f2";);
 
                String r = s.serialize(t);
                t = p2.parse(r, G.class);
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/utest/utils/Utils.java 
b/juneau-utest/src/test/java/org/apache/juneau/utest/utils/Utils.java
index 2254e8c6e..7844b2898 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/utest/utils/Utils.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/utest/utils/Utils.java
@@ -13,6 +13,7 @@
 package org.apache.juneau.utest.utils;
 
 import java.io.*;
+import java.net.*;
 import java.util.*;
 import java.util.regex.*;
 
@@ -163,4 +164,11 @@ public class Utils extends 
org.apache.juneau.common.internal.Utils {  // NOSONAR
        public static final StringReader reader(String in) {
                return new StringReader(in);
        }
+
+       /**
+        * Constructs a {@link URL} object from a string.
+        */
+       public static URL url(String value) {
+               return safe(()->new URI(value).toURL());
+       }
 }
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/xml/CommonXmlTest.java 
b/juneau-utest/src/test/java/org/apache/juneau/xml/CommonXmlTest.java
index d51f25d6e..ee9dbea93 100755
--- a/juneau-utest/src/test/java/org/apache/juneau/xml/CommonXmlTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/xml/CommonXmlTest.java
@@ -16,6 +16,7 @@ import static org.apache.juneau.utest.utils.Utils.*;
 import static org.apache.juneau.xml.annotation.XmlFormat.*;
 import static org.junit.Assert.*;
 import static org.junit.runners.MethodSorters.*;
+import static org.apache.juneau.utest.utils.Utils.*;
 
 import java.net.*;
 
@@ -53,7 +54,7 @@ public class CommonXmlTest {
                public String name;
                public A() {}
                public A(String url, int id, String name) throws Exception {
-                       this.url = new URL(url);
+                       this.url = url(url);
                        this.id = id;
                        this.name = name;
                }
@@ -76,8 +77,8 @@ public class CommonXmlTest {
                public URL url2;
                public B() {}
                public B(String url) throws Exception {
-                       this.url = new URL(url);
-                       this.url2 = new URL(url+"/2");
+                       this.url = url(url);
+                       this.url2 = url(url+"/2");
                }
        }
 }
\ No newline at end of file
diff --git a/juneau-utest/src/test/java/org/apache/juneau/xml/XmlTest.java 
b/juneau-utest/src/test/java/org/apache/juneau/xml/XmlTest.java
index fcc118022..96c72ded0 100755
--- a/juneau-utest/src/test/java/org/apache/juneau/xml/XmlTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/xml/XmlTest.java
@@ -449,7 +449,7 @@ public class XmlTest {
                public String name;
                public N() {}
                public N(String url, int id, String name) throws Exception {
-                       this.url = new URL(url);
+                       this.url = url(url);
                        this.id = id;
                        this.name = name;
                }
@@ -482,7 +482,7 @@ public class XmlTest {
                public String name;
                public O() {}
                public O(String url, int id, String name) throws Exception {
-                       this.url = new URL(url);
+                       this.url = url(url);
                        this.id = id;
                        this.name = name;
                }
@@ -515,7 +515,7 @@ public class XmlTest {
                public String name;
                public P() {}
                public P(String url, int id, String name) throws Exception {
-                       this.url = new URL(url);
+                       this.url = url(url);
                        this.id = id;
                        this.name = name;
                }
@@ -993,7 +993,7 @@ public class XmlTest {
                String r;
 
                Q t = new Q();
-               t.f1 = new URL("http://xf1";);
+               t.f1 = url("http://xf1";);
                t.f2 = "xf2";
                t.f3 = "xf3";
                r = s.build().serialize(t);
@@ -1028,7 +1028,7 @@ public class XmlTest {
                public String f3;
 
                public Q() throws Exception {
-                       f1 = new URL("http://f1";);
+                       f1 = url("http://f1";);
                        f2 = "f2";
                        f3 = "f3";
                }

Reply via email to