commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r940507 - in /commons/proper/jexl/trunk/src: main/java/org/apache/commons/jexl2/internal/MethodExecutor.java test/java/org/apache/commons/jexl2/MethodTest.java
Date Mon, 03 May 2010 16:42:31 GMT
Author: henrib
Date: Mon May  3 16:42:31 2010
New Revision: 940507

URL: http://svn.apache.org/viewvc?rev=940507&view=rev
Log:
JEXL-101: Added explicit comments in code & test

Modified:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/MethodExecutor.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MethodTest.java

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/MethodExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/MethodExecutor.java?rev=940507&r1=940506&r2=940507&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/MethodExecutor.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/MethodExecutor.java
Mon May  3 16:42:31 2010
@@ -138,6 +138,7 @@ public final class MethodExecutor extend
                 Array.set(lastActual, 0, actual[index]);
                 actual[index] = lastActual;
             }
+            // else, the vararg is null and used as is, considered as T[]
         } else {
             // if no or multiple values are being passed into the vararg,
             // put them in an array of the expected type

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MethodTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MethodTest.java?rev=940507&r1=940506&r2=940507&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MethodTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MethodTest.java Mon May
 3 16:42:31 2010
@@ -32,8 +32,12 @@ public class MethodTest extends JexlTest
     public static class VarArgs {
         public String callInts(Integer... args) {
             int result = 0;
-            for (int i = 0; i < args.length; i++) {
-                result += args[i].intValue();
+            if (args != null) {
+                for (int i = 0; i < args.length; i++) {
+                        result += args[i] != null ?args[i] : -100;
+                }
+            } else {
+                result = -1000;
             }
             return "Varargs:"+result;
         }
@@ -42,8 +46,10 @@ public class MethodTest extends JexlTest
             int result = fixed.intValue();
             if (args != null) {
                 for (int i = 0; i < args.length; i++) {
-                    result += args[i].intValue();
+                    result += args[i] != null ?args[i] : -100;
                 }
+            } else {
+                result -= 1000;
             }
             return "Mixed:"+result;
         }
@@ -51,9 +57,11 @@ public class MethodTest extends JexlTest
         public String callMixed(String mixed, Integer... args) {
             int result = 0;
             if (args != null) {
-                for (int arg : args) {
-                    result += arg;
+                for (int i = 0; i < args.length; i++) {
+                    result += args[i] != null ?args[i] : -100;
                 }
+            } else {
+                result = -1000;
             }
             return mixed+":"+result;
         }
@@ -98,24 +106,37 @@ public class MethodTest extends JexlTest
     }
 
     public void testCallVarArgMethod() throws Exception {
-        asserter.setVariable("test", new VarArgs());
+        VarArgs test = new VarArgs();
+        asserter.setVariable("test", test);
         asserter.assertExpression("test.callInts()", "Varargs:0");
         asserter.assertExpression("test.callInts(1)", "Varargs:1");
         asserter.assertExpression("test.callInts(1,2,3,4,5)", "Varargs:15");
     }
 
     public void testCallMixedVarArgMethod() throws Exception {
-        asserter.setVariable("test", new VarArgs());
+        VarArgs test = new VarArgs();
+        asserter.setVariable("test", test);
+        assertEquals("Mixed:1", test.callMixed(1));
         asserter.assertExpression("test.callMixed(1)", "Mixed:1");
-        asserter.assertExpression("test.callMixed(1, null)", "Mixed:1");
+        // Java and JEXL equivalent behavior: 'Mixed:-999' expected
+        //{
+        assertEquals("Mixed:-999", test.callMixed(1, null));
+        asserter.assertExpression("test.callMixed(1, null)", "Mixed:-999");
+        //}
         asserter.assertExpression("test.callMixed(1,2)", "Mixed:3");
         asserter.assertExpression("test.callMixed(1,2,3,4,5)", "Mixed:15");
     }
 
     public void testCallJexlVarArgMethod() throws Exception {
-        asserter.setVariable("test", new VarArgs());
+        VarArgs test = new VarArgs();
+        asserter.setVariable("test", test);
+        assertEquals("jexl:0", test.callMixed("jexl"));
         asserter.assertExpression("test.callMixed('jexl')", "jexl:0");
-        asserter.assertExpression("test.callMixed('jexl', null)", "jexl:0");
+        // Java and JEXL equivalent behavior: 'jexl:-1000' expected
+        //{
+        assertEquals("jexl:-1000", test.callMixed("jexl", null));
+        asserter.assertExpression("test.callMixed('jexl', null)", "jexl:-1000");
+        //}
         asserter.assertExpression("test.callMixed('jexl', 2)", "jexl:2");
         asserter.assertExpression("test.callMixed('jexl',2,3,4,5)", "jexl:14");
     }



Mime
View raw message