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:41:03 UTC
svn commit: r589305 - in
/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl:
ArrayAccessTest.java Foo.java JexlTest.java
Author: dion
Date: Sun Oct 28 01:41:01 2007
New Revision: 589305
URL: http://svn.apache.org/viewvc?rev=589305&view=rev
Log:
Move ArrayAccess tests to own class
Added:
commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArrayAccessTest.java
Modified:
commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/Foo.java
commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/JexlTest.java
Added: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArrayAccessTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArrayAccessTest.java?rev=589305&view=auto
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArrayAccessTest.java (added)
+++ commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArrayAccessTest.java Sun Oct 28 01:41:01 2007
@@ -0,0 +1,126 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.jexl.junit.Asserter;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for array access operator []
+ *
+ * @since 2.0
+ */
+public class ArrayAccessTest extends TestCase {
+
+ private Asserter asserter;
+
+ protected static final String GET_METHOD_STRING = "GetMethod string";
+ protected static final String[] GET_METHOD_ARRAY =
+ new String[] { "One", "Two", "Three" };
+
+ protected static final String[][] GET_METHOD_ARRAY2 =
+ new String[][] { {"One", "Two", "Three"},{"Four", "Five", "Six"} };
+
+ public void setUp() {
+ asserter = new Asserter();
+ }
+
+ /**
+ * test simple array access
+ */
+ public void testArrayAccess() throws Exception {
+
+ /*
+ * test List access
+ */
+
+ List l = new ArrayList();
+ l.add(new Integer(1));
+ l.add(new Integer(2));
+ l.add(new Integer(3));
+
+ asserter.setVariable("list", l);
+
+ asserter.assertExpression("list[1]", new Integer(2));
+ asserter.assertExpression("list[1+1]", new Integer(3));
+ asserter.setVariable("loc", new Integer(1));
+ asserter.assertExpression("list[loc+1]", new Integer(3));
+
+ /*
+ * test array access
+ */
+
+ String[] args = { "hello", "there" };
+ asserter.setVariable("array", args);
+ asserter.assertExpression("array[0]", "hello");
+
+ /*
+ * to think that this was an intentional syntax...
+ */
+ asserter.assertExpression("array.0", "hello");
+
+ /*
+ * test map access
+ */
+ Map m = new HashMap();
+ m.put("foo", "bar");
+
+ asserter.setVariable("map", m);
+ asserter.setVariable("key", "foo");
+
+ asserter.assertExpression("map[\"foo\"]", "bar");
+ asserter.assertExpression("map[key]", "bar");
+
+ /*
+ * test bean access
+ */
+ asserter.setVariable("foo", new Foo());
+ asserter.assertExpression("foo[\"bar\"]", GET_METHOD_STRING);
+ asserter.assertExpression("foo[\"bar\"] == foo.bar", Boolean.TRUE);
+ }
+
+ /**
+ * test some simple double array lookups
+ */
+ public void testDoubleArrays() throws Exception {
+ Object[][] foo = new Object[2][2];
+ foo[0][0] = "one";
+ foo[0][1] = "two";
+
+ asserter.setVariable("foo", foo);
+
+ asserter.assertExpression("foo[0][1]", "two");
+ }
+
+ public void testArrayProperty() throws Exception {
+ Foo foo = new Foo();
+
+ asserter.setVariable("foo", foo);
+
+ asserter.assertExpression("foo.array[1]", GET_METHOD_ARRAY[1]);
+ asserter.assertExpression("foo.array.1", GET_METHOD_ARRAY[1]);
+ asserter.assertExpression("foo.array2[1][1]", GET_METHOD_ARRAY2[1][1]);
+ // asserter.assertExpression("foo.array2.1.1", GET_METHOD_ARRAY2[1][1]);
+ }
+
+}
\ No newline at end of file
Modified: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/Foo.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/Foo.java?rev=589305&r1=589304&r2=589305&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/Foo.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/Foo.java Sun Oct 28 01:41:01 2007
@@ -71,12 +71,12 @@
public String[] getArray()
{
- return JexlTest.GET_METHOD_ARRAY;
+ return ArrayAccessTest.GET_METHOD_ARRAY;
}
public String[][] getArray2()
{
- return JexlTest.GET_METHOD_ARRAY2;
+ return ArrayAccessTest.GET_METHOD_ARRAY2;
}
public boolean isSimple()
Modified: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/JexlTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/JexlTest.java?rev=589305&r1=589304&r2=589305&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/JexlTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/JexlTest.java Sun Oct 28 01:41:01 2007
@@ -49,12 +49,6 @@
protected static final String METHOD_STRING = "Method string";
protected static final String GET_METHOD_STRING = "GetMethod string";
- protected static final String[] GET_METHOD_ARRAY =
- new String[] { "One", "Two", "Three" };
-
- protected static final String[][] GET_METHOD_ARRAY2 =
- new String[][] { {"One", "Two", "Three"},{"Four", "Five", "Six"} };
-
public static Test suite()
{
return new TestSuite(JexlTest.class);
@@ -85,64 +79,6 @@
assertEquals("o incorrect", GET_METHOD_STRING, o);
}
- /**
- * test a simple method expression
- */
- public void testArrayAccess()
- throws Exception
- {
- JexlContext jc = JexlHelper.createContext();
-
- /*
- * test List access
- */
-
- List l = new ArrayList();
- l.add(new Integer(1));
- l.add(new Integer(2));
- l.add(new Integer(3));
-
- jc.getVars().put("list", l);
-
- assertExpression(jc, "list[1]", new Integer(2));
- assertExpression(jc, "list[1+1]", new Integer(3));
- jc.getVars().put("loc", new Integer(1));
- assertExpression(jc, "list[loc+1]", new Integer(3));
-
- /*
- * test array access
- */
-
- String[] args = {"hello", "there"};
- jc.getVars().put("array", args);
- assertExpression(jc, "array[0]", "hello");
-
- /*
- * to think that this was an intentional syntax...
- */
- assertExpression(jc, "array.0", "hello");
-
- /*
- * test map access
- */
- Map m = new HashMap();
- m.put("foo", "bar");
-
- jc.getVars().put("map", m);
- jc.getVars().put("key", "foo");
-
- assertExpression(jc, "map[\"foo\"]", "bar");
- assertExpression(jc, "map[key]", "bar");
-
- /*
- * test bean access
- */
- jc.getVars().put("foo", new Foo());
- assertExpression(jc, "foo[\"bar\"]", GET_METHOD_STRING);
- assertExpression(jc, "foo[\"bar\"] == foo.bar", Boolean.TRUE);
-
- }
-
public void testBoolean()
throws Exception
{
@@ -563,23 +499,6 @@
/**
- * test some simple double array lookups
- */
- public void testDoubleArrays()
- throws Exception
- {
- JexlContext jc = JexlHelper.createContext();
-
- Object[][] foo = new Object[2][2];
- foo[0][0] = "one";
- foo[0][1] = "two";
-
- jc.getVars().put("foo", foo );
-
- assertExpression(jc, "foo[0][1]", "two");
- }
-
- /**
* test variables with underscore names
*/
public void testVariableNames()
@@ -652,20 +571,6 @@
assertExpression(jc, "foo.count != -1", Boolean.TRUE);
assertExpression(jc, "foo.count == 5", Boolean.TRUE);
assertExpression(jc, "foo.count == -1", Boolean.FALSE);
- }
-
- public void testArrayProperty()
- throws Exception
- {
- Foo foo = new Foo();
-
- JexlContext jc = JexlHelper.createContext();
- jc.getVars().put("foo", foo );
-
- assertExpression(jc, "foo.array[1]", GET_METHOD_ARRAY[1]);
- assertExpression(jc, "foo.array.1", GET_METHOD_ARRAY[1]);
- assertExpression(jc, "foo.array2[1][1]", GET_METHOD_ARRAY2[1][1]);
- //assertExpression(jc, "foo.array2.1.1", GET_METHOD_ARRAY2[1][1]);
}
/**