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 315f92017 Unit test modernization.
315f92017 is described below

commit 315f92017d696ab96dd3207c5e8194b85b49559b
Author: James Bognar <[email protected]>
AuthorDate: Thu Aug 7 17:14:27 2025 -0400

    Unit test modernization.
---
 .../org/apache/juneau/common/internal/Utils.java   |  4 ++++
 .../java/org/apache/juneau/AssertionHelpers.java   |  7 ++++++
 .../java/org/apache/juneau/ComboRoundTripTest.java |  5 ++--
 .../java/org/apache/juneau/ComboSerializeTest.java |  4 +++-
 .../test/java/org/apache/juneau/MaxIndentTest.java |  5 ++--
 .../java/org/apache/juneau/SimpleTestBase.java     |  7 ++++++
 .../org/apache/juneau/http/part/PartList_Test.java |  1 -
 .../rest/client/RestClient_Response_Body_Test.java |  6 ++---
 .../juneau/serializer/UriResolutionTest.java       |  7 +++---
 .../utils/UriContextResolutionComboTest.java       | 27 +++++++++++-----------
 .../juneau/utils/UriContextUriComboTest.java       | 17 +++++++-------
 11 files changed, 57 insertions(+), 33 deletions(-)

diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
index ae9f552af..9a23c3249 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
@@ -669,6 +669,10 @@ public class Utils {
                        return o2.toInstant().toString();
                if (o instanceof InputStream o2)
                        return toHex(o2);
+               if (o instanceof Reader o2)
+                       return safe(()->IOUtils.read(o2));
+               if (o instanceof File o2)
+                       return safe(()->IOUtils.read(o2));
                if (o instanceof byte[] o2)
                        return toHex(o2);
                if (o != null && o.getClass().isArray()) {
diff --git a/juneau-utest/src/test/java/org/apache/juneau/AssertionHelpers.java 
b/juneau-utest/src/test/java/org/apache/juneau/AssertionHelpers.java
index 1ad70e091..a6303af4f 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/AssertionHelpers.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/AssertionHelpers.java
@@ -91,6 +91,13 @@ public class AssertionHelpers {
                assertEquals(expected, r(actual));
        }
 
+       /**
+        * Asserts an object matches the expected string after it's been made 
readable.
+        */
+       public static void assertString(String expected, Object actual, 
Supplier<String> messageSupplier) {
+               assertEquals(expected, r(actual), messageSupplier);
+       }
+
        /**
         * Asserts an object matches the expected string after it's been made 
readable.
         */
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/ComboRoundTripTest.java 
b/juneau-utest/src/test/java/org/apache/juneau/ComboRoundTripTest.java
index 796f4de49..6b11c6dc6 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/ComboRoundTripTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/ComboRoundTripTest.java
@@ -12,6 +12,7 @@
 // 
***************************************************************************************************************************
 package org.apache.juneau;
 
+import static org.apache.juneau.AssertionHelpers.*;
 import static org.apache.juneau.assertions.AssertionPredicates.*;
 import static org.apache.juneau.assertions.Assertions.*;
 import static org.junit.Assert.*;
@@ -121,7 +122,7 @@ public abstract class ComboRoundTripTest {
                                System.out.println(r);
                        }
 
-                       assertString(r).setMsg("{0}/{1} parse-normal 
failed.\n{msg}", comboInput.label, testName).is(expected);
+                       assertString(expected, r, ss("{0}/{1} parse-normal 
failed.\n{msg}", comboInput.label, testName));
 
                } catch (AssertionError e) {
                        if (comboInput.exceptionMsg == null)
@@ -150,7 +151,7 @@ public abstract class ComboRoundTripTest {
                        o = comboInput.convert(o);
                        r = s.serializeToString(o);
 
-                       assertString(r).setMsg("{0}/{1} parse-normal failed", 
comboInput.label, testName).is(expected);
+                       assertString(expected, r, ss("{0}/{1} parse-normal 
failed", comboInput.label, testName));
 
                } catch (AssertionError e) {
                        if (comboInput.exceptionMsg == null)
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/ComboSerializeTest.java 
b/juneau-utest/src/test/java/org/apache/juneau/ComboSerializeTest.java
index de55e6da6..517ed1b85 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/ComboSerializeTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/ComboSerializeTest.java
@@ -12,8 +12,10 @@
 // 
***************************************************************************************************************************
 package org.apache.juneau;
 
+import static org.apache.juneau.AssertionHelpers.*;
 import static org.apache.juneau.assertions.AssertionPredicates.*;
 import static org.apache.juneau.assertions.Assertions.*;
+import static org.junit.jupiter.api.Assertions.*;
 import static org.junit.runners.MethodSorters.*;
 
 import java.util.*;
@@ -78,7 +80,7 @@ public abstract class ComboSerializeTest {
                                }
                        }
 
-                       assertString(r).setMsg("{0}/{1} parse-normal failed: 
<<<MSG>>>", comboInput.label, testName).is(expected);
+                       assertEquals(expected, r, ss("{0}/{1} parse-normal 
failed: <<<MSG>>>", comboInput.label, testName));
 
                } catch (AssertionError e) {
                        if (comboInput.exceptionMsg == null)
diff --git a/juneau-utest/src/test/java/org/apache/juneau/MaxIndentTest.java 
b/juneau-utest/src/test/java/org/apache/juneau/MaxIndentTest.java
index f51ffcac1..94aa51df6 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/MaxIndentTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/MaxIndentTest.java
@@ -12,7 +12,8 @@
 // 
***************************************************************************************************************************
 package org.apache.juneau;
 
-import static org.apache.juneau.assertions.Assertions.*;
+import static org.apache.juneau.AssertionHelpers.*;
+import static org.junit.jupiter.api.Assertions.*;
 import static org.junit.runners.MethodSorters.*;
 
 import java.util.*;
@@ -303,7 +304,7 @@ public class MaxIndentTest {
                                return;
                        }
 
-                       assertString(r).setMsg("{0}/{1} parse-normal failed", 
input.label, testName).is(expected);
+                       assertEquals(expected, r, ss("{0}/{1} parse-normal 
failed", input.label, testName));
 
                } catch (AssertionError e) {
                        throw e;
diff --git a/juneau-utest/src/test/java/org/apache/juneau/SimpleTestBase.java 
b/juneau-utest/src/test/java/org/apache/juneau/SimpleTestBase.java
index b1b89c15d..2fec1af20 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/SimpleTestBase.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/SimpleTestBase.java
@@ -72,6 +72,13 @@ public abstract class SimpleTestBase {
                AssertionHelpers.assertString(expected, actual);
        }
 
+       /**
+        * Asserts an object matches the expected string after it's been made 
readable.
+        */
+       public static void assertString(String expected, Object actual, 
Supplier<String> messageSupplier) {
+               AssertionHelpers.assertString(expected, actual, 
messageSupplier);
+       }
+
        /**
         * Asserts an object matches the expected string after it's been made 
readable.
         */
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/http/part/PartList_Test.java 
b/juneau-utest/src/test/java/org/apache/juneau/http/part/PartList_Test.java
index 9fead41b3..df829e4a9 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/http/part/PartList_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/http/part/PartList_Test.java
@@ -12,7 +12,6 @@
 // 
***************************************************************************************************************************
 package org.apache.juneau.http.part;
 
-import static org.apache.juneau.assertions.Assertions.*;
 import static org.apache.juneau.common.internal.StringUtils.*;
 import static org.apache.juneau.http.HttpParts.*;
 import static org.apache.juneau.internal.CollectionUtils.*;
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Body_Test.java
 
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Body_Test.java
index a93e06efb..d568c8dd6 100644
--- 
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Body_Test.java
+++ 
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Body_Test.java
@@ -139,15 +139,15 @@ class RestClient_Response_Body_Test extends 
SimpleTestBase {
                TestClient x = testClient();
                x.entity(inputStreamEntity("{f:1}"));
                Reader r = x.get("/bean").run().getContent().asReader();
-               assertReader(r).is("{f:1}");
+               assertString("{f:1}", r);
 
                x.entity(inputStreamEntity("{f:1}"));
                r = x.get("/bean").run().getContent().asReader(UTF8);
-               assertReader(r).is("{f:1}");
+               assertString("{f:1}", r);
 
                x.entity(inputStreamEntity("{f:1}"));
                r = x.get("/bean").run().getContent().asReader(null);
-               assertReader(r).is("{f:1}");
+               assertString("{f:1}", r);
        }
 
        @Test void a05_asBytes() throws Exception {
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/serializer/UriResolutionTest.java
 
b/juneau-utest/src/test/java/org/apache/juneau/serializer/UriResolutionTest.java
index d64e65acb..a34b4855e 100644
--- 
a/juneau-utest/src/test/java/org/apache/juneau/serializer/UriResolutionTest.java
+++ 
b/juneau-utest/src/test/java/org/apache/juneau/serializer/UriResolutionTest.java
@@ -12,7 +12,8 @@
 // 
***************************************************************************************************************************
 package org.apache.juneau.serializer;
 
-import static org.apache.juneau.assertions.Assertions.*;
+import static org.apache.juneau.AssertionHelpers.*;
+import static org.junit.jupiter.api.Assertions.*;
 import static org.junit.runners.MethodSorters.*;
 
 import java.util.*;
@@ -553,7 +554,7 @@ public class UriResolutionTest {
                                System.out.println(r);
                        }
 
-                       assertString(r).setMsg("{0}/{1} serialize-normal 
failed", label, s.getClass().getSimpleName()).is(expected);
+                       assertEquals(expected, r, ss("{0}/{1} serialize-normal 
failed", label, s.getClass().getSimpleName()));
 
                } catch (AssertionError e) {
                        throw e;
@@ -570,7 +571,7 @@ public class UriResolutionTest {
                        TreeMap<String,String> m = p.parse(r, TreeMap.class, 
String.class, String.class);
 
                        String r2 = Json5Serializer.DEFAULT.toString(m);
-                       assertString(results.json).setMsg("{0}/{1} parse 
failed", label, s.getClass().getSimpleName()).is(r2);
+                       assertEquals(r2, results.json, ss("{0}/{1} parse 
failed", label, s.getClass().getSimpleName()));
 
                } catch (AssertionError e) {
                        throw e;
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/utils/UriContextResolutionComboTest.java
 
b/juneau-utest/src/test/java/org/apache/juneau/utils/UriContextResolutionComboTest.java
index 381e62532..8bc8de1cd 100644
--- 
a/juneau-utest/src/test/java/org/apache/juneau/utils/UriContextResolutionComboTest.java
+++ 
b/juneau-utest/src/test/java/org/apache/juneau/utils/UriContextResolutionComboTest.java
@@ -14,7 +14,8 @@ package org.apache.juneau.utils;
 
 import static org.apache.juneau.UriRelativity.*;
 import static org.apache.juneau.UriResolution.*;
-import static org.apache.juneau.assertions.Assertions.*;
+import static org.apache.juneau.AssertionHelpers.*;
+import static org.junit.jupiter.api.Assertions.*;
 import static org.junit.runners.MethodSorters.*;
 
 import java.util.*;
@@ -996,72 +997,72 @@ public class UriContextResolutionComboTest {
        @Test
        public void a01_testAbsoluteResource() {
                String x = UriResolver.of(ABSOLUTE, RESOURCE, 
UriContext.of(in.authority, in.context, in.resource, in.path)).resolve(in.uri);
-               assertString(x).setMsg("{0}: testAbsolute() failed", 
label).is(r.aResource);
+               assertEquals(r.aResource, x, ss("{0}: testAbsolute() failed", 
label));
        }
 
        @Test
        public void a02_testAppendAbsoluteResource() {
                Appendable x = UriResolver.of(ABSOLUTE, RESOURCE, 
UriContext.of(in.authority, in.context, in.resource, in.path)).append(new 
StringBuilder(), in.uri);
-               assertString(x).setMsg("{0}: testAbsolute() failed", 
label).is(r.aResource);
+               assertString(r.aResource, x, ss("{0}: testAbsolute() failed", 
label));
        }
 
        @Test
        public void a03_testAbsolutePathInfo() {
                String x = UriResolver.of(ABSOLUTE, PATH_INFO, 
UriContext.of(in.authority, in.context, in.resource, in.path)).resolve(in.uri);
-               assertString(x).setMsg("{0}: testAbsolute() failed", 
label).is(r.aPathInfo);
+               assertEquals(r.aPathInfo, x, ss("{0}: testAbsolute() failed", 
label));
        }
 
        @Test
        public void a04_testAppendAbsolutePathInfo() {
                Appendable x = UriResolver.of(ABSOLUTE, PATH_INFO, 
UriContext.of(in.authority, in.context, in.resource, in.path)).append(new 
StringBuilder(), in.uri);
-               assertString(x).setMsg("{0}: testAbsolute() failed", 
label).is(r.aPathInfo);
+               assertString(r.aPathInfo, x, ss("{0}: testAbsolute() failed", 
label));
        }
 
        @Test
        public void a05_testRootRelativeResource() {
                String x = UriResolver.of(ROOT_RELATIVE, RESOURCE, 
UriContext.of(in.authority, in.context, in.resource, in.path)).resolve(in.uri);
-               assertString(x).setMsg("{0}: testAbsolute() failed", 
label).is(r.rrResource);
+               assertEquals(r.rrResource, x, ss("{0}: testAbsolute() failed", 
label));
        }
 
        @Test
        public void a06_testAppendRootRelativeResource() {
                Appendable x = UriResolver.of(ROOT_RELATIVE, RESOURCE, 
UriContext.of(in.authority, in.context, in.resource, in.path)).append(new 
StringBuilder(), in.uri);
-               assertString(x).setMsg("{0}: testAbsolute() failed", 
label).is(r.rrResource);
+               assertString(r.rrResource, x, ss("{0}: testAbsolute() failed", 
label));
        }
 
        @Test
        public void a07_testRootRelativePathInfo() {
                String x = UriResolver.of(ROOT_RELATIVE, PATH_INFO, 
UriContext.of(in.authority, in.context, in.resource, in.path)).resolve(in.uri);
-               assertString(x).setMsg("{0}: testAbsolute() failed", 
label).is(r.rrPathInfo);
+               assertEquals(r.rrPathInfo, x, ss("{0}: testAbsolute() failed", 
label));
        }
 
        @Test
        public void a08_testAppendRootRelativePathInfo() {
                Appendable x = UriResolver.of(ROOT_RELATIVE, PATH_INFO, 
UriContext.of(in.authority, in.context, in.resource, in.path)).append(new 
StringBuilder(), in.uri);
-               assertString(x).setMsg("{0}: testAbsolute() failed", 
label).is(r.rrPathInfo);
+               assertString(r.rrPathInfo, x, ss("{0}: testAbsolute() failed", 
label));
        }
 
        @Test
        public void a09_testNoneResource() {
                String x = UriResolver.of(NONE, RESOURCE, 
UriContext.of(in.authority, in.context, in.resource, in.path)).resolve(in.uri);
-               assertString(x).setMsg("{0}: testAbsolute() failed", 
label).is(r.nResource);
+               assertEquals(r.nResource, x, ss("{0}: testAbsolute() failed", 
label));
        }
 
        @Test
        public void a10_testAppendNoneResource() {
                Appendable x = UriResolver.of(NONE, RESOURCE, 
UriContext.of(in.authority, in.context, in.resource, in.path)).append(new 
StringBuilder(), in.uri);
-               assertString(x).setMsg("{0}: testAbsolute() failed", 
label).is(r.nResource);
+               assertString(r.nResource, x, ss("{0}: testAbsolute() failed", 
label));
        }
 
        @Test
        public void a11_testNonePathInfo() {
                String x = UriResolver.of(NONE, PATH_INFO, 
UriContext.of(in.authority, in.context, in.resource, in.path)).resolve(in.uri);
-               assertString(x).setMsg("{0}: testAbsolute() failed", 
label).is(r.nPathInfo);
+               assertEquals(r.nPathInfo, x, ss("{0}: testAbsolute() failed", 
label));
        }
 
        @Test
        public void a12_testAppendNonePathInfo() {
                Appendable x = UriResolver.of(NONE, PATH_INFO, 
UriContext.of(in.authority, in.context, in.resource, in.path)).append(new 
StringBuilder(), in.uri);
-               assertString(x).setMsg("{0}: testAbsolute() failed", 
label).is(r.nPathInfo);
+               assertString(r.nPathInfo, x, ss("{0}: testAbsolute() failed", 
label));
        }
 }
\ No newline at end of file
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/utils/UriContextUriComboTest.java
 
b/juneau-utest/src/test/java/org/apache/juneau/utils/UriContextUriComboTest.java
index 9ac829901..0edd92525 100644
--- 
a/juneau-utest/src/test/java/org/apache/juneau/utils/UriContextUriComboTest.java
+++ 
b/juneau-utest/src/test/java/org/apache/juneau/utils/UriContextUriComboTest.java
@@ -12,7 +12,8 @@
 // 
***************************************************************************************************************************
 package org.apache.juneau.utils;
 
-import static org.apache.juneau.assertions.Assertions.*;
+import static org.apache.juneau.AssertionHelpers.*;
+import static org.junit.jupiter.api.Assertions.*;
 import static org.junit.runners.MethodSorters.*;
 
 import java.util.*;
@@ -231,36 +232,36 @@ public class UriContextUriComboTest {
 
        @Test
        public void a1_testAbsoluteAuthority() {
-               assertString(in.uriContext.getAbsoluteAuthority()).setMsg("{0}: 
testAbsoluteAuthority() failed", label).is(r.eAbsoluteAuthority);
+               assertEquals(r.eAbsoluteAuthority, 
in.uriContext.getAbsoluteAuthority(), ss("{0}: testAbsoluteAuthority() failed", 
label));
        }
 
        @Test
        public void a2_testAbsoluteContext() {
-               
assertString(in.uriContext.getAbsoluteContextRoot()).setMsg("{0}: 
testAbsoluteContext() failed", label).is(r.eAbsoluteContext);
+               assertEquals(r.eAbsoluteContext, 
in.uriContext.getAbsoluteContextRoot(), ss("{0}: testAbsoluteContext() failed", 
label));
        }
 
        @Test
        public void a3_testAbsoluteResource() {
-               
assertString(in.uriContext.getAbsoluteServletPath()).setMsg("{0}: 
testAbsoluteResource() failed", label).is(r.eAbsoluteResource);
+               assertEquals(r.eAbsoluteResource, 
in.uriContext.getAbsoluteServletPath(), ss("{0}: testAbsoluteResource() 
failed", label));
        }
 
        @Test
        public void a4_testAbsolutePath() {
-               assertString(in.uriContext.getAbsolutePathInfo()).setMsg("{0}: 
testAbsolutePath() failed", label).is(r.eAbsolutePath);
+               assertEquals(r.eAbsolutePath, 
in.uriContext.getAbsolutePathInfo(), ss("{0}: testAbsolutePath() failed", 
label));
        }
 
        @Test
        public void a5_testRootRelativeContext() {
-               
assertString(in.uriContext.getRootRelativeContextRoot()).setMsg("{0}: 
testRootRelativeContext() failed", label).is(r.eRootRelativeContext);
+               assertEquals(r.eRootRelativeContext, 
in.uriContext.getRootRelativeContextRoot(), ss("{0}: testRootRelativeContext() 
failed", label));
        }
 
        @Test
        public void a6_testRootRelativeResource() {
-               
assertString(in.uriContext.getRootRelativeServletPath()).setMsg("{0}: 
testRootRelativeResource() failed", label).is(r.eRootRelativeResource);
+               assertEquals(r.eRootRelativeResource, 
in.uriContext.getRootRelativeServletPath(), ss("{0}: testRootRelativeResource() 
failed", label));
        }
 
        @Test
        public void a7_testRootRelativePath() {
-               
assertString(in.uriContext.getRootRelativePathInfo()).setMsg("{0}: 
testRootRelativePath() failed", label).is(r.eRootRelativePath);
+               assertEquals(r.eRootRelativePath, 
in.uriContext.getRootRelativePathInfo(), ss("{0}: testRootRelativePath() 
failed", label));
        }
 }
\ No newline at end of file

Reply via email to