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 791e4b2e944599fc0fd14fdefb1c20103ae1cb80 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sat Jun 1 18:33:20 2024 -0400 Use assertThrows() --- .../java/org/apache/commons/jexl3/LexicalTest.java | 35 ++++++++-------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/test/java/org/apache/commons/jexl3/LexicalTest.java b/src/test/java/org/apache/commons/jexl3/LexicalTest.java index be7659ff..18fb1bcf 100644 --- a/src/test/java/org/apache/commons/jexl3/LexicalTest.java +++ b/src/test/java/org/apache/commons/jexl3/LexicalTest.java @@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -416,26 +417,19 @@ public class LexicalTest { public void testConst1() { final JexlFeatures f = new JexlFeatures(); final JexlEngine jexl = new JexlBuilder().strict(true).create(); - try { - final JexlScript script = jexl.createScript( - "const foo; foo"); - fail("should fail, const foo must be followed by assign."); - } catch (final JexlException.Parsing xparse) { - assertTrue(xparse.getMessage().contains("const")); - } + final JexlException.Parsing xparse = assertThrows(JexlException.Parsing.class, () -> jexl.createScript("const foo; foo"), + "should fail, const foo must be followed by assign."); + assertTrue(xparse.getMessage().contains("const")); + } @Test public void testConst2a() { - final JexlFeatures f = new JexlFeatures(); final JexlEngine jexl = new JexlBuilder().strict(true).create(); - for(final String op : Arrays.asList("=", "+=", "-=", "/=", "*=", "%=", "<<=", ">>=", ">>>=", "^=", "&=", "|=")) { - try { - final JexlScript script = jexl.createScript("const foo = 42; foo "+op+" 1;"); - fail("should fail, const precludes assignment"); - } catch (final JexlException.Parsing xparse) { - assertTrue(xparse.getMessage().contains("foo")); - } + for (final String op : Arrays.asList("=", "+=", "-=", "/=", "*=", "%=", "<<=", ">>=", ">>>=", "^=", "&=", "|=")) { + final JexlException.Parsing xparse = assertThrows(JexlException.Parsing.class, () -> jexl.createScript("const foo = 42; foo " + op + " 1;"), + "should fail, const precludes assignment"); + assertTrue(xparse.getMessage().contains("foo")); } } @@ -443,13 +437,10 @@ public class LexicalTest { public void testConst2b() { final JexlFeatures f = new JexlFeatures(); final JexlEngine jexl = new JexlBuilder().strict(true).create(); - for(final String op : Arrays.asList("=", "+=", "-=", "/=", "*=", "%=", "<<=", ">>=", ">>>=", "^=", "&=", "|=")) { - try { - final JexlScript script = jexl.createScript("const foo = 42; if (true) { foo "+op+" 1; }"); - fail("should fail, const precludes assignment"); - } catch (final JexlException.Parsing xparse) { - assertTrue(xparse.getMessage().contains("foo")); - } + for (final String op : Arrays.asList("=", "+=", "-=", "/=", "*=", "%=", "<<=", ">>=", ">>>=", "^=", "&=", "|=")) { + final JexlException.Parsing xparse = assertThrows(JexlException.Parsing.class, () -> jexl.createScript("const foo = 42; if (true) { foo " + op + " 1; }"), + "should fail, const precludes assignment"); + assertTrue(xparse.getMessage().contains("foo")); } }