You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2018/01/21 10:44:04 UTC

svn commit: r1821782 - /commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java

Author: henrib
Date: Sun Jan 21 10:44:04 2018
New Revision: 1821782

URL: http://svn.apache.org/viewvc?rev=1821782&view=rev
Log:
JEXL:
Coverage, added a test on method overloads / object parameters / null arguments

Modified:
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java?rev=1821782&r1=1821781&r2=1821782&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java Sun Jan 21 10:44:04 2018
@@ -21,6 +21,7 @@ import java.util.Map;
 import org.apache.commons.jexl3.introspection.JexlMethod;
 import org.apache.commons.jexl3.junit.Asserter;
 import java.util.Arrays;
+import java.util.Date;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -191,6 +192,25 @@ public class MethodTest extends JexlTest
         public static Class<?> NPEIfNull(Object x) {
             return x.getClass();
         }
+
+        public Object over(String f, int i) {
+            return f + " + " + i;
+        }
+
+        public Object over(String f, Date g) {
+            return f + " + " + g;
+        }
+
+        public Object over(String f, String g) {
+            return f + " + " + g;
+        }
+    }
+
+    public static class FunctorOver extends Functor {
+
+        public Object over(Object f, Object g) {
+            return f + " + " + g;
+        }
     }
 
     @Test
@@ -210,6 +230,31 @@ public class MethodTest extends JexlTest
         } catch (Exception xj0) {
             // ignore
         }
+
+        Object result;
+        try {
+            result = JEXL.invokeMethod(func, "over", "foo", 42);
+            Assert.assertEquals("foo + 42", result);
+        } catch (Exception xj0) {
+            // ignore
+            result = xj0;
+        }
+
+        try {
+            result = JEXL.invokeMethod(func, "over", null, null);
+            Assert.fail("method should have thrown!");
+        } catch (Exception xj0) {
+            // ignore
+            result = xj0;
+        }
+
+        func = new FunctorOver();
+        try {
+            result = JEXL.invokeMethod(func, "over", null, null);
+            Assert.assertEquals("null + null", result);
+        } catch (Exception xj0) {
+            Assert.fail("method should not have thrown!");
+        }
     }
 
     /**