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 fb32d155e2efddf15cdab6c447ae62b7c34f1534
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sat Jun 1 19:02:36 2024 -0400

    Use assertThrows()
---
 .../java/org/apache/commons/jexl3/MethodTest.java  | 25 ++++++----------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/src/test/java/org/apache/commons/jexl3/MethodTest.java 
b/src/test/java/org/apache/commons/jexl3/MethodTest.java
index 1cdde0cd..d4f2b2b7 100644
--- a/src/test/java/org/apache/commons/jexl3/MethodTest.java
+++ b/src/test/java/org/apache/commons/jexl3/MethodTest.java
@@ -684,12 +684,8 @@ public class MethodTest extends JexlTestCase {
         assertEquals("foo + 42", result);
         // tryInvoke fails
         func.setKill(true);
-        try {
-            /*result = */method.tryInvoke("over", func, "foo", 42);
-            fail("should throw TryFailed");
-        } catch (final JexlException.TryFailed xfail) {
-            assertEquals(UnsupportedOperationException.class, 
xfail.getCause().getClass());
-        }
+        JexlException.TryFailed xfail = 
assertThrows(JexlException.TryFailed.class, () -> method.tryInvoke("over", 
func, "foo", 42));
+        assertEquals(UnsupportedOperationException.class, 
xfail.getCause().getClass());
 
         func.setKill(false);
         final JexlPropertySet setter = uber.getPropertySet(func, "under", 
"42");
@@ -703,23 +699,16 @@ public class MethodTest extends JexlTestCase {
         assertEquals("42", result);
 
         func.setKill(true);
-        try {
-            /*result = */setter.tryInvoke(func, "under", "42");
-            fail("should throw TryFailed");
-        } catch (final JexlException.TryFailed xfail) {
-            assertEquals(UnsupportedOperationException.class, 
xfail.getCause().getClass());
-        }
+        xfail = assertThrows(JexlException.TryFailed.class, () -> 
setter.tryInvoke(func, "under", "42"), "should throw TryFailed");
+        assertEquals(UnsupportedOperationException.class, 
xfail.getCause().getClass());
+
         func.setKill(false);
         result = setter.tryInvoke(func, "under", "-42");
         assertEquals("-42", result);
 
         func.setKill(true);
-        try {
-            /*result = */getter.tryInvoke(func, "under");
-            fail("should throw TryFailed");
-        } catch (final JexlException.TryFailed xfail) {
-            assertEquals(UnsupportedOperationException.class, 
xfail.getCause().getClass());
-        }
+        xfail = assertThrows(JexlException.TryFailed.class, () -> 
getter.tryInvoke(func, "under"), "should throw TryFailed");
+        assertEquals(UnsupportedOperationException.class, 
xfail.getCause().getClass());
 
         func.setKill(false);
         result = getter.tryInvoke(func, "under");

Reply via email to