You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2009/08/04 17:29:33 UTC
svn commit: r800842 -
/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/
Author: sebb
Date: Tue Aug 4 15:29:32 2009
New Revision: 800842
URL: http://svn.apache.org/viewvc?rev=800842&view=rev
Log:
JEXL-68 Remove usage of deprecated classes in tests
Removed:
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ScriptFactoryTest.java
Modified:
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BitwiseOperatorTest.java
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BlockTest.java
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ForEachTest.java
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IfTest.java
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/Jexl.java
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/JexlTest.java
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/JexlTestCase.java
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/MapLiteralTest.java
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ParseFailuresTest.java
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ScriptTest.java
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/WhileTest.java
Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BitwiseOperatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BitwiseOperatorTest.java?rev=800842&r1=800841&r2=800842&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BitwiseOperatorTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BitwiseOperatorTest.java Tue Aug 4 15:29:32 2009
@@ -34,35 +34,35 @@
}
public void testAndWithTwoNulls() throws Exception {
- Expression e = ExpressionFactory.createExpression("null & null");
+ Expression e = JEXL.createExpression("null & null");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Long(0), o);
}
public void testAndWithLeftNull() throws Exception {
- Expression e = ExpressionFactory.createExpression("null & 1");
+ Expression e = JEXL.createExpression("null & 1");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Long(0), o);
}
public void testAndWithRightNull() throws Exception {
- Expression e = ExpressionFactory.createExpression("1 & null");
+ Expression e = JEXL.createExpression("1 & null");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Long(0), o);
}
public void testAndSimple() throws Exception {
- Expression e = ExpressionFactory.createExpression("15 & 3");
+ Expression e = JEXL.createExpression("15 & 3");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Long(3), o);
}
public void testAndVariableNumberCoercion() throws Exception {
- Expression e = ExpressionFactory.createExpression("x & y");
+ Expression e = JEXL.createExpression("x & y");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("x", new Integer(15));
jc.getVars().put("y", new Short((short)7));
@@ -71,7 +71,7 @@
}
public void testAndVariableStringCoercion() throws Exception {
- Expression e = ExpressionFactory.createExpression("x & y");
+ Expression e = JEXL.createExpression("x & y");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("x", new Integer(15));
jc.getVars().put("y", "7");
@@ -80,21 +80,21 @@
}
public void testComplementWithNull() throws Exception {
- Expression e = ExpressionFactory.createExpression("~null");
+ Expression e = JEXL.createExpression("~null");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Long(-1), o);
}
public void testComplementSimple() throws Exception {
- Expression e = ExpressionFactory.createExpression("~128");
+ Expression e = JEXL.createExpression("~128");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Long(-129), o);
}
public void testComplementVariableNumberCoercion() throws Exception {
- Expression e = ExpressionFactory.createExpression("~x");
+ Expression e = JEXL.createExpression("~x");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("x", new Integer(15));
Object o = e.evaluate(jc);
@@ -102,7 +102,7 @@
}
public void testComplementVariableStringCoercion() throws Exception {
- Expression e = ExpressionFactory.createExpression("~x");
+ Expression e = JEXL.createExpression("~x");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("x", "15");
Object o = e.evaluate(jc);
@@ -110,35 +110,35 @@
}
public void testOrWithTwoNulls() throws Exception {
- Expression e = ExpressionFactory.createExpression("null | null");
+ Expression e = JEXL.createExpression("null | null");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Long(0), o);
}
public void testOrWithLeftNull() throws Exception {
- Expression e = ExpressionFactory.createExpression("null | 1");
+ Expression e = JEXL.createExpression("null | 1");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Long(1), o);
}
public void testOrWithRightNull() throws Exception {
- Expression e = ExpressionFactory.createExpression("1 | null");
+ Expression e = JEXL.createExpression("1 | null");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Long(1), o);
}
public void testOrSimple() throws Exception {
- Expression e = ExpressionFactory.createExpression("12 | 3");
+ Expression e = JEXL.createExpression("12 | 3");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Long(15), o);
}
public void testOrVariableNumberCoercion() throws Exception {
- Expression e = ExpressionFactory.createExpression("x | y");
+ Expression e = JEXL.createExpression("x | y");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("x", new Integer(12));
jc.getVars().put("y", new Short((short) 3));
@@ -147,7 +147,7 @@
}
public void testOrVariableStringCoercion() throws Exception {
- Expression e = ExpressionFactory.createExpression("x | y");
+ Expression e = JEXL.createExpression("x | y");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("x", new Integer(12));
jc.getVars().put("y", "3");
@@ -156,35 +156,35 @@
}
public void testXorWithTwoNulls() throws Exception {
- Expression e = ExpressionFactory.createExpression("null ^ null");
+ Expression e = JEXL.createExpression("null ^ null");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Long(0), o);
}
public void testXorWithLeftNull() throws Exception {
- Expression e = ExpressionFactory.createExpression("null ^ 1");
+ Expression e = JEXL.createExpression("null ^ 1");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Long(1), o);
}
public void testXorWithRightNull() throws Exception {
- Expression e = ExpressionFactory.createExpression("1 ^ null");
+ Expression e = JEXL.createExpression("1 ^ null");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Long(1), o);
}
public void testXorSimple() throws Exception {
- Expression e = ExpressionFactory.createExpression("1 ^ 3");
+ Expression e = JEXL.createExpression("1 ^ 3");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Long(2), o);
}
public void testXorVariableNumberCoercion() throws Exception {
- Expression e = ExpressionFactory.createExpression("x ^ y");
+ Expression e = JEXL.createExpression("x ^ y");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("x", new Integer(1));
jc.getVars().put("y", new Short((short) 3));
@@ -193,7 +193,7 @@
}
public void testXorVariableStringCoercion() throws Exception {
- Expression e = ExpressionFactory.createExpression("x ^ y");
+ Expression e = JEXL.createExpression("x ^ y");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("x", new Integer(1));
jc.getVars().put("y", "3");
Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BlockTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BlockTest.java?rev=800842&r1=800841&r2=800842&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BlockTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/BlockTest.java Tue Aug 4 15:29:32 2009
@@ -32,16 +32,14 @@
}
public void testBlockSimple() throws Exception {
- Expression e = ExpressionFactory
- .createExpression("if (true) { 'hello'; }");
+ Expression e = JEXL.createExpression("if (true) { 'hello'; }");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", "hello", o);
}
-
+
public void testBlockExecutesAll() throws Exception {
- Expression e = ExpressionFactory
- .createExpression("if (true) { x = 'Hello'; y = 'World';}");
+ Expression e = JEXL.createExpression("if (true) { x = 'Hello'; y = 'World';}");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("First result is wrong", "Hello", jc.getVars().get("x"));
@@ -50,37 +48,33 @@
}
public void testEmptyBlock() throws Exception {
- Expression e = ExpressionFactory
- .createExpression("if (true) { }");
+ Expression e = JEXL.createExpression("if (true) { }");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertNull("Result is wrong", o);
}
public void testBlockLastExecuted01() throws Exception {
- Expression e = ExpressionFactory
- .createExpression("if (true) { x = 1; } else { x = 2; }");
+ Expression e = JEXL.createExpression("if (true) { x = 1; } else { x = 2; }");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Block result is wrong", new Integer(1), o);
}
public void testBlockLastExecuted02() throws Exception {
- Expression e = ExpressionFactory
- .createExpression("if (false) { x = 1; } else { x = 2; }");
+ Expression e = JEXL.createExpression("if (false) { x = 1; } else { x = 2; }");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Block result is wrong", new Integer(2), o);
}
public void testNestedBlock() throws Exception {
- Expression e = ExpressionFactory
- .createExpression("if (true) { x = 'hello'; y = 'world';"
- + " if (true) { x; } y; }");
+ Expression e = JEXL.createExpression("if (true) { x = 'hello'; y = 'world';" + " if (true) { x; } y; }");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
assertEquals("Block result is wrong", "world", o);
}
+
public static void main(String[] args) throws Exception {
new BlockTest("debug").testBlockExecutesAll();
//new AssignTest("debug").testArray();
Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ForEachTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ForEachTest.java?rev=800842&r1=800841&r2=800842&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ForEachTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ForEachTest.java Tue Aug 4 15:29:32 2009
@@ -36,7 +36,7 @@
}
public void testForEachWithEmptyStatement() throws Exception {
- Expression e = ExpressionFactory.createExpression("foreach (item in list) ;");
+ Expression e = JEXL.createExpression("foreach (item in list) ;");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
@@ -44,7 +44,7 @@
}
public void testForEachWithEmptyList() throws Exception {
- Expression e = ExpressionFactory.createExpression("foreach (item in list) 1+1");
+ Expression e = JEXL.createExpression("foreach (item in list) 1+1");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
@@ -52,7 +52,7 @@
}
public void testForEachWithArray() throws Exception {
- Expression e = ExpressionFactory.createExpression("foreach (item in list) item");
+ Expression e = JEXL.createExpression("foreach (item in list) item");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("list", new Object[] {"Hello", "World"});
Object o = e.evaluate(jc);
@@ -60,7 +60,7 @@
}
public void testForEachWithCollection() throws Exception {
- Expression e = ExpressionFactory.createExpression("foreach (item in list) item");
+ Expression e = JEXL.createExpression("foreach (item in list) item");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("list", Arrays.asList(new Object[] {"Hello", "World"}));
Object o = e.evaluate(jc);
@@ -68,7 +68,7 @@
}
public void testForEachWithEnumeration() throws Exception {
- Expression e = ExpressionFactory.createExpression("foreach (item in list) item");
+ Expression e = JEXL.createExpression("foreach (item in list) item");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("list", new StringTokenizer("Hello,World", ","));
Object o = e.evaluate(jc);
@@ -76,7 +76,7 @@
}
public void testForEachWithIterator() throws Exception {
- Expression e = ExpressionFactory.createExpression("foreach (item in list) item");
+ Expression e = JEXL.createExpression("foreach (item in list) item");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("list", Arrays.asList(new Object[] {"Hello", "World"}).iterator());
Object o = e.evaluate(jc);
@@ -84,17 +84,17 @@
}
public void testForEachWithMap() throws Exception {
- Expression e = ExpressionFactory.createExpression("foreach (item in list) item");
+ Expression e = JEXL.createExpression("foreach (item in list) item");
JexlContext jc = JexlHelper.createContext();
- Map map = System.getProperties();
- String lastProperty = (String) new ArrayList(map.values()).get(System.getProperties().size() - 1);
+ Map<?, ?> map = System.getProperties();
+ String lastProperty = (String) new ArrayList<Object>(map.values()).get(System.getProperties().size() - 1);
jc.getVars().put("list", map);
Object o = e.evaluate(jc);
assertEquals("Result is not last evaluated expression", lastProperty, o);
}
public void testForEachWithBlock() throws Exception {
- Expression e = ExpressionFactory.createExpression("foreach (item in list) { x = x + item; }");
+ Expression e = JEXL.createExpression("foreach (item in list) { x = x + item; }");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("list", new Object[] {"1", "1"});
jc.getVars().put("x", new Integer(0));
@@ -104,18 +104,17 @@
}
public void testForEachWithListExpression() throws Exception {
- Expression e = ExpressionFactory.createExpression("foreach (item in list.keySet()) item");
+ Expression e = JEXL.createExpression("foreach (item in list.keySet()) item");
JexlContext jc = JexlHelper.createContext();
- Map map = System.getProperties();
- String lastKey = (String) new ArrayList(map.keySet()).get(System.getProperties().size() - 1);
+ Map<?, ?> map = System.getProperties();
+ String lastKey = (String) new ArrayList<Object>(map.keySet()).get(System.getProperties().size() - 1);
jc.getVars().put("list", map);
Object o = e.evaluate(jc);
assertEquals("Result is not last evaluated expression", lastKey, o);
}
- public void testForEachWithProperty() throws Exception
- {
- Expression e = ExpressionFactory.createExpression("foreach (item in list.cheeseList) item");
+ public void testForEachWithProperty() throws Exception {
+ Expression e = JEXL.createExpression("foreach (item in list.cheeseList) item");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("list", new Foo());
Object o = e.evaluate(jc);
Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IfTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IfTest.java?rev=800842&r1=800841&r2=800842&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IfTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IfTest.java Tue Aug 4 15:29:32 2009
@@ -36,7 +36,7 @@
* @throws Exception on any error
*/
public void testSimpleIfTrue() throws Exception {
- Expression e = ExpressionFactory.createExpression("if (true) 1");
+ Expression e = JEXL.createExpression("if (true) 1");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
@@ -49,7 +49,7 @@
* @throws Exception on any error
*/
public void testSimpleIfFalse() throws Exception {
- Expression e = ExpressionFactory.createExpression("if (false) 1");
+ Expression e = JEXL.createExpression("if (false) 1");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
@@ -62,7 +62,7 @@
* @throws Exception on any error
*/
public void testSimpleElse() throws Exception {
- Expression e = ExpressionFactory
+ Expression e = JEXL
.createExpression("if (false) 1; else 2;");
JexlContext jc = JexlHelper.createContext();
@@ -76,7 +76,7 @@
* @throws Exception on any error
*/
public void testBlockIfTrue() throws Exception {
- Expression e = ExpressionFactory
+ Expression e = JEXL
.createExpression("if (true) { 'hello'; }");
JexlContext jc = JexlHelper.createContext();
@@ -90,7 +90,7 @@
* @throws Exception on any error
*/
public void testBlockElse() throws Exception {
- Expression e = ExpressionFactory
+ Expression e = JEXL
.createExpression("if (false) {1;} else {2;}");
JexlContext jc = JexlHelper.createContext();
@@ -104,7 +104,7 @@
* @throws Exception on any error
*/
public void testIfWithSimpleExpression() throws Exception {
- Expression e = ExpressionFactory
+ Expression e = JEXL
.createExpression("if (x == 1) true;");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("x", new Integer(1));
@@ -119,7 +119,7 @@
* @throws Exception on any error
*/
public void testIfWithArithmeticExpression() throws Exception {
- Expression e = ExpressionFactory
+ Expression e = JEXL
.createExpression("if ((x * 2) + 1 == 5) true;");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("x", new Integer(2));
@@ -134,7 +134,7 @@
* @throws Exception on any error
*/
public void testIfWithDecimalArithmeticExpression() throws Exception {
- Expression e = ExpressionFactory
+ Expression e = JEXL
.createExpression("if ((x * 2) == 5) true;");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("x", new Float(2.5f));
@@ -149,7 +149,7 @@
* @throws Exception on any error
*/
public void testIfWithAssignment() throws Exception {
- Expression e = ExpressionFactory
+ Expression e = JEXL
.createExpression("if ((x * 2) == 5) {y = 1;} else {y = 2;}");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("x", new Float(2.5f));
Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java?rev=800842&r1=800841&r2=800842&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java Tue Aug 4 15:29:32 2009
@@ -33,16 +33,16 @@
public void test49() throws Exception {
JexlContext ctxt = JexlHelper.createContext();
String stmt = "{a = 'b'; c = 'd';}";
- Script expr = ScriptFactory.createScript(stmt);
- Object value = expr.execute(ctxt);
- Map vars = ctxt.getVars();
+ Script expr = JEXL.createScript(stmt);
+ /* Object value = */ expr.execute(ctxt);
+ Map<String, Object> vars = ctxt.getVars();
assertTrue("JEXL-49 is not fixed", vars.get("a").equals("b") && vars.get("c").equals("d"));
}
// JEXL-48: bad assignment detection
public static class Another {
- private Boolean foo = true;
+ private Boolean foo = Boolean.TRUE;
public Boolean foo() {
return foo;
}
@@ -71,7 +71,7 @@
jc.getVars().put("foo", new Foo() );
try {
- Object o = e.evaluate(jc);
+ /* Object o = */ e.evaluate(jc);
fail("Should have failed due to invalid assignment");
}
catch(JexlException xjexl) {
@@ -89,15 +89,15 @@
Expression expr = jexl.createExpression( "true//false\n" );
Object value = expr.evaluate(ctxt);
- assertTrue("should be true", (Boolean) value);
+ assertTrue("should be true", ((Boolean) value).booleanValue());
expr = jexl.createExpression( "/*true*/false" );
value = expr.evaluate(ctxt);
- assertFalse("should be false", (Boolean) value);
+ assertFalse("should be false", ((Boolean) value).booleanValue());
expr = jexl.createExpression( "/*\"true\"*/false" );
value = expr.evaluate(ctxt);
- assertFalse("should be false", (Boolean) value);
+ assertFalse("should be false", ((Boolean) value).booleanValue());
}
// JEXL-42: NullPointerException evaluating an expression
@@ -122,6 +122,7 @@
}
class Derived extends Base {
+ @Override
public boolean foo() {
return true;
}
@@ -136,7 +137,7 @@
Expression expr = jexl.createExpression( "derived.foo()" );
Object value = expr.evaluate(ctxt);
- assertTrue("should be true", (Boolean) value);
+ assertTrue("should be true", ((Boolean) value).booleanValue());
}
// JEXL-52: can be implemented by deriving Interpreter.{g,s}etAttribute; later
@@ -172,13 +173,11 @@
for(int e = 0; e < exprs.length; ++e) {
try {
Expression expr = jexl.createExpression( exprs[e]);
- Object value = expr.evaluate(ctxt);
+ /* Object value = */ expr.evaluate(ctxt);
fail("Should have failed due to null argument");
}
catch(JexlException xjexl) {
// expected
- String msg = xjexl.toString();
- String xmsg = msg;
}
}
}
Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/Jexl.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/Jexl.java?rev=800842&r1=800841&r2=800842&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/Jexl.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/Jexl.java Tue Aug 4 15:29:32 2009
@@ -27,14 +27,16 @@
public class Jexl {
public static void main(String[] args) {
+ final JexlEngine JEXL = new JexlEngine();
// dummy context to get variables
JexlContext context = new JexlContext() {
+ @SuppressWarnings("unchecked")
public Map getVars() { return System.getProperties(); }
- public void setVars(Map map) { }
+ public void setVars(Map<String,Object> map) { }
};
try {
for (int i = 0; i < args.length; i++) {
- Expression e = ExpressionFactory.createExpression(args[i]);
+ Expression e = JEXL.createExpression(args[i]);
System.out.println("evaluate(" + args[i] + ") = '" + e.evaluate(context) + "'");
}
} catch (Exception e) {
Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/JexlTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/JexlTest.java?rev=800842&r1=800841&r2=800842&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/JexlTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/JexlTest.java Tue Aug 4 15:29:32 2009
@@ -68,7 +68,7 @@
* tests a simple property expression
*/
- Expression e = ExpressionFactory.createExpression("foo.bar");
+ Expression e = JEXL.createExpression("foo.bar");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("foo", new Foo() );
@@ -172,9 +172,9 @@
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("string", "");
jc.getVars().put("array", new Object[0]);
- jc.getVars().put("map", new HashMap());
- jc.getVars().put("list", new ArrayList());
- jc.getVars().put("set", (new HashMap()).keySet());
+ jc.getVars().put("map", new HashMap<Object, Object>());
+ jc.getVars().put("list", new ArrayList<Object>());
+ jc.getVars().put("set", (new HashMap<Object, Object>()).keySet());
jc.getVars().put("longstring", "thingthing");
/*
@@ -197,7 +197,7 @@
jc.getVars().put("s", "five!");
jc.getVars().put("array", new Object[5]);
- Map map = new HashMap();
+ Map<String, Integer> map = new HashMap<String, Integer>();
map.put("1", new Integer(1));
map.put("2", new Integer(2));
@@ -207,7 +207,7 @@
jc.getVars().put("map", map);
- List list = new ArrayList();
+ List<String> list = new ArrayList<String>();
list.add("1");
list.add("2");
@@ -218,7 +218,7 @@
jc.getVars().put("list", list);
// 30652 - support for set
- Set set = new HashSet();
+ Set<String> set = new HashSet<String>();
set.addAll(list);
set.add("1");
@@ -247,7 +247,7 @@
public void testSizeAsProperty() throws Exception
{
JexlContext jc = JexlHelper.createContext();
- Map map = new HashMap();
+ Map<String, Object> map = new HashMap<String, Object>();
map.put("size", "cheese");
jc.getVars().put("map", map);
jc.getVars().put("foo", new Foo());
@@ -269,13 +269,13 @@
jc.getVars().put("foo", "org.apache.commons.jexl.Foo");
Expression expr;
Object value;
- expr = ExpressionFactory.createExpression("new(double, 1)");
+ expr = JEXL.createExpression("new(double, 1)");
value = expr.evaluate(jc);
assertEquals(expr.toString(), new Double(1.0), value);
- expr = ExpressionFactory.createExpression("new('java.lang.Float', 100)");
+ expr = JEXL.createExpression("new('java.lang.Float', 100)");
value = expr.evaluate(jc);
assertEquals(expr.toString(), new Float(100.0), value);
- expr = ExpressionFactory.createExpression("new(foo).quux");
+ expr = JEXL.createExpression("new(foo).quux");
value = expr.evaluate(jc);
assertEquals(expr.toString(), "Repeat : quux", value);
}
@@ -319,8 +319,8 @@
jc.getVars().put("aChar", new Character('A'));
jc.getVars().put("aBool", Boolean.TRUE);
StringBuffer buffer = new StringBuffer("abc");
- List list = new ArrayList();
- List list2 = new LinkedList();
+ List<Object> list = new ArrayList<Object>();
+ List<Object> list2 = new LinkedList<Object>();
jc.getVars().put("aBuffer", buffer);
jc.getVars().put("aList", list);
jc.getVars().put("bList", list2);
@@ -501,7 +501,7 @@
public void testMapDot()
throws Exception
{
- Map foo = new HashMap();
+ Map<String, String> foo = new HashMap<String, String>();
foo.put( "bar", "123" );
JexlContext jc = JexlHelper.createContext();
@@ -586,8 +586,8 @@
public void testEmptySubListOfMap() throws Exception
{
JexlContext jc = JexlHelper.createContext();
- Map m = new HashMap();
- m.put("aList", new ArrayList());
+ Map<String, ArrayList<?>> m = new HashMap<String, ArrayList<?>>();
+ m.put("aList", new ArrayList<Object>());
jc.getVars().put( "aMap", m );
@@ -625,7 +625,7 @@
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("first", Boolean.FALSE);
jc.getVars().put("foo", tester);
- Expression expr = ExpressionFactory.createExpression("first and foo.trueAndModify");
+ Expression expr = JEXL.createExpression("first and foo.trueAndModify");
expr.evaluate(jc);
assertTrue("Short circuit failure: rhs evaluated when lhs FALSE", !tester.getModified());
// handle true for the left arg of 'and'
@@ -647,7 +647,7 @@
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("first", Boolean.FALSE);
jc.getVars().put("foo", tester);
- Expression expr = ExpressionFactory.createExpression("first or foo.trueAndModify");
+ Expression expr = JEXL.createExpression("first or foo.trueAndModify");
expr.evaluate(jc);
assertTrue("Short circuit failure: rhs not evaluated when lhs FALSE", tester.getModified());
// handle true for the left arg of 'or'
@@ -672,7 +672,7 @@
public void testToString() throws Exception {
String code = "abcd";
- Expression expr = ExpressionFactory.createExpression(code);
+ Expression expr = JEXL.createExpression(code);
assertEquals("Bad expression value", code, expr.toString());
}
@@ -747,6 +747,7 @@
public static final class Duck {
int user = 10;
+ @SuppressWarnings("boxing")
public Integer get(String val) {
if ("zero".equals(val))
return 0;
@@ -756,6 +757,7 @@
return user;
return -1;
}
+ @SuppressWarnings("boxing")
public void put(String val, Object value) {
if ("user".equals(val)) {
if ("zero".equals(value))
@@ -768,6 +770,7 @@
}
}
+ @SuppressWarnings("boxing")
public void testDuck() throws Exception {
JexlEngine jexl = new JexlEngine();
JexlContext jc = JexlHelper.createContext();
@@ -793,6 +796,7 @@
assertEquals(expr.toString(), 0, result);
}
+ @SuppressWarnings("boxing")
public void testArray() throws Exception {
int[] array = { 100, 101 , 102 };
JexlEngine jexl = new JexlEngine();
@@ -817,7 +821,7 @@
*/
protected void assertExpression(JexlContext jc, String expression, Object expected) throws Exception
{
- Expression e = ExpressionFactory.createExpression(expression);
+ Expression e = JEXL.createExpression(expression);
Object actual = e.evaluate(jc);
assertEquals(expression, expected, actual);
}
Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/JexlTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/JexlTestCase.java?rev=800842&r1=800841&r2=800842&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/JexlTestCase.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/JexlTestCase.java Tue Aug 4 15:29:32 2009
@@ -26,6 +26,9 @@
public class JexlTestCase extends TestCase {
private static final Class<?>[] noParms = {};
+ /** A default Jexl engine instance. */
+ protected final JexlEngine JEXL = new JexlEngine();
+
public JexlTestCase(String name) {
super(name);
}
Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/MapLiteralTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/MapLiteralTest.java?rev=800842&r1=800841&r2=800842&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/MapLiteralTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/MapLiteralTest.java Tue Aug 4 15:29:32 2009
@@ -29,7 +29,7 @@
public class MapLiteralTest extends JexlTestCase {
public void testLiteralWithStrings() throws Exception {
- Expression e = ExpressionFactory.createExpression( "[ 'foo' => 'bar' ]" );
+ Expression e = JEXL.createExpression( "[ 'foo' => 'bar' ]" );
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate( jc );
@@ -37,10 +37,10 @@
}
public void testLiteralWithMultipleEntries() throws Exception {
- Expression e = ExpressionFactory.createExpression( "[ 'foo' => 'bar', 'eat' => 'food' ]" );
+ Expression e = JEXL.createExpression( "[ 'foo' => 'bar', 'eat' => 'food' ]" );
JexlContext jc = JexlHelper.createContext();
- Map expected = new HashMap();
+ Map<String, String> expected = new HashMap<String, String>();
expected.put( "foo", "bar" );
expected.put( "eat", "food" );
@@ -49,7 +49,7 @@
}
public void testLiteralWithNumbers() throws Exception {
- Expression e = ExpressionFactory.createExpression( "[ 5 => 10 ]" );
+ Expression e = JEXL.createExpression( "[ 5 => 10 ]" );
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate( jc );
@@ -57,7 +57,7 @@
}
public void testSizeOfSimpleMapLiteral() throws Exception {
- Expression e = ExpressionFactory.createExpression( "size([ 'foo' => 'bar' ])" );
+ Expression e = JEXL.createExpression( "size([ 'foo' => 'bar' ])" );
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate( jc );
@@ -65,7 +65,7 @@
}
public void testCallingMethodsOnNewMapLiteral() throws Exception {
- Expression e = ExpressionFactory.createExpression( "size([ 'foo' => 'bar' ].values())" );
+ Expression e = JEXL.createExpression( "size([ 'foo' => 'bar' ].values())" );
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate( jc );
@@ -73,7 +73,7 @@
}
public void testNotEmptySimpleMapLiteral() throws Exception {
- Expression e = ExpressionFactory.createExpression( "empty([ 'foo' => 'bar' ])" );
+ Expression e = JEXL.createExpression( "empty([ 'foo' => 'bar' ])" );
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate( jc );
Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ParseFailuresTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ParseFailuresTest.java?rev=800842&r1=800841&r2=800842&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ParseFailuresTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ParseFailuresTest.java Tue Aug 4 15:29:32 2009
@@ -20,7 +20,7 @@
/**
* Tests for malformed expressions and scripts.
- * ({@link ExpressionFactory} and {@link ScriptFactory} should throw
+ * ({@link JexlEngine#createExpression(String)} and {@link JexlEngine#createScript(String)} should throw
* {@link ParseException}s).
*
* @since 1.1
@@ -40,7 +40,7 @@
// this will throw a ParseException
String badExpression = "eq";
try {
- ExpressionFactory.createExpression(badExpression);
+ JEXL.createExpression(badExpression);
fail("Parsing \"" + badExpression
+ "\" should result in a ParseException");
} catch (ParseException pe) {
@@ -52,7 +52,7 @@
// this will throw a TokenMgrErr, which we rethrow as a ParseException
String badExpression = "?";
try {
- ExpressionFactory.createExpression(badExpression);
+ JEXL.createExpression(badExpression);
fail("Parsing \"" + badExpression
+ "\" should result in a ParseException");
} catch (ParseException pe) {
@@ -64,7 +64,7 @@
// this will throw a TokenMgrErr, which we rethrow as a ParseException
String badScript = "eq";
try {
- ScriptFactory.createScript(badScript);
+ JEXL.createScript(badScript);
fail("Parsing \"" + badScript
+ "\" should result in a ParseException");
} catch (ParseException pe) {
@@ -77,7 +77,7 @@
// this will throw a TokenMgrErr, which we rethrow as a ParseException
String badScript = "?";
try {
- ScriptFactory.createScript(badScript);
+ JEXL.createScript(badScript);
fail("Parsing \"" + badScript
+ "\" should result in a ParseException");
} catch (ParseException pe) {
@@ -89,7 +89,7 @@
// this will throw a TokenMgrErr, which we rethrow as a ParseException
String badScript = "foo=1;bar=2;a?b:c:d;";
try {
- ScriptFactory.createScript(badScript);
+ JEXL.createScript(badScript);
fail("Parsing \"" + badScript
+ "\" should result in a ParseException");
} catch (ParseException pe) {
Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ScriptTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ScriptTest.java?rev=800842&r1=800841&r2=800842&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ScriptTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ScriptTest.java Tue Aug 4 15:29:32 2009
@@ -53,7 +53,7 @@
*/
public void testSimpleScript() throws Exception {
String code = "while (x < 10) x = x + 1;";
- Script s = ScriptFactory.createScript(code);
+ Script s = JEXL.createScript(code);
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("x", new Integer(1));
@@ -64,7 +64,7 @@
public void testScriptFromFile() throws Exception {
File testScript = new File(TEST1);
- Script s = ScriptFactory.createScript(testScript);
+ Script s = JEXL.createScript(testScript);
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("out", System.out);
Object result = s.execute(jc);
@@ -74,7 +74,7 @@
public void testScriptFromURL() throws Exception {
URL testUrl = new File("src/test/scripts/test1.jexl").toURI().toURL();
- Script s = ScriptFactory.createScript(testUrl);
+ Script s = JEXL.createScript(testUrl);
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("out", System.out);
Object result = s.execute(jc);
@@ -84,8 +84,8 @@
public void testScriptUpdatesContext() throws Exception {
String jexlCode = "resultat.setCode('OK')";
- Expression e = ExpressionFactory.createExpression(jexlCode);
- Script s = ScriptFactory.createScript(jexlCode);
+ Expression e = JEXL.createExpression(jexlCode);
+ Script s = JEXL.createScript(jexlCode);
Tester resultatJexl = new Tester();
JexlContext jc = JexlHelper.createContext();
Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/WhileTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/WhileTest.java?rev=800842&r1=800841&r2=800842&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/WhileTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/WhileTest.java Tue Aug 4 15:29:32 2009
@@ -29,7 +29,7 @@
}
public void testSimpleWhileFalse() throws Exception {
- Expression e = ExpressionFactory.createExpression("while (false) ;");
+ Expression e = JEXL.createExpression("while (false) ;");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
@@ -37,7 +37,7 @@
}
public void testWhileExecutesExpressionWhenLooping() throws Exception {
- Expression e = ExpressionFactory.createExpression("while (x < 10) x = x + 1;");
+ Expression e = JEXL.createExpression("while (x < 10) x = x + 1;");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("x", new Integer(1));
@@ -46,7 +46,7 @@
}
public void testWhileWithBlock() throws Exception {
- Expression e = ExpressionFactory.createExpression("while (x < 10) { x = x + 1; y = y * 2; }");
+ Expression e = JEXL.createExpression("while (x < 10) { x = x + 1; y = y * 2; }");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("x", new Integer(1));
jc.getVars().put("y", new Integer(1));