This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git

commit fa3adb2bac40ea05e4ed817ce673d7291b9c1a24
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Jun 1 14:12:37 2024 -0400

    Use assertThrows()
---
 .../java/org/apache/commons/jexl3/CacheTest.java   | 34 +++++++++-------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/src/test/java/org/apache/commons/jexl3/CacheTest.java 
b/src/test/java/org/apache/commons/jexl3/CacheTest.java
index c92d3745..fdd1a289 100644
--- a/src/test/java/org/apache/commons/jexl3/CacheTest.java
+++ b/src/test/java/org/apache/commons/jexl3/CacheTest.java
@@ -18,6 +18,7 @@ package org.apache.commons.jexl3;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.fail;
 
 import java.util.ArrayList;
@@ -382,14 +383,9 @@ public class CacheTest extends JexlTestCase {
                 assertEquals(expected, result, compute2::toString);
 
                 if (value instanceof Integer) {
-                    try {
-                        vars.put("a0", Short.valueOf((short) 17));
-                        vars.put("a1", Short.valueOf((short) 19));
-                        result = ambiguous.evaluate(jc);
-                        fail("should have thrown an exception");
-                    } catch (final JexlException xany) {
-                        // throws due to ambiguous exception
-                    }
+                    vars.put("a0", Short.valueOf((short) 17));
+                    vars.put("a1", Short.valueOf((short) 19));
+                    assertThrows(JexlException.class, () -> 
ambiguous.evaluate(jc));
                 }
 
                 if (value instanceof String) {
@@ -404,19 +400,15 @@ public class CacheTest extends JexlTestCase {
                 result = compute1.evaluate(jc);
                 assertEquals(expected, result, compute1::toString);
 
-                try {
-                    vars.put("a0", null);
-                    result = compute1null.evaluate(jc);
-                    fail("should have thrown an exception");
-                } catch (final JexlException xany) {
-                    // throws due to ambiguous exception
-                    final String sany = xany.getMessage();
-                    final String tname = getClass().getName();
-                    if (!sany.startsWith(tname)) {
-                        fail("debug mode should carry caller information, "
-                                + sany + ", "
-                                + tname);
-                    }
+                vars.put("a0", null);
+                final JexlException xany = assertThrows(JexlException.class, 
() -> compute1null.evaluate(jc));
+                // throws due to ambiguous exception
+                final String sany = xany.getMessage();
+                final String tname = getClass().getName();
+                if (!sany.startsWith(tname)) {
+                    fail("debug mode should carry caller information, "
+                            + sany + ", "
+                            + tname);
                 }
             }
             return Integer.valueOf(loops);

Reply via email to