You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/06/01 18:24:58 UTC
(commons-jexl) 13/26: Use assertThrows()
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 60c4372c9aadc904408abffce8969a959d3aae9b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 1 11:41:34 2024 -0400
Use assertThrows()
---
.../apache/commons/jexl3/parser/ParserTest.java | 23 +++++++---------------
1 file changed, 7 insertions(+), 16 deletions(-)
diff --git a/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java b/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java
index 6039351c..c7fda53c 100644
--- a/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java
+++ b/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java
@@ -19,7 +19,7 @@ package org.apache.commons.jexl3.parser;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import org.apache.commons.jexl3.JexlException;
import org.apache.commons.jexl3.JexlFeatures;
@@ -56,27 +56,18 @@ public class ParserTest {
@Test
public void testErrorAmbiguous() throws Exception {
final Parser parser = new Parser(";");
- try {
- final JexlNode sn = parser.parse(null, FEATURES, "x = 1 y = 5", null);
- fail("should have failed on ambiguous statement");
- } catch (final JexlException.Ambiguous xambiguous) {
- // ok
- }
+ assertThrows(JexlException.Ambiguous.class, () -> parser.parse(null, FEATURES, "x = 1 y = 5", null), "should have failed on ambiguous statement");
}
@Test
public void testErrorAssign() throws Exception {
final String[] ops = { "=", "+=", "-=", "/=", "*=", "^=", "&=", "|=" };
- for(final String op : ops) {
+ for (final String op : ops) {
final Parser parser = new Parser(";");
- try {
- final JexlNode sn = parser.parse(null, FEATURES, "foo() "+op+" 1;", null);
- fail("should have failed on invalid assignment " + op);
- } catch (final JexlException.Parsing xparse) {
- // ok
- final String ss = xparse.getDetail();
- final String sss = xparse.toString();
- }
+ JexlException.Parsing xparse = assertThrows(JexlException.Parsing.class, () -> parser.parse(null, FEATURES, "foo() " + op + " 1;", null),
+ () -> "should have failed on invalid assignment " + op);
+ assertNotNull(xparse.getDetail());
+ assertNotNull(xparse.toString());
}
}