You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by di...@apache.org on 2007/10/28 09:28:03 UTC

svn commit: r589302 - /commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/MethodTest.java

Author: dion
Date: Sun Oct 28 01:28:02 2007
New Revision: 589302

URL: http://svn.apache.org/viewvc?rev=589302&view=rev
Log:
JEXL-25 Add test for varargs
Move method tests to own test class

Added:
    commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/MethodTest.java

Added: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/MethodTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/MethodTest.java?rev=589302&view=auto
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/MethodTest.java (added)
+++ commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/MethodTest.java Sun Oct 28 01:28:02 2007
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jexl;
+
+import org.apache.commons.jexl.junit.Asserter;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for calling methods on objects
+ * 
+ * @since 2.0
+ */
+public class MethodTest extends TestCase {
+
+    private Asserter asserter;
+
+    private static final String METHOD_STRING = "Method string";
+
+    public static class TestClass {
+        public String testVarArgs(Integer[] args) {
+            return "Test";
+        }
+    }
+
+    public void setUp() {
+        asserter = new Asserter();
+    }
+
+    public void testCallVarArgMethod() throws Exception {
+        asserter.setVariable("test", new TestClass());
+        asserter.assertExpression("test.testVarArgs(1,2,3,4,5)", "Test");
+    }
+
+    /**
+     * test a simple method expression
+     */
+    public void testMethod() throws Exception {
+        // tests a simple method expression
+        asserter.setVariable("foo", new Foo());
+        asserter.assertExpression("foo.bar()", METHOD_STRING);
+    }
+
+    public void testMulti() throws Exception {
+        asserter.setVariable("foo", new Foo());
+        asserter.assertExpression("foo.innerFoo.bar()", METHOD_STRING);
+    }
+
+    /**
+     * test some String method calls
+     */
+    public void testStringMethods() throws Exception {
+        asserter.setVariable("foo", "abcdef");
+        asserter.assertExpression("foo.substring(3)", "def");
+        asserter.assertExpression("foo.substring(0,(size(foo)-3))", "abc");
+        asserter.assertExpression("foo.substring(0,size(foo)-3)", "abc");
+        asserter.assertExpression("foo.substring(0,foo.length()-3)", "abc");
+        asserter.assertExpression("foo.substring(0, 1+1)", "ab");
+    }
+
+    /**
+     * Ensures static methods on objects can be called.
+     */
+    public void testStaticMethodInvocation() throws Exception {
+        asserter.setVariable("aBool", Boolean.FALSE);
+        asserter.assertExpression("aBool.valueOf('true')", Boolean.TRUE);
+    }
+
+    public void testStaticMethodInvocationOnClasses() throws Exception {
+        asserter.setVariable("Boolean", Boolean.class);
+        asserter.assertExpression("Boolean.valueOf('true')", Boolean.TRUE);
+    }
+
+}
\ No newline at end of file