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 20:04:27 UTC

(commons-jexl) branch master updated (3cec854f -> e937696a)

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

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


    from 3cec854f Use assertThrows()
     new 525c8b02 Use assertThrows()
     new e9170704 Use assertThrows()
     new a3df5480 Use assertThrows()
     new ae3a880a Use assertThrows()
     new 2ebc5993 Use assertThrows()
     new 77c73fb7 Use assertThrows()
     new 54fed69a Use assertThrows()
     new c24fd28f Use assertThrows()
     new e937696a Normalize format

The 9 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/commons/jexl3/Issues300Test.java    | 293 ++++++++++-----------
 1 file changed, 143 insertions(+), 150 deletions(-)


(commons-jexl) 04/09: Use assertThrows()

Posted by gg...@apache.org.
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 ae3a880ad89f9c9a0362370e8a26020258184fdd
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 1 15:56:03 2024 -0400

    Use assertThrows()
---
 .../org/apache/commons/jexl3/Issues300Test.java     | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/test/java/org/apache/commons/jexl3/Issues300Test.java b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
index 55a862c7..68b58699 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues300Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
@@ -958,31 +958,30 @@ public class Issues300Test {
     @Test
     public void test384b() {
         // be explicit about + handling null
+        // @formatter:off
         final JexlEngine jexl = new JexlBuilder()
                 .arithmetic(new Arithmetic384(true))
                 .safe(false)
                 .strict(true)
                 .create();
+        // @formatter:on
         // constant
-        for(final String src0 : Arrays.asList("'ABC' + null", "null + 'ABC'")) {
+        for (final String src0 : Arrays.asList("'ABC' + null", "null + 'ABC'")) {
             final JexlContext ctxt = new MapContext();
             final JexlScript s0 = jexl.createScript(src0);
             assertEquals("ABC", s0.execute(ctxt));
         }
         // null local a
-        for(final String src1 : Arrays.asList("'ABC' + a", "a + 'ABC'")) {
+        for (final String src1 : Arrays.asList("'ABC' + a", "a + 'ABC'")) {
             final JexlContext ctxt = new MapContext();
-            JexlScript s1 = jexl.createScript(src1, "a");
+            final JexlScript s1 = jexl.createScript(src1, "a");
             assertEquals("ABC", s1.execute(ctxt, (Object) null));
             // undefined a
-            s1 = jexl.createScript(src1);
-            try {
-                s1.execute(ctxt, (Object) null);
-                fail("null argument should throw");
-            } catch (final JexlException.Variable xvar) {
-                assertEquals("a", xvar.getVariable());
-                assertTrue(xvar.isUndefined());
-            }
+            final JexlScript s2 = jexl.createScript(src1);
+            final JexlException.Variable xvar = assertThrows(JexlException.Variable.class, () -> s2.execute(ctxt, (Object) null), "null argument should throw");
+            assertEquals("a", xvar.getVariable());
+            assertTrue(xvar.isUndefined());
+
             // null a
             ctxt.set("a", null);
             assertEquals("ABC", s1.execute(ctxt, (Object) null));


(commons-jexl) 06/09: Use assertThrows()

Posted by gg...@apache.org.
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 77c73fb7462c09a6c6a5880ba65f98d252f64971
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 1 15:58:50 2024 -0400

    Use assertThrows()
---
 src/test/java/org/apache/commons/jexl3/Issues300Test.java | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/test/java/org/apache/commons/jexl3/Issues300Test.java b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
index 3e94c655..2c704aab 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues300Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
@@ -1044,6 +1044,7 @@ public class Issues300Test {
 
     @Test
     public void test393() {
+        // @formatter:off
         final String src = "const total = 0;\n" +
                 "if (true) {\n" +
                 "  total = 1;\n" +
@@ -1053,12 +1054,9 @@ public class Issues300Test {
                 .safe(false)
                 .strict(true)
                 .create();
-        try {
-            final JexlScript script = jexl.createScript(src);
-            fail("should fail on const total assignment");
-        } catch (final JexlException.Parsing xparse) {
-            assertTrue(xparse.getMessage().contains("total"));
-        }
+        // @formatter:on
+        final JexlException.Parsing xparse = assertThrows(JexlException.Parsing.class, () -> jexl.createScript(src), "should fail on const total assignment");
+        assertTrue(xparse.getMessage().contains("total"));
     }
 
     @Test


(commons-jexl) 01/09: Use assertThrows()

Posted by gg...@apache.org.
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 525c8b02ea113e14908af13187a12225f5e87f0d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 1 15:45:01 2024 -0400

    Use assertThrows()
---
 .../java/org/apache/commons/jexl3/Issues300Test.java    | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/src/test/java/org/apache/commons/jexl3/Issues300Test.java b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
index 812a52db..2baed53c 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues300Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
@@ -846,13 +846,8 @@ public class Issues300Test {
         final String src = "var i = ++1";
         final JexlEngine jexl = new JexlBuilder().safe(true).create();
         final JexlInfo info = new JexlInfo("badscript", 0, 0);
-        try {
-            final JexlScript script = jexl.createScript(info, src);
-            fail("should not parse");
-        } catch (final JexlException.Parsing xparse) {
-            final String msg = xparse.getMessage();
-            assertTrue(msg.contains("badscript"));
-        }
+        final JexlException.Parsing xparse = assertThrows(JexlException.Parsing.class, () -> jexl.createScript(info, src), "should not parse");
+        assertTrue(xparse.getMessage().contains("badscript"));
     }
 
     @Test
@@ -865,13 +860,7 @@ public class Issues300Test {
         myObject.setName("John");
         final JexlContext context = new ObjectContext<>(engine, myObject);
         // Expect an exception because nested is null, so we are doing null.name
-        try {
-            final Object result = expr.evaluate(context);
-            fail("An exception expected, but got: " + result);
-        } catch (final JexlException ex) {
-            // Expected
-            //ex.printStackTrace();
-        }
+        assertThrows(JexlException.class, () -> expr.evaluate(context));
     }
 
     @Test


(commons-jexl) 05/09: Use assertThrows()

Posted by gg...@apache.org.
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 2ebc59939999e591a171f3ed37f8ce1e4569b4f7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 1 15:57:51 2024 -0400

    Use assertThrows()
---
 .../java/org/apache/commons/jexl3/Issues300Test.java   | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/test/java/org/apache/commons/jexl3/Issues300Test.java b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
index 68b58699..3e94c655 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues300Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
@@ -1024,22 +1024,20 @@ public class Issues300Test {
 
     @Test
     public void test390() throws Exception {
+        // @formatter:off
         final JexlEngine jexl = new JexlBuilder()
                 .safe(false)
                 .strict(true)
                 .debug(true)
                 .create();
+        // @formatter:on
         JexlScript script = null;
-        String src;
-        src = "if (true) #pragma one 42";
-        try {
-            script = jexl.createScript(src);
-            fail("should have failed parsing");
-        } catch (final JexlException.Parsing xparse) {
-            assertTrue(xparse.getDetail().contains("pragma"));
-        }
-        src = "if (true) { #pragma one 42 }";
-        script = jexl.createScript(src);
+        final String src = "if (true) #pragma one 42";
+        final JexlException.Parsing xparse = assertThrows(JexlException.Parsing.class, () -> jexl.createScript(src), "should have failed parsing");
+        assertTrue(xparse.getDetail().contains("pragma"));
+
+        String src1 = "if (true) { #pragma one 42 }";
+        script = jexl.createScript(src1);
         final Object result = script.execute(null);
         debuggerCheck(jexl);
     }


(commons-jexl) 08/09: Use assertThrows()

Posted by gg...@apache.org.
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 c24fd28fcc4b4b67de4ccac1188a1b97501dd8fc
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 1 16:01:37 2024 -0400

    Use assertThrows()
---
 src/test/java/org/apache/commons/jexl3/Issues300Test.java | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/src/test/java/org/apache/commons/jexl3/Issues300Test.java b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
index 6dfeee4d..4b29aca8 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues300Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
@@ -1036,7 +1036,7 @@ public class Issues300Test {
         final JexlException.Parsing xparse = assertThrows(JexlException.Parsing.class, () -> jexl.createScript(src), "should have failed parsing");
         assertTrue(xparse.getDetail().contains("pragma"));
 
-        String src1 = "if (true) { #pragma one 42 }";
+        final String src1 = "if (true) { #pragma one 42 }";
         script = jexl.createScript(src1);
         final Object result = script.execute(null);
         debuggerCheck(jexl);
@@ -1270,6 +1270,7 @@ public class Issues300Test {
     @Test
     public void testUnsolvableMethod() throws Exception {
         final JexlEngine jexl = new JexlBuilder().create();
+        // @formatter:off
         final JexlScript script = jexl.createScript(
             "var myFunction1 = function(object) {"
                 + " myNonExistentFunction();"
@@ -1278,11 +1279,8 @@ public class Issues300Test {
                 + " myFunction1();"
                 + "}"
                 + "myFunction2();");
-        try {
-            script.execute(new MapContext());
-            fail("myNonExistentFunction() is not solvable");
-        } catch (final JexlException.Method unsolvable) {
-            assertEquals("myNonExistentFunction", unsolvable.getMethod());
-        }
+        // @formatter:on
+        final JexlException.Method unsolvable = assertThrows(JexlException.Method.class, () -> script.execute(new MapContext()));
+        assertEquals("myNonExistentFunction", unsolvable.getMethod());
     }
 }


(commons-jexl) 09/09: Normalize format

Posted by gg...@apache.org.
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 e937696a4bcb3e477e0bb110650954dfadfb0863
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 1 16:04:13 2024 -0400

    Normalize format
---
 .../org/apache/commons/jexl3/Issues300Test.java    | 119 ++++++++++++++-------
 1 file changed, 78 insertions(+), 41 deletions(-)

diff --git a/src/test/java/org/apache/commons/jexl3/Issues300Test.java b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
index 4b29aca8..4019324f 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues300Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
@@ -57,12 +57,13 @@ public class Issues300Test {
         public Arithmetic383(final boolean astrict) {
             super(astrict);
         }
+
         @Override
         public boolean isStrict(final JexlOperator op) {
-            switch(op) {
-                case NOT:
-                case CONDITION:
-                    return false;
+            switch (op) {
+            case NOT:
+            case CONDITION:
+                return false;
             }
             return super.isStrict(op);
         }
@@ -84,17 +85,21 @@ public class Issues300Test {
 
     public static class Arithmetic384c extends JexlArithmetic {
         AtomicInteger cmp = new AtomicInteger();
+
         public Arithmetic384c(final boolean astrict) {
             super(astrict);
         }
+
         public Arithmetic384c(final boolean astrict, final MathContext bigdContext, final int bigdScale) {
             super(astrict, bigdContext, bigdScale);
         }
+
         @Override
         protected int compare(final Object l, final Object r, final String op) {
             cmp.incrementAndGet();
             return super.compare(l, r, op);
         }
+
         int getCmpCalls() {
             return cmp.get();
         }
@@ -104,13 +109,15 @@ public class Issues300Test {
         public Arithmetic384d(final boolean astrict) {
             super(astrict);
         }
+
         public Arithmetic384d(final boolean astrict, final MathContext bigdContext, final int bigdScale) {
             super(astrict, bigdContext, bigdScale);
         }
     }
 
     private static class Class397 implements Interface397i {
-        @Override public String summary() {
+        @Override
+        public String summary() {
             return getClass().getName();
         }
     }
@@ -118,6 +125,7 @@ public class Issues300Test {
     public static class Context0930 extends MapContext {
         /**
          * This allows using a JEXL lambda as a filter.
+         *
          * @param stream the stream
          * @param filter the lambda to use as filter
          * @return the filtered stream
@@ -132,9 +140,11 @@ public class Issues300Test {
      */
     public static class Driver0930 {
         private final String name;
+
         Driver0930(final String n) {
             name = n;
         }
+
         public String getAttributeName() {
             return name;
         }
@@ -153,23 +163,26 @@ public class Issues300Test {
     public static class TestObject374 {
         private String name;
         private TestObject374 nested;
+
         public String getName() {
             return name;
         }
+
         public TestObject374 getNested() {
             return nested;
         }
+
         public void setName(final String pName) {
             this.name = pName;
         }
+
         public void setNested(final TestObject374 pNested) {
             nested = pNested;
         }
     }
 
     public enum Type375 {
-        DELIVERY_ADDRESS,
-        DOMICILE
+        DELIVERY_ADDRESS, DOMICILE
     }
 
     public static class User322 {
@@ -194,9 +207,11 @@ public class Issues300Test {
 
     public static class Var370 {
         private String name;
+
         public String getName() {
             return name;
         }
+
         public void setName(final String s) {
             name = s;
         }
@@ -204,15 +219,13 @@ public class Issues300Test {
 
     static JexlContext pragmaticContext() {
         final JexlOptions opts = new JexlOptions();
-        opts.setFlags( "-strict", "-cancellable", "-lexical", "-lexicalShade", "+safe", "+sharedInstance");
+        opts.setFlags("-strict", "-cancellable", "-lexical", "-lexicalShade", "+safe", "+sharedInstance");
         return new JexlTestCase.PragmaticContext(opts);
     }
 
     <T> T createProxy(final JexlEngine jexl, final Object o, final Class[] clazzz) {
         // a JEX-based delegating proxy
-        return (T) Proxy.newProxyInstance(getClass().getClassLoader(), clazzz,
-            (proxy, method, args) ->  jexl.invokeMethod(o, method.getName(), args)
-        );
+        return (T) Proxy.newProxyInstance(getClass().getClassLoader(), clazzz, (proxy, method, args) -> jexl.invokeMethod(o, method.getName(), args));
     }
 
     private Object run361a(final JexlEngine jexl) {
@@ -224,13 +237,15 @@ public class Issues300Test {
     }
 
     private Object run361b(final JexlEngine jexl) {
+        // @formatter:off
         final String src = "()-> { ()-> {" +
                 "var voa = vaf.value;\n" +
                 "if (voa != NaN && voa <= 0)" +
                 "{ return 'foo'; } else { return 'bar'; }" +
                 "} }";
+        // @formatter:on
         final JexlContext context = new MapContext();
-        final Map<String,Object> vaf = Collections.singletonMap("value", null);
+        final Map<String, Object> vaf = Collections.singletonMap("value", null);
         context.set("vaf", vaf);
         final JexlScript script = jexl.createScript(src);
         final Object result = script.execute(null);
@@ -239,15 +254,17 @@ public class Issues300Test {
     }
 
     private String run361c(final JexlEngine jexl) {
+        // @formatter:off
         final String src = "$$var t = null;\n" +
                 "$$if (t < 0) {\n" +
                 "'foo'\n" +
                 "$$} else {\n" +
                 "'bar'\n" +
                 "$$}";
+        // @formatter:on
         final JxltEngine jxlt = jexl.createJxltEngine();
         final JexlContext context = new MapContext();
-        final Map<String,Object> vaf = Collections.singletonMap("value", null);
+        final Map<String, Object> vaf = Collections.singletonMap("value", null);
         context.set("vaf", vaf);
         final JxltEngine.Template template = jxlt.createTemplate(src);
         final StringWriter strw = new StringWriter();
@@ -264,9 +281,7 @@ public class Issues300Test {
     @Test
     public void test301a() {
         final JexlEngine jexl = new JexlBuilder().safe(false).arithmetic(new JexlArithmetic(false)).create();
-        final String[] srcs = {
-                "var x = null; x.0", "var x = null; x[0]", "var x = [null,1]; x[0][0]"
-        };
+        final String[] srcs = { "var x = null; x.0", "var x = null; x[0]", "var x = [null,1]; x[0][0]" };
         for (int i = 0; i < srcs.length; ++i) {
             final String src = srcs[i];
             final JexlScript s = jexl.createScript(src);
@@ -284,12 +299,14 @@ public class Issues300Test {
     @Test
     public void test302() {
         final JexlContext jc = new MapContext();
+        // @formatter:off
         final String[] strs = {
                 "{if (0) 1 else 2; var x = 4;}",
                 "if (0) 1; else 2; ",
                 "{ if (0) 1; else 2; }",
                 "{ if (0) { if (false) 1 else -3 } else 2; }"
         };
+        // @formatter:on
         final JexlEngine jexl = new JexlBuilder().create();
         for (final String str : strs) {
             final JexlScript e = jexl.createScript(str);
@@ -320,14 +337,15 @@ public class Issues300Test {
         value = e304.evaluate(context);
         assertEquals(42, value);
 
+        // @formatter:off
         final String[]  keywords = {
                 "if", "else", "do", "while", "for", "break", "continue", "function", "return", "new", "size", "empty",
                 "var", "let", "const",
                 "null", "true", "false",
                 "not", "div", "mod", "and", "or",
                 "eq", "ne", "lt", "gt", "ge", "le",
-
         };
+        // @formatter:on
         for (final String keyword : keywords) {
             final String pkw = "e304." + keyword;
             map.put(pkw, 42);
@@ -335,7 +353,7 @@ public class Issues300Test {
             value = e304.evaluate(context);
             assertEquals(42, value);
         }
-        for(int i = 0; i < keywords.length; ++i) {
+        for (int i = 0; i < keywords.length; ++i) {
             final String pkw = "e304." + keywords[i] + "." + keywords[keywords.length - 1 - i];
             map.put(pkw, 42);
             e304 = jexlEngine.createExpression(pkw);
@@ -545,9 +563,11 @@ public class Issues300Test {
         JexlScript script;
         Object result;
         JexlInfo info = new JexlInfo("test317", 1, 1);
+        // @formatter:off
         script = jexl.createScript(info, "var f = "
                         + "()-> {x + x }; f",
                 "x");
+        // @formatter:on
         result = script.execute(ctxt, 21);
         assertTrue(result instanceof JexlScript);
         script = (JexlScript) result;
@@ -750,7 +770,8 @@ public class Issues300Test {
         assertFalse((Boolean) result);
     }
 
-    @Test public void test349() {
+    @Test
+    public void test349() {
         final String text = "(A ? C.D : E)";
         final JexlEngine jexl = new JexlBuilder().safe(true).create();
         final JexlExpression expr = jexl.createExpression(text);
@@ -766,7 +787,7 @@ public class Issues300Test {
     @Test
     public void test361a_32() {
         final JexlEngine jexl = new Engine32(new JexlBuilder().safe(false));
-        final Object result  = run361a(jexl);
+        final Object result = run361a(jexl);
         assertNotNull(result);
     }
 
@@ -799,7 +820,7 @@ public class Issues300Test {
     @Test
     public void test361d_32() {
         final JexlEngine jexl = new Engine32(new JexlBuilder().lexical(false).lexicalShade(false).safe(false));
-        final Object result  = run361d(jexl);
+        final Object result = run361d(jexl);
         assertNotNull(result);
     }
 
@@ -809,7 +830,8 @@ public class Issues300Test {
         assertThrows(JexlException.class, () -> run361d(jexl), "null arg should fail");
     }
 
-    @Test public void test367() {
+    @Test
+    public void test367() {
         final String text = "var toto; function foo(x) { x }; var tata = 3; foo(3)";
         final JexlEngine jexl = new JexlBuilder().safe(true).create();
         final JexlScript script = jexl.createScript(text);
@@ -890,9 +912,11 @@ public class Issues300Test {
 
     @Test
     public void test379a() {
+        // @formatter:off
         final String src =
                 "#pragma jexl.import java.util\n"+
                         "const map = new LinkedHashMap({0 : 'zero'});";
+        // @formatter:on
         final JexlEngine jexl = new JexlBuilder().safe(true).create();
         final JexlScript script = jexl.createScript(src);
         assertNotNull(script);
@@ -955,6 +979,7 @@ public class Issues300Test {
             assertFalse(xvar.isUndefined());
         }
     }
+
     @Test
     public void test384b() {
         // be explicit about + handling null
@@ -991,11 +1016,13 @@ public class Issues300Test {
     @Test
     public void test384c() {
         final Arithmetic384c ja = new Arithmetic384c(true);
+        // @formatter:off
         final JexlEngine jexl = new JexlBuilder()
                 .safe(false)
                 .strict(true)
                 .arithmetic(ja)
                 .create();
+        // @formatter:on
         assertTrue(ja.toBoolean(jexl.createExpression("3 < 4").evaluate(null)));
         assertTrue(ja.toBoolean(jexl.createExpression("6 <= 8").evaluate(null)));
         assertFalse(ja.toBoolean(jexl.createExpression("6 == 7").evaluate(null)));
@@ -1008,11 +1035,13 @@ public class Issues300Test {
     @Test
     public void test384d() {
         final Arithmetic384c ja = new Arithmetic384d(true);
+        // @formatter:off
         final JexlEngine jexl = new JexlBuilder()
                 .safe(false)
                 .strict(true)
                 .arithmetic(ja)
                 .create();
+        // @formatter:on
         assertTrue(ja.toBoolean(jexl.createExpression("3 < 4").evaluate(null)));
         assertTrue(ja.toBoolean(jexl.createExpression("6 <= 8").evaluate(null)));
         assertFalse(ja.toBoolean(jexl.createExpression("6 == 7").evaluate(null)));
@@ -1076,7 +1105,8 @@ public class Issues300Test {
         assertEquals("'\\b\\t\\f'", parsed);
     }
 
-    @Test public void testDow() {
+    @Test
+    public void testDow() {
         // @formatter:off
         final String src = "(y, m, d)->{\n" +
                 "// will return 0 for Sunday, 6 for Saturday\n" +
@@ -1097,7 +1127,8 @@ public class Issues300Test {
         assertEquals(0, dow.intValue());
     }
 
-    @Test public void testIssue394() {
+    @Test
+    public void testIssue394() {
         final StringBuilder x = new StringBuilder("foobar");
         assertEquals("foobar", x.toString());
         final String src = "x -> x.setLength(3)";
@@ -1107,7 +1138,8 @@ public class Issues300Test {
         assertEquals("foo", x.toString());
     }
 
-    @Test public void testIssue397() {
+    @Test
+    public void testIssue397() {
         String result;
         final String control = Class397.class.getName();
         final JexlEngine jexl = new JexlBuilder().permissions(RESTRICTED).create();
@@ -1116,7 +1148,7 @@ public class Issues300Test {
         result = (String) jexl.invokeMethod(instance, "summary");
         assertEquals(control, result);
 
-        final Interface397i proxy = createProxy(jexl, instance, new Class[] { Interface397i.class }) ;
+        final Interface397i proxy = createProxy(jexl, instance, new Class[] { Interface397i.class });
         result = (String) jexl.invokeMethod(proxy, "summary");
         assertEquals(control, result);
 
@@ -1129,34 +1161,38 @@ public class Issues300Test {
 
     @Test
     public void testIssue398a() {
+        // @formatter:off
         final String src = "let m = {\n" +
             "  \"foo\": 1,\n" +
             "  \"bar\": 2,\n" +
             "}";
+        // @formatter:on
         final JexlEngine jexl = new JexlBuilder().create();
         final JexlScript script = jexl.createScript(src);
         final Object result = script.execute(null);
         assertTrue(result instanceof Map);
-        final Map<?,?> map = (Map<?, ?>) result;
+        final Map<?, ?> map = (Map<?, ?>) result;
         assertEquals(2, map.size());
     }
 
     @Test
     public void testIssue398b() {
-        final Map<String,Object> foo = Collections.singletonMap("X", "x");
-        final Map<String,Object> bar = Collections.singletonMap("Y", "y");
+        final Map<String, Object> foo = Collections.singletonMap("X", "x");
+        final Map<String, Object> bar = Collections.singletonMap("Y", "y");
         final JexlContext ctxt = new MapContext();
         ctxt.set("foo", foo);
         ctxt.set("bar", bar);
+        // @formatter:off
         final String src = "let m = {\n" +
                 "  foo.X: 1,\n" +
                 "  bar.Y: 2,\n" +
                 "}";
+        // @formatter:on
         final JexlEngine jexl = new JexlBuilder().create();
         JexlScript script = jexl.createScript(src);
         Object result = script.execute(ctxt);
         assertTrue(result instanceof Map);
-        Map<?,?> map = (Map<?, ?>) result;
+        Map<?, ?> map = (Map<?, ?>) result;
         assertEquals(2, map.size());
         assertEquals(1, map.get("x"));
         assertEquals(2, map.get("y"));
@@ -1179,19 +1215,21 @@ public class Issues300Test {
         assertTrue(jexl.createScript("[1,...]").execute(null) instanceof ArrayList<?>);
         assertTrue(jexl.createScript("{1}").execute(null) instanceof HashSet<?>);
         assertTrue(jexl.createScript("{1,...}").execute(null) instanceof LinkedHashSet<?>);
-        assertTrue(jexl.createScript("{'one': 1}").execute(null) instanceof HashMap<?,?>);
-        assertTrue(jexl.createScript("{'one': 1,...}").execute(null) instanceof LinkedHashMap<?,?>);
+        assertTrue(jexl.createScript("{'one': 1}").execute(null) instanceof HashMap<?, ?>);
+        assertTrue(jexl.createScript("{'one': 1,...}").execute(null) instanceof LinkedHashMap<?, ?>);
     }
 
-    @Test public void testPropagateOptions() {
+    @Test
+    public void testPropagateOptions() {
+        // @formatter:off
         final String src0 = "`${$options.strict?'+':'-'}strict"
                 + " ${$options.cancellable?'+':'-'}cancellable"
                 + " ${$options.lexical?'+':'-'}lexical"
                 + " ${$options.lexicalShade?'+':'-'}lexicalShade"
                 + " ${$options.sharedInstance?'+':'-'}sharedInstance"
                 + " ${$options.safe?'+':'-'}safe`";
-        final String text = "#pragma script.mode pro50\n" +
-                "()->{ ()->{ "+src0+"; } }";
+        // @formatter:on
+        final String text = "#pragma script.mode pro50\n" + "()->{ ()->{ " + src0 + "; } }";
         final JexlEngine jexl = new JexlBuilder().safe(true).create();
         final JexlScript script = jexl.createScript(text);
         JexlContext context = pragmaticContext();
@@ -1200,14 +1238,13 @@ public class Issues300Test {
         final Object result = closure.execute(opts);
         assertEquals("+strict +cancellable +lexical +lexicalShade -sharedInstance -safe", result);
 
-        final String text0 = "#pragma script.mode pro50\n" +
-                "()->{ "+src0+"; }";
+        final String text0 = "#pragma script.mode pro50\n" + "()->{ " + src0 + "; }";
         final JexlScript script0 = jexl.createScript(text0);
         context = pragmaticContext();
         final Object result0 = script0.execute(context);
         assertEquals("+strict +cancellable +lexical +lexicalShade -sharedInstance -safe", result0);
 
-        final String text1 = "#pragma script.mode pro50\n"+src0;
+        final String text1 = "#pragma script.mode pro50\n" + src0;
         final JexlScript script1 = jexl.createScript(text1);
         context = pragmaticContext();
         final Object result1 = script1.execute(context);
@@ -1238,10 +1275,10 @@ public class Issues300Test {
     public void testSO20220930() {
         // fill some drivers in a list
         final List<Driver0930> values = new ArrayList<>();
-        for(int i = 0; i < 8; ++i) {
+        for (int i = 0; i < 8; ++i) {
             values.add(new Driver0930("drvr" + Integer.toOctalString(i)));
         }
-        for(int i = 0; i < 4; ++i) {
+        for (int i = 0; i < 4; ++i) {
             values.add(new Driver0930("favorite" + Integer.toOctalString(i)));
         }
         // Use a context that can filter and that exposes Collectors
@@ -1252,7 +1289,7 @@ public class Issues300Test {
         // The script with a JEXL 3.2 (lambda function) and 3.3 syntax (lambda expression)
         final String src32 = "values.stream().filter((driver) ->{ driver.attributeName =^ 'favorite' }).collect(Collectors.toList())";
         final String src33 = "values.stream().filter(driver -> driver.attributeName =^ 'favorite').collect(Collectors.toList())";
-        for(final String src : Arrays.asList(src32, src33)) {
+        for (final String src : Arrays.asList(src32, src33)) {
             final JexlExpression s = jexl.createExpression(src);
             assertNotNull(s);
 


(commons-jexl) 03/09: Use assertThrows()

Posted by gg...@apache.org.
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 a3df54801dfac84440dfe42e8ce55f1fe8f605b8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 1 15:53:52 2024 -0400

    Use assertThrows()
---
 .../org/apache/commons/jexl3/Issues300Test.java    | 49 +++++++---------------
 1 file changed, 15 insertions(+), 34 deletions(-)

diff --git a/src/test/java/org/apache/commons/jexl3/Issues300Test.java b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
index ce84fd8a..55a862c7 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues300Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
@@ -929,49 +929,30 @@ public class Issues300Test {
 
     @Test
     public void test384a() {
-        final JexlEngine jexl = new JexlBuilder()
-                .safe(false)
-                .strict(true)
-                .create();
+        final JexlEngine jexl = new JexlBuilder().safe(false).strict(true).create();
         // constant
-        for(final String src0 : Arrays.asList("'ABC' + null", "null + 'ABC'")) {
+        for (final String src0 : Arrays.asList("'ABC' + null", "null + 'ABC'")) {
             final JexlContext ctxt = new MapContext();
             final JexlScript s0 = jexl.createScript(src0);
-            try {
-                s0.execute(ctxt, (Object) null);
-                fail("null argument should throw");
-            } catch (final JexlException xvar) {
-                assertTrue(xvar.toString().contains("+"));
-            }
+            final JexlException xvar = assertThrows(JexlException.class, () -> s0.execute(ctxt, (Object) null), "null argument should throw");
+            assertTrue(xvar.toString().contains("+"));
         }
         // null local a
-        for(final String src1 : Arrays.asList("'ABC' + a", "a + 'ABC'")) {
+        for (final String src1 : Arrays.asList("'ABC' + a", "a + 'ABC'")) {
             final JexlContext ctxt = new MapContext();
-            JexlScript s1 = jexl.createScript(src1, "a");
-            try {
-                s1.execute(ctxt, (Object) null);
-                fail("null argument should throw");
-            } catch (final JexlException.Variable xvar) {
-                assertEquals("a", xvar.getVariable());
-            }
+            final JexlScript s1 = jexl.createScript(src1, "a");
+            JexlException.Variable xvar = assertThrows(JexlException.Variable.class, () -> s1.execute(ctxt, (Object) null), "null argument should throw");
+            assertEquals("a", xvar.getVariable());
             // undefined a
-            s1 = jexl.createScript(src1);
-            try {
-                s1.execute(ctxt, (Object) null);
-                fail("null argument should throw");
-            } catch (final JexlException.Variable xvar) {
-                assertEquals("a", xvar.getVariable());
-                assertTrue(xvar.isUndefined());
-            }
+            final JexlScript s2 = jexl.createScript(src1);
+            xvar = assertThrows(JexlException.Variable.class, () -> s2.execute(ctxt, (Object) null), "null argument should throw");
+            assertEquals("a", xvar.getVariable());
+            assertTrue(xvar.isUndefined());
             // null a
             ctxt.set("a", null);
-            try {
-                s1.execute(ctxt, (Object) null);
-                fail("null argument should throw");
-            } catch (final JexlException.Variable xvar) {
-                assertEquals("a", xvar.getVariable());
-                assertFalse(xvar.isUndefined());
-            }
+            xvar = assertThrows(JexlException.Variable.class, () -> s2.execute(ctxt, (Object) null), "null argument should throw");
+            assertEquals("a", xvar.getVariable());
+            assertFalse(xvar.isUndefined());
         }
     }
     @Test


(commons-jexl) 07/09: Use assertThrows()

Posted by gg...@apache.org.
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 54fed69a25b70a02ed9b81e5aac136bfe4758590
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 1 16:00:06 2024 -0400

    Use assertThrows()
---
 src/test/java/org/apache/commons/jexl3/Issues300Test.java | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/test/java/org/apache/commons/jexl3/Issues300Test.java b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
index 2c704aab..6dfeee4d 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues300Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
@@ -1077,12 +1077,14 @@ public class Issues300Test {
     }
 
     @Test public void testDow() {
+        // @formatter:off
         final String src = "(y, m, d)->{\n" +
                 "// will return 0 for Sunday, 6 for Saturday\n" +
                 "const t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4];\n"+
                 "if (m < 3) { --y }\n" +
                 "(y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;\n" +
             "}";
+        // @formatter:on
         final JexlEngine jexl = new JexlBuilder().create();
         final JexlScript script = jexl.createScript(src);
         Object r = script.execute(null, 2023, 3, 1);
@@ -1221,21 +1223,14 @@ public class Issues300Test {
     @Test
     public void tests301b() {
         final JexlEngine jexl = new JexlBuilder().safe(false).arithmetic(new JexlArithmetic(false)).create();
-        final Object[] xs = {null, null, new Object[]{null, 1}};
-        final String[] srcs = {
-                "x.0", "x[0]", "x[0][0]"
-        };
+        final Object[] xs = { null, null, new Object[] { null, 1 } };
+        final String[] srcs = { "x.0", "x[0]", "x[0][0]" };
         final JexlContext ctxt = new MapContext();
         for (int i = 0; i < xs.length; ++i) {
             ctxt.set("x", xs[i]);
             final String src = srcs[i];
             final JexlScript s = jexl.createScript(src);
-            try {
-                final Object o = s.execute(null);
-                fail(src + ": Should have failed");
-            } catch (final Exception ex) {
-                //
-            }
+            assertThrows(JexlException.class, () -> s.execute(null));
         }
     }
 


(commons-jexl) 02/09: Use assertThrows()

Posted by gg...@apache.org.
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 e91707045d868e523fc13554de67aa0941bb4d4a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 1 15:47:55 2024 -0400

    Use assertThrows()
---
 .../org/apache/commons/jexl3/Issues300Test.java    | 34 ++++++++++------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/src/test/java/org/apache/commons/jexl3/Issues300Test.java b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
index 2baed53c..ce84fd8a 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues300Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
@@ -901,34 +901,32 @@ public class Issues300Test {
         assertTrue(result instanceof LinkedHashMap);
         assertEquals(1, ((Map) result).size());
     }
-    @Test public void test383() {
+
+    @Test
+    public void test383() {
         final JexlEngine jexl = new JexlBuilder().safe(false).arithmetic(new Arithmetic383(true)).create();
-        final String src0 =  "if (a) 1; else 2;";
+        final String src0 = "if (a) 1; else 2;";
         final String src1 = "if (!a) 1; else 2;";
         // local var
-        JexlScript s0 = jexl.createScript(src0, "a");
-        JexlScript s1 = jexl.createScript(src1, "a");
+        final JexlScript s0 = jexl.createScript(src0, "a");
+        final JexlScript s1 = jexl.createScript(src1, "a");
         assertEquals(2, s0.execute(null, (Object) null));
         assertEquals(1, s1.execute(null, (Object) null));
         // global var undefined
-        s0 = jexl.createScript(src0);
-        s1 = jexl.createScript(src1);
-        try {
-            assertEquals(2, s0.execute(null, (Object) null));
-        } catch (final JexlException.Variable xvar) {
-            assertEquals("a", xvar.getVariable());
-        }
-        try {
-            assertEquals(1, s1.execute(null, (Object) null));
-        } catch (final JexlException.Variable xvar) {
-            assertEquals("a", xvar.getVariable());
-        }
+        final JexlScript s2 = jexl.createScript(src0);
+        final JexlScript s3 = jexl.createScript(src1);
+        JexlException.Variable xvar = assertThrows(JexlException.Variable.class, () -> s2.execute(null, (Object) null));
+        assertEquals("a", xvar.getVariable());
+        xvar = assertThrows(JexlException.Variable.class, () -> s3.execute(null, (Object) null));
+        assertEquals("a", xvar.getVariable());
+
         // global var null
         final MapContext ctxt = new MapContext();
         ctxt.set("a", null);
-        assertEquals(2, s0.execute(ctxt, (Object) null));
-        assertEquals(1, s1.execute(ctxt, (Object) null));
+        assertEquals(2, s2.execute(ctxt, (Object) null));
+        assertEquals(1, s3.execute(ctxt, (Object) null));
     }
+
     @Test
     public void test384a() {
         final JexlEngine jexl = new JexlBuilder()