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 2015/06/10 18:30:17 UTC
svn commit: r1684706 [4/5] - in /commons/proper/jexl/trunk: ./
src/main/java/org/apache/commons/jexl3/
src/main/java/org/apache/commons/jexl3/annotations/
src/main/java/org/apache/commons/jexl3/internal/
src/main/java/org/apache/commons/jexl3/internal/...
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/LambdaTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/LambdaTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/LambdaTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/LambdaTest.java Wed Jun 10 16:30:16 2015
@@ -20,14 +20,17 @@ import org.apache.commons.jexl3.internal
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
+import org.junit.Assert;
+import org.junit.Test;
/**
* Tests function/lambda/closure features.
*/
+@SuppressWarnings({"UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"})
public class LambdaTest extends JexlTestCase {
- public LambdaTest(String testName) {
- super(testName);
+ public LambdaTest() {
+ super("LambdaTest");
}
public void testScriptArguments() throws Exception {
@@ -35,100 +38,107 @@ public class LambdaTest extends JexlTest
JexlScript s = jexl.createScript(" x + x ", "x");
JexlScript s42 = jexl.createScript("s(21)", "s");
Object result = s42.execute(null, s);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
}
+ @Test
public void testScriptContext() throws Exception {
JexlEngine jexl = new Engine();
JexlScript s = jexl.createScript("function(x) { x + x }");
String fsstr = s.getParsedText();
- assertEquals("(x)->{ x + x; }", fsstr);
- assertEquals(42, s.execute(null, 21));
+ Assert.assertEquals("(x)->{ x + x; }", fsstr);
+ Assert.assertEquals(42, s.execute(null, 21));
JexlScript s42 = jexl.createScript("s(21)");
JexlEvalContext ctxt = new JexlEvalContext();
ctxt.set("s", s);
Object result = s42.execute(ctxt);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
result = s42.execute(ctxt);
- assertEquals(42, result);
- s = jexl.createScript("x-> { x + x }");
- result = s42.execute(ctxt);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
+ s42 = jexl.createScript("x-> { x + x }");
+ result = s42.execute(ctxt, 21);
+ Assert.assertEquals(42, result);
}
+ @Test
public void testLambda() throws Exception {
JexlEngine jexl = new Engine();
String strs = "var s = function(x) { x + x }; s(21)";
JexlScript s42 = jexl.createScript(strs);
Object result = s42.execute(null);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
strs = "var s = function(x, y) { x + y }; s(15, 27)";
s42 = jexl.createScript(strs);
result = s42.execute(null);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
}
+ @Test
public void testLambdaClosure() throws Exception {
JexlEngine jexl = new Engine();
String strs = "var t = 20; var s = function(x, y) { x + y + t}; s(15, 7)";
JexlScript s42 = jexl.createScript(strs);
Object result = s42.execute(null);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
strs = "var t = 19; var s = function(x, y) { var t = 20; x + y + t}; s(15, 7)";
s42 = jexl.createScript(strs);
result = s42.execute(null);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
strs = "var t = 20; var s = function(x, y) {x + y + t}; t = 54; s(15, 7)";
s42 = jexl.createScript(strs);
result = s42.execute(null);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
strs = "var t = 19; var s = function(x, y) { var t = 20; x + y + t}; t = 54; s(15, 7)";
s42 = jexl.createScript(strs);
result = s42.execute(null);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
}
+ @Test
public void testLambdaLambda() throws Exception {
JexlEngine jexl = new Engine();
String strs = "var t = 19; ( (x, y)->{ var t = 20; x + y + t} )(15, 7);";
JexlScript s42 = jexl.createScript(strs);
Object result = s42.execute(null);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
strs = "( (x, y)->{ ( (xx, yy)->{xx + yy } )(x, y) } )(15, 27)";
s42 = jexl.createScript(strs);
result = s42.execute(null);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
strs = "var t = 19; var s = (x, y)->{ var t = 20; x + y + t}; t = 54; s(15, 7)";
s42 = jexl.createScript(strs);
result = s42.execute(null);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
}
+ @Test
public void testNestLambda() throws Exception {
JexlEngine jexl = new Engine();
String strs = "( (x)->{ (y)->{ x + y } })(15)(27)";
JexlScript s42 = jexl.createScript(strs);
Object result = s42.execute(null);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
}
+ @Test
public void testNestLambada() throws Exception {
JexlEngine jexl = new Engine();
JexlContext ctx = null;
String strs = "(x)->{ (y)->{ x + y } }";
JexlScript s42 = jexl.createScript(strs);
Object result = s42.execute(ctx, 15);
- assertTrue(result instanceof JexlScript);
+ Assert.assertTrue(result instanceof JexlScript);
JexlScript s15 = (JexlScript) result;
Callable<Object> s15b = s15.callable(ctx, 27);
result = s15.execute(ctx, 27);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
result = s15b.call();
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
}
+ @Test
public void testHoistLambada() throws Exception {
JexlEngine jexl = new Engine();
JexlContext ctx = null;
@@ -143,39 +153,41 @@ public class LambdaTest extends JexlTest
strs = "(x)->{ (y)->{ x + y } }";
s42 = jexl.createScript(strs);
result = s42.execute(ctx, 15);
- assertTrue(result instanceof JexlScript);
+ Assert.assertTrue(result instanceof JexlScript);
s15 = (JexlScript) result;
localv = s15.getLocalVariables();
- assertNull(localv);
+ Assert.assertNull(localv);
hvars = s15.getVariables();
- assertEquals(1, hvars.size());
+ Assert.assertEquals(1, hvars.size());
// declaring a local that overrides hoisted
strs = "(x)->{ (y)->{ var x; x + y } }";
s42 = jexl.createScript(strs);
result = s42.execute(ctx, 15);
- assertTrue(result instanceof JexlScript);
+ Assert.assertTrue(result instanceof JexlScript);
s15 = (JexlScript) result;
localv = s15.getLocalVariables();
- assertNotNull(localv);
- assertEquals(1, localv.length);
+ Assert.assertNotNull(localv);
+ Assert.assertEquals(1, localv.length);
hvars = s15.getVariables();
- assertEquals(0, hvars.size());
+ Assert.assertEquals(0, hvars.size());
}
+ @Test
public void testRecurse() throws Exception {
JexlEngine jexl = new Engine();
JexlContext jc = new MapContext();
try {
JexlScript script = jexl.createScript("var fact = (x)->{ if (x <= 1) 1; else x * fact(x - 1) }; fact(5)");
int result = (Integer) script.execute(jc);
- assertEquals(120, result);
+ Assert.assertEquals(120, result);
} catch (JexlException xany) {
String msg = xany.toString();
throw xany;
}
}
+ @Test
public void testRecurse2() throws Exception {
JexlEngine jexl = new Engine();
JexlContext jc = new MapContext();
@@ -185,13 +197,14 @@ public class LambdaTest extends JexlTest
"var y = 1; var z = 1; "
+"var fact = (x)->{ if (x <= y) z; else x * fact(x - 1) }; fact(6)");
int result = (Integer) script.execute(jc);
- assertEquals(720, result);
+ Assert.assertEquals(720, result);
} catch (JexlException xany) {
String msg = xany.toString();
throw xany;
}
}
+ @Test
public void testRecurse3() throws Exception {
JexlEngine jexl = new Engine();
JexlContext jc = new MapContext();
@@ -201,10 +214,22 @@ public class LambdaTest extends JexlTest
"var y = 1; var z = 1;var foo = (x)->{y + z}; "
+"var fact = (x)->{ if (x <= y) z; else x * fact(x - 1) }; fact(6)");
int result = (Integer) script.execute(jc);
- assertEquals(720, result);
+ Assert.assertEquals(720, result);
} catch (JexlException xany) {
String msg = xany.toString();
throw xany;
}
}
+
+ @Test
+ public void testIdentity() throws Exception {
+ JexlEngine jexl = new Engine();
+ JexlScript script;
+ Object result;
+
+ script = jexl.createScript("(x)->{ x }");
+ Assert.assertArrayEquals(new String[]{"x"}, script.getParameters());
+ result = script.execute(null, 42);
+ Assert.assertEquals(42, result);
+ }
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java Wed Jun 10 16:30:16 2015
@@ -19,131 +19,147 @@ package org.apache.commons.jexl3;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import org.junit.Assert;
+import org.junit.Test;
/**
* Tests for map literals
- *
* @since 1.2
*/
+@SuppressWarnings({"UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"})
public class MapLiteralTest extends JexlTestCase {
public MapLiteralTest() {
super("MapLiteralTest");
}
+ @Test
public void testLiteralWithStrings() throws Exception {
- JexlExpression e = JEXL.createExpression( "{ 'foo' : 'bar' }" );
+ JexlExpression e = JEXL.createExpression("{ 'foo' : 'bar' }");
JexlContext jc = new MapContext();
- Object o = e.evaluate( jc );
- assertEquals( Collections.singletonMap( "foo", "bar" ), o );
+ Object o = e.evaluate(jc);
+ Assert.assertEquals(Collections.singletonMap("foo", "bar"), o);
}
+ @Test
public void testLiteralWithMultipleEntries() throws Exception {
- JexlExpression e = JEXL.createExpression( "{ 'foo' : 'bar', 'eat' : 'food' }" );
+ JexlExpression e = JEXL.createExpression("{ 'foo' : 'bar', 'eat' : 'food' }");
JexlContext jc = new MapContext();
Map<String, String> expected = new HashMap<String, String>();
- expected.put( "foo", "bar" );
- expected.put( "eat", "food" );
+ expected.put("foo", "bar");
+ expected.put("eat", "food");
- Object o = e.evaluate( jc );
- assertEquals( expected, o );
+ Object o = e.evaluate(jc);
+ Assert.assertEquals(expected, o);
}
+ @Test
public void testLiteralWithNumbers() throws Exception {
- JexlExpression e = JEXL.createExpression( "{ 5 : 10 }" );
+ JexlExpression e = JEXL.createExpression("{ 5 : 10 }");
JexlContext jc = new MapContext();
- Object o = e.evaluate( jc );
- assertEquals( Collections.singletonMap( new Integer( 5 ), new Integer( 10 ) ), o );
+ Object o = e.evaluate(jc);
+ Assert.assertEquals(Collections.singletonMap(new Integer(5), new Integer(10)), o);
e = JEXL.createExpression("m = { 3 : 30, 4 : 40, 5 : 'fifty', '7' : 'seven', 7 : 'SEVEN' }");
e.evaluate(jc);
e = JEXL.createExpression("m.3");
o = e.evaluate(jc);
- assertEquals(new Integer(30), o);
+ Assert.assertEquals(new Integer(30), o);
e = JEXL.createExpression("m[4]");
o = e.evaluate(jc);
- assertEquals(new Integer(40), o);
+ Assert.assertEquals(new Integer(40), o);
jc.set("i", Integer.valueOf(5));
e = JEXL.createExpression("m[i]");
o = e.evaluate(jc);
- assertEquals("fifty", o);
+ Assert.assertEquals("fifty", o);
e = JEXL.createExpression("m.3 = 'thirty'");
e.evaluate(jc);
e = JEXL.createExpression("m.3");
o = e.evaluate(jc);
- assertEquals("thirty", o);
+ Assert.assertEquals("thirty", o);
e = JEXL.createExpression("m['7']");
o = e.evaluate(jc);
- assertEquals("seven", o);
+ Assert.assertEquals("seven", o);
e = JEXL.createExpression("m.7");
o = e.evaluate(jc);
- assertEquals("SEVEN", o);
+ Assert.assertEquals("SEVEN", o);
jc.set("k", Integer.valueOf(7));
e = JEXL.createExpression("m[k]");
o = e.evaluate(jc);
- assertEquals("SEVEN", o);
+ Assert.assertEquals("SEVEN", o);
jc.set("k", "7");
e = JEXL.createExpression("m[k]");
o = e.evaluate(jc);
- assertEquals("seven", o);
+ Assert.assertEquals("seven", o);
}
+ @Test
public void testSizeOfSimpleMapLiteral() throws Exception {
- JexlExpression e = JEXL.createExpression( "size({ 'foo' : 'bar' })" );
+ JexlExpression e = JEXL.createExpression("size({ 'foo' : 'bar' })");
JexlContext jc = new MapContext();
- Object o = e.evaluate( jc );
- assertEquals( new Integer( 1 ), o );
+ Object o = e.evaluate(jc);
+ Assert.assertEquals(new Integer(1), o);
}
+ @Test
public void testCallingMethodsOnNewMapLiteral() throws Exception {
- JexlExpression e = JEXL.createExpression( "size({ 'foo' : 'bar' }.values())" );
+ JexlExpression e = JEXL.createExpression("size({ 'foo' : 'bar' }.values())");
JexlContext jc = new MapContext();
- Object o = e.evaluate( jc );
- assertEquals( new Integer( 1 ), o );
+ Object o = e.evaluate(jc);
+ Assert.assertEquals(new Integer(1), o);
}
+ @Test
public void testNotEmptySimpleMapLiteral() throws Exception {
- JexlExpression e = JEXL.createExpression( "empty({ 'foo' : 'bar' })" );
+ JexlExpression e = JEXL.createExpression("empty({ 'foo' : 'bar' })");
JexlContext jc = new MapContext();
- Object o = e.evaluate( jc );
- assertFalse( ( (Boolean) o ).booleanValue() );
+ Object o = e.evaluate(jc);
+ Assert.assertFalse(((Boolean) o).booleanValue());
}
+ @Test
public void testMapMapLiteral() throws Exception {
- JexlExpression e = JEXL.createExpression( "{'foo' : { 'inner' : 'bar' }}" );
+ JexlExpression e = JEXL.createExpression("{'foo' : { 'inner' : 'bar' }}");
JexlContext jc = new MapContext();
- Object o = e.evaluate( jc );
- assertNotNull(o);
+ Object o = e.evaluate(jc);
+ Assert.assertNotNull(o);
jc.set("outer", o);
e = JEXL.createExpression("outer.foo.inner");
- o = e.evaluate( jc );
- assertEquals( "bar", o );
+ o = e.evaluate(jc);
+ Assert.assertEquals("bar", o);
}
+ @Test
public void testMapArrayLiteral() throws Exception {
- JexlExpression e = JEXL.createExpression( "{'foo' : [ 'inner' , 'bar' ]}" );
+ JexlExpression e = JEXL.createExpression("{'foo' : [ 'inner' , 'bar' ]}");
JexlContext jc = new MapContext();
- Object o = e.evaluate( jc );
- assertNotNull(o);
+ Object o = e.evaluate(jc);
+ Assert.assertNotNull(o);
jc.set("outer", o);
e = JEXL.createExpression("outer.foo.1");
- o = e.evaluate( jc );
- assertEquals( "bar", o );
+ o = e.evaluate(jc);
+ Assert.assertEquals("bar", o);
}
+ @Test
+ public void testEmptyMap() throws Exception {
+ JexlScript script = JEXL.createScript("map['']", "map");
+ Object result = script.execute(null, Collections.singletonMap("", 42));
+ Assert.assertEquals(42, result);
+ }
}
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=1684706&r1=1684705&r2=1684706&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 Wed Jun 10 16:30:16 2015
@@ -21,12 +21,16 @@ import java.util.Map;
import org.apache.commons.jexl3.introspection.JexlMethod;
import org.apache.commons.jexl3.junit.Asserter;
import java.util.Arrays;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests for calling methods on objects
*
* @since 2.0
*/
+@SuppressWarnings({"UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"})
public class MethodTest extends JexlTestCase {
private Asserter asserter;
private static final String METHOD_STRING = "Method string";
@@ -80,7 +84,7 @@ public class MethodTest extends JexlTest
public String concat(String... strs) {
if (strs.length > 0) {
StringBuilder strb = new StringBuilder(strs[0]);
- for(int s = 1; s < strs.length; ++s) {
+ for (int s = 1; s < strs.length; ++s) {
strb.append(", ");
strb.append(strs[s]);
}
@@ -119,48 +123,52 @@ public class MethodTest extends JexlTest
}
}
+ @Before
@Override
public void setUp() {
asserter = new Asserter(JEXL);
}
+ @Test
public void testCallVarArgMethod() throws Exception {
VarArgs test = new VarArgs();
asserter.setVariable("test", test);
asserter.assertExpression("test.callInts()", test.callInts());
asserter.assertExpression("test.callInts(1)", test.callInts(1));
- asserter.assertExpression("test.callInts(1,2,3,4,5)", test.callInts(1,2,3,4,5));
+ asserter.assertExpression("test.callInts(1,2,3,4,5)", test.callInts(1, 2, 3, 4, 5));
asserter.assertExpression("test.concat(['1', '2', '3'])", test.concat(new String[]{"1", "2", "3"}));
asserter.assertExpression("test.concat('1', '2', '3')", test.concat("1", "2", "3"));
}
+ @Test
public void testCallMixedVarArgMethod() throws Exception {
VarArgs test = new VarArgs();
asserter.setVariable("test", test);
- assertEquals("Mixed:1", test.callMixed(Integer.valueOf(1)));
+ Assert.assertEquals("Mixed:1", test.callMixed(Integer.valueOf(1)));
asserter.assertExpression("test.callMixed(1)", test.callMixed(1));
// Java and JEXL equivalent behavior: 'Mixed:-999' expected
//{
- assertEquals("Mixed:-999", test.callMixed(Integer.valueOf(1), (Integer[]) null));
+ Assert.assertEquals("Mixed:-999", test.callMixed(Integer.valueOf(1), (Integer[]) null));
asserter.assertExpression("test.callMixed(1, null)", "Mixed:-999");
//}
- asserter.assertExpression("test.callMixed(1,2)", test.callMixed(1,2));
- asserter.assertExpression("test.callMixed(1,2,3,4,5)", test.callMixed(1,2,3,4,5));
+ asserter.assertExpression("test.callMixed(1,2)", test.callMixed(1, 2));
+ asserter.assertExpression("test.callMixed(1,2,3,4,5)", test.callMixed(1, 2, 3, 4, 5));
}
+ @Test
public void testCallJexlVarArgMethod() throws Exception {
VarArgs test = new VarArgs();
asserter.setVariable("test", test);
- assertEquals("jexl:0", test.callMixed("jexl"));
+ Assert.assertEquals("jexl:0", test.callMixed("jexl"));
asserter.assertExpression("test.callMixed('jexl')", "jexl:0");
// Java and JEXL equivalent behavior: 'jexl:-1000' expected
//{
- assertEquals("jexl:-1000", test.callMixed("jexl", (Integer[]) null));
+ Assert.assertEquals("jexl:-1000", test.callMixed("jexl", (Integer[]) null));
asserter.assertExpression("test.callMixed('jexl', null)", "jexl:-1000");
//}
asserter.assertExpression("test.callMixed('jexl', 2)", test.callMixed("jexl", 2));
- asserter.assertExpression("test.callMixed('jexl',2,3,4,5)", test.callMixed("jexl",2,3,4,5));
+ asserter.assertExpression("test.callMixed('jexl',2,3,4,5)", test.callMixed("jexl", 2, 3, 4, 5));
}
public static class Functor {
@@ -185,19 +193,20 @@ public class MethodTest extends JexlTest
}
}
+ @Test
public void testInvoke() throws Exception {
Functor func = new Functor();
- assertEquals(Integer.valueOf(10), JEXL.invokeMethod(func, "ten"));
- assertEquals(Integer.valueOf(42), JEXL.invokeMethod(func, "PLUS20", Integer.valueOf(22)));
+ Assert.assertEquals(Integer.valueOf(10), JEXL.invokeMethod(func, "ten"));
+ Assert.assertEquals(Integer.valueOf(42), JEXL.invokeMethod(func, "PLUS20", Integer.valueOf(22)));
try {
JEXL.invokeMethod(func, "nonExistentMethod");
- fail("method does not exist!");
+ Assert.fail("method does not exist!");
} catch (Exception xj0) {
// ignore
}
try {
JEXL.invokeMethod(func, "NPEIfNull", (Object[]) null);
- fail("method should have thrown!");
+ Assert.fail("method should have thrown!");
} catch (Exception xj0) {
// ignore
}
@@ -206,12 +215,14 @@ public class MethodTest extends JexlTest
/**
* test a simple method expression
*/
+ @Test
public void testMethod() throws Exception {
// tests a simple method expression
asserter.setVariable("foo", new Foo());
asserter.assertExpression("foo.bar()", METHOD_STRING);
}
+ @Test
public void testMulti() throws Exception {
asserter.setVariable("foo", new Foo());
asserter.assertExpression("foo.innerFoo.bar()", METHOD_STRING);
@@ -220,6 +231,7 @@ public class MethodTest extends JexlTest
/**
* test some String method calls
*/
+ @Test
public void testStringMethods() throws Exception {
asserter.setVariable("foo", "abcdef");
asserter.assertExpression("foo.substring(3)", "def");
@@ -232,11 +244,13 @@ public class MethodTest extends JexlTest
/**
* Ensures static methods on objects can be called.
*/
+ @Test
public void testStaticMethodInvocation() throws Exception {
asserter.setVariable("aBool", Boolean.FALSE);
asserter.assertExpression("aBool.valueOf('true')", Boolean.TRUE);
}
+ @Test
public void testStaticMethodInvocationOnClasses() throws Exception {
asserter.setVariable("Boolean", Boolean.class);
asserter.assertExpression("Boolean.valueOf('true')", Boolean.TRUE);
@@ -248,6 +262,7 @@ public class MethodTest extends JexlTest
}
}
+ @Test
public void testTopLevelCall() throws Exception {
java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
funcs.put(null, new Functor());
@@ -258,26 +273,27 @@ public class MethodTest extends JexlTest
JexlExpression e = JEXL.createExpression("ten()");
Object o = e.evaluate(jc);
- assertEquals("Result is not 10", new Integer(10), o);
+ Assert.assertEquals("Result is not 10", new Integer(10), o);
e = JEXL.createExpression("plus10(10)");
o = e.evaluate(jc);
- assertEquals("Result is not 20", new Integer(20), o);
+ Assert.assertEquals("Result is not 20", new Integer(20), o);
e = JEXL.createExpression("plus10(ten())");
o = e.evaluate(jc);
- assertEquals("Result is not 20", new Integer(20), o);
+ Assert.assertEquals("Result is not 20", new Integer(20), o);
jc.set("pi", new Double(Math.PI));
e = JEXL.createExpression("math:cos(pi)");
o = e.evaluate(jc);
- assertEquals(Double.valueOf(-1), o);
+ Assert.assertEquals(Double.valueOf(-1), o);
e = JEXL.createExpression("cx:ratio(10) + cx:ratio(20)");
o = e.evaluate(jc);
- assertEquals(Integer.valueOf(7), o);
+ Assert.assertEquals(Integer.valueOf(7), o);
}
+ @Test
public void testNamespaceCall() throws Exception {
java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
funcs.put("func", new Functor());
@@ -287,27 +303,28 @@ public class MethodTest extends JexlTest
JexlEvalContext jc = new EnhancedContext(funcs);
Object o = e.evaluate(jc);
- assertEquals("Result is not 10", new Integer(10), o);
+ Assert.assertEquals("Result is not 10", new Integer(10), o);
e = JEXL.createExpression("func:plus10(10)");
o = e.evaluate(jc);
- assertEquals("Result is not 20", new Integer(20), o);
+ Assert.assertEquals("Result is not 20", new Integer(20), o);
e = JEXL.createExpression("func:plus10(func:ten())");
o = e.evaluate(jc);
- assertEquals("Result is not 20", new Integer(20), o);
+ Assert.assertEquals("Result is not 20", new Integer(20), o);
e = JEXL.createExpression("FUNC:PLUS20(10)");
o = e.evaluate(jc);
- assertEquals("Result is not 30", new Integer(30), o);
+ Assert.assertEquals("Result is not 30", new Integer(30), o);
e = JEXL.createExpression("FUNC:PLUS20(FUNC:TWENTY())");
o = e.evaluate(jc);
- assertEquals("Result is not 40", new Integer(40), o);
+ Assert.assertEquals("Result is not 40", new Integer(40), o);
}
public static class Edge {
- private Edge() {}
+ private Edge() {
+ }
public int exec(int arg) {
return 1;
@@ -355,8 +372,8 @@ public class MethodTest extends JexlTest
public Class<?>[] execute(Object... args) {
Class<?>[] clazz = new Class<?>[args.length];
- for(int a = 0; a < args.length; ++a) {
- clazz[a] = args[a] != null? args[a].getClass() : Void.class;
+ for (int a = 0; a < args.length; ++a) {
+ clazz[a] = args[a] != null ? args[a].getClass() : Void.class;
}
return clazz;
}
@@ -371,7 +388,7 @@ public class MethodTest extends JexlTest
return false;
}
-
+ @Test
public void testNamespaceCallEdge() throws Exception {
java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
Edge func = new Edge();
@@ -385,57 +402,57 @@ public class MethodTest extends JexlTest
for (int i = 0; i < 2; ++i) {
e = JEXL.createExpression("func:exec([1, 2])");
o = e.evaluate(jc);
- assertEquals("exec(int[] arg): " + i, 20, o);
+ Assert.assertEquals("exec(int[] arg): " + i, 20, o);
e = JEXL.createExpression("func:exec(1, 2)");
o = e.evaluate(jc);
- assertEquals("exec(Object... args): " + i, 4, o);
+ Assert.assertEquals("exec(Object... args): " + i, 4, o);
e = JEXL.createExpression("func:exec([10.0, 20.0])");
o = e.evaluate(jc);
- assertEquals("exec(Object args): " + i, 3, o);
+ Assert.assertEquals("exec(Object args): " + i, 3, o);
e = JEXL.createExpression("func:exec('1', 2)");
o = e.evaluate(jc);
- assertEquals("exec(Object... args): " + i, 4, o);
+ Assert.assertEquals("exec(Object... args): " + i, 4, o);
// no way to differentiate between a single arg call with an array and a vararg call with same args
- assertEquals("exec(String... args): " + i, func.exec("1", "2"), func.exec(new String[]{"1", "2"}));
+ Assert.assertEquals("exec(String... args): " + i, func.exec("1", "2"), func.exec(new String[]{"1", "2"}));
e = JEXL.createExpression("func:exec(['1', '2'])");
o = e.evaluate(jc);
- assertEquals("exec(String... args): " + i, func.exec(new String[]{"1", "2"}), o);
+ Assert.assertEquals("exec(String... args): " + i, func.exec(new String[]{"1", "2"}), o);
e = JEXL.createExpression("func:exec('1', '2')");
o = e.evaluate(jc);
- assertEquals("exec(String... args): " + i, func.exec("1", "2"), o);
+ Assert.assertEquals("exec(String... args): " + i, func.exec("1", "2"), o);
e = JEXL.createExpression("func:exec(true, [1, 2])");
o = e.evaluate(jc);
- assertEquals("exec(int[] arg): " + i, 20, o);
+ Assert.assertEquals("exec(int[] arg): " + i, 20, o);
e = JEXL.createExpression("func:exec(true, 1, 2)");
o = e.evaluate(jc);
- assertEquals("exec(Object... args): " + i, 4, o);
+ Assert.assertEquals("exec(Object... args): " + i, 4, o);
e = JEXL.createExpression("func:exec(true, ['1', '2'])");
o = e.evaluate(jc);
- assertEquals("exec(Object args): " + i, 3, o);
+ Assert.assertEquals("exec(Object args): " + i, 3, o);
e = JEXL.createExpression("func:exec(true, '1', '2')");
o = e.evaluate(jc);
- assertEquals("exec(Object... args): " + i, 4, o);
+ Assert.assertEquals("exec(Object... args): " + i, 4, o);
e = JEXL.createExpression("func:execute(true, '1', '2')");
o = e.evaluate(jc);
c = func.execute(Boolean.TRUE, "1", "2");
- assertTrue("execute(Object... args): " + i, eqExecute(o, c));
+ Assert.assertTrue("execute(Object... args): " + i, eqExecute(o, c));
e = JEXL.createExpression("func:execute([true])");
o = e.evaluate(jc);
c = func.execute(new boolean[]{true});
- assertTrue("execute(Object... args): " + i, eqExecute(o, c));
+ Assert.assertTrue("execute(Object... args): " + i, eqExecute(o, c));
}
} catch (JexlException xjexl) {
- fail(xjexl.toString());
+ Assert.fail(xjexl.toString());
}
}
@@ -472,25 +489,26 @@ public class MethodTest extends JexlTest
}
}
+ @Test
public void testScriptCall() throws Exception {
JexlContext context = new MapContext();
JexlScript plus = JEXL.createScript("a + b", new String[]{"a", "b"});
context.set("plus", plus);
JexlScript forty2 = JEXL.createScript("plus(4, 2) * plus(4, 3)");
Object o = forty2.execute(context);
- assertEquals("Result is not 42", new Integer(42), o);
+ Assert.assertEquals("Result is not 42", new Integer(42), o);
Map<String, Object> foo = new HashMap<String, Object>();
foo.put("plus", plus);
context.set("foo", foo);
forty2 = JEXL.createScript("foo.plus(4, 2) * foo.plus(4, 3)");
o = forty2.execute(context);
- assertEquals("Result is not 42", new Integer(42), o);
+ Assert.assertEquals("Result is not 42", new Integer(42), o);
context = new ScriptContext(foo);
forty2 = JEXL.createScript("script:plus(4, 2) * script:plus(4, 3)");
o = forty2.execute(context);
- assertEquals("Result is not 42", new Integer(42), o);
+ Assert.assertEquals("Result is not 42", new Integer(42), o);
final JexlArithmetic ja = JEXL.getArithmetic();
JexlMethod mplus = new JexlMethod() {
@@ -535,30 +553,30 @@ public class MethodTest extends JexlTest
foo.put("PLUS", mplus);
forty2 = JEXL.createScript("script:PLUS(4, 2) * script:PLUS(4, 3)");
o = forty2.execute(context);
- assertEquals("Result is not 42", new Integer(42), o);
+ Assert.assertEquals("Result is not 42", new Integer(42), o);
context.set("foo.bar", foo);
forty2 = JEXL.createScript("foo.'bar'.PLUS(4, 2) * foo.bar.PLUS(4, 3)");
o = forty2.execute(context);
- assertEquals("Result is not 42", new Integer(42), o);
+ Assert.assertEquals("Result is not 42", new Integer(42), o);
}
-
+ @Test
public void testFizzCall() throws Exception {
ScriptContext context = new ScriptContext(new HashMap<String, Object>());
JexlScript bar = JEXL.createScript("functor:get('drink')");
Object o;
o = bar.execute(context);
- assertEquals("Wrong choice", "champaign", o);
+ Assert.assertEquals("Wrong choice", "champaign", o);
context.set("base", "gin");
o = bar.execute(context);
- assertEquals("Wrong choice", "gin fizz", o);
+ Assert.assertEquals("Wrong choice", "gin fizz", o);
// despite being called twice, the functor is created only once.
context.set("base", "wine");
bar = JEXL.createScript("var glass = functor:get('drink'); base = 'gin'; functor:get('drink')");
o = bar.execute(context);
- assertEquals("Wrong choice", "champaign", o);
+ Assert.assertEquals("Wrong choice", "champaign", o);
}
-}
\ No newline at end of file
+}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ParseFailuresTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ParseFailuresTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ParseFailuresTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ParseFailuresTest.java Wed Jun 10 16:30:16 2015
@@ -1,12 +1,12 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
+ * 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
+ * the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -18,6 +18,8 @@ package org.apache.commons.jexl3;
import org.apache.log4j.Logger;
import org.apache.log4j.LogManager;
+import org.junit.Assert;
+import org.junit.Test;
/**
* Tests for malformed expressions and scripts.
@@ -30,6 +32,7 @@ import org.apache.log4j.LogManager;
public class ParseFailuresTest extends JexlTestCase {
static final Logger LOGGER = LogManager.getLogger(ParseFailuresTest.class.getName());
+
/**
* Create the test.
*
@@ -39,66 +42,70 @@ public class ParseFailuresTest extends J
super("ParseFailuresTest");
}
+ @Test
public void testMalformedExpression1() throws Exception {
// this will throw a JexlException
String badExpression = "eq";
try {
JEXL.createExpression(badExpression);
- fail("Parsing \"" + badExpression
- + "\" should result in a JexlException");
+ Assert.fail("Parsing \"" + badExpression
+ + "\" should result in a JexlException");
} catch (JexlException pe) {
// expected
LOGGER.info(pe);
}
}
+ @Test
public void testMalformedExpression2() throws Exception {
// this will throw a TokenMgrErr, which we rethrow as a JexlException
String badExpression = "?";
try {
JEXL.createExpression(badExpression);
- fail("Parsing \"" + badExpression
- + "\" should result in a JexlException");
+ Assert.fail("Parsing \"" + badExpression
+ + "\" should result in a JexlException");
} catch (JexlException pe) {
// expected
LOGGER.info(pe);
}
}
+ @Test
public void testMalformedScript1() throws Exception {
// this will throw a TokenMgrErr, which we rethrow as a JexlException
String badScript = "eq";
try {
JEXL.createScript(badScript);
- fail("Parsing \"" + badScript
- + "\" should result in a JexlException");
+ Assert.fail("Parsing \"" + badScript
+ + "\" should result in a JexlException");
} catch (JexlException pe) {
// expected
LOGGER.info(pe);
}
}
-
+ @Test
public void testMalformedScript2() throws Exception {
// this will throw a TokenMgrErr, which we rethrow as a JexlException
String badScript = "?";
try {
JEXL.createScript(badScript);
- fail("Parsing \"" + badScript
- + "\" should result in a JexlException");
+ Assert.fail("Parsing \"" + badScript
+ + "\" should result in a JexlException");
} catch (JexlException pe) {
// expected
LOGGER.info(pe);
}
}
+ @Test
public void testMalformedScript3() throws Exception {
// this will throw a TokenMgrErr, which we rethrow as a JexlException
String badScript = "foo=1;bar=2;a?b:c:d;";
try {
JEXL.createScript(badScript);
- fail("Parsing \"" + badScript
- + "\" should result in a JexlException");
+ Assert.fail("Parsing \"" + badScript
+ + "\" should result in a JexlException");
} catch (JexlException pe) {
// expected
LOGGER.error(pe);
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PragmaTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PragmaTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PragmaTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PragmaTest.java Wed Jun 10 16:30:16 2015
@@ -18,6 +18,7 @@ package org.apache.commons.jexl3;
import java.util.Map;
import org.junit.Assert;
+import org.junit.Test;
/**
* Tests for pragmas
@@ -27,13 +28,14 @@ public class PragmaTest extends JexlTest
* Create a new test case.
* @param name case name
*/
- public PragmaTest(String name) {
- super(name);
+ public PragmaTest() {
+ super("PragmaTest");
}
/**
* Test creating a script from a string.
*/
+ @Test
public void testPragmas() throws Exception {
JexlContext jc = new MapContext();
try {
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PropertyAccessTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PropertyAccessTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PropertyAccessTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PropertyAccessTest.java Wed Jun 10 16:30:16 2015
@@ -21,12 +21,16 @@ import java.util.Map;
import org.apache.commons.jexl3.internal.Debugger;
import org.apache.commons.jexl3.junit.Asserter;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests for property access operator '.'
* @since 3.0
*/
+@SuppressWarnings({"UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"})
public class PropertyAccessTest extends JexlTestCase {
private Asserter asserter;
@@ -35,13 +39,14 @@ public class PropertyAccessTest extends
super("PropertyAccessTest");
}
+ @Before
@Override
public void setUp() {
asserter = new Asserter(JEXL);
}
- public void testPropertyProperty() throws Exception {
+ @Test public void testPropertyProperty() throws Exception {
Integer i42 = Integer.valueOf(42);
Integer i43 = Integer.valueOf(43);
String s42 = "fourty-two";
@@ -120,58 +125,58 @@ public class PropertyAccessTest extends
}
}
- public void testInnerProperty() throws Exception {
+ @Test public void testInnerProperty() throws Exception {
Container quux = new Container("quux", 42);
JexlScript get;
Object result;
JexlScript getName = JEXL.createScript("foo.property.name", "foo");
result = getName.execute(null, quux);
- assertEquals("quux", result);
+ Assert.assertEquals("quux", result);
JexlScript get0 = JEXL.createScript("foo.property.0", "foo");
result = get0.execute(null, quux);
- assertEquals("quux", result);
+ Assert.assertEquals("quux", result);
JexlScript getNumber = JEXL.createScript("foo.property.number", "foo");
result = getNumber.execute(null, quux);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
JexlScript get1 = JEXL.createScript("foo.property.1", "foo");
result = get1.execute(null, quux);
- assertEquals(42, result);
+ Assert.assertEquals(42, result);
JexlScript setName = JEXL.createScript("foo.property.name = $0", "foo", "$0");
setName.execute(null, quux, "QUUX");
result = getName.execute(null, quux);
- assertEquals("QUUX", result);
+ Assert.assertEquals("QUUX", result);
result = get0.execute(null, quux);
- assertEquals("QUUX", result);
+ Assert.assertEquals("QUUX", result);
JexlScript set0 = JEXL.createScript("foo.property.0 = $0", "foo", "$0");
set0.execute(null, quux, "BAR");
result = getName.execute(null, quux);
- assertEquals("BAR", result);
+ Assert.assertEquals("BAR", result);
result = get0.execute(null, quux);
- assertEquals("BAR", result);
+ Assert.assertEquals("BAR", result);
JexlScript setNumber = JEXL.createScript("foo.property.number = $0", "foo", "$0");
setNumber.execute(null, quux, -42);
result = getNumber.execute(null, quux);
- assertEquals(-42, result);
+ Assert.assertEquals(-42, result);
result = get1.execute(null, quux);
- assertEquals(-42, result);
+ Assert.assertEquals(-42, result);
JexlScript set1 = JEXL.createScript("foo.property.1 = $0", "foo", "$0");
set1.execute(null, quux, 24);
result = getNumber.execute(null, quux);
- assertEquals(24, result);
+ Assert.assertEquals(24, result);
result = get1.execute(null, quux);
- assertEquals(24, result);
+ Assert.assertEquals(24, result);
}
- public void testStringIdentifier() throws Exception {
+ @Test public void testStringIdentifier() throws Exception {
Map<String, String> foo = new HashMap<String, String>();
JexlContext jc = new MapContext();
@@ -179,20 +184,20 @@ public class PropertyAccessTest extends
foo.put("q u u x", "456");
JexlExpression e = JEXL.createExpression("foo.\"q u u x\"");
Object result = e.evaluate(jc);
- assertEquals("456", result);
+ Assert.assertEquals("456", result);
e = JEXL.createExpression("foo.'q u u x'");
result = e.evaluate(jc);
- assertEquals("456", result);
+ Assert.assertEquals("456", result);
JexlScript s = JEXL.createScript("foo.\"q u u x\"");
result = s.execute(jc);
- assertEquals("456", result);
+ Assert.assertEquals("456", result);
s = JEXL.createScript("foo.'q u u x'");
result = s.execute(jc);
- assertEquals("456", result);
+ Assert.assertEquals("456", result);
Debugger dbg = new Debugger();
dbg.debug(e);
String dbgdata = dbg.toString();
- assertEquals("foo.'q u u x'", dbgdata);
+ Assert.assertEquals("foo.'q u u x'", dbgdata);
}
}
\ No newline at end of file
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PublicFieldsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PublicFieldsTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PublicFieldsTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PublicFieldsTest.java Wed Jun 10 16:30:16 2015
@@ -16,10 +16,14 @@
*/
package org.apache.commons.jexl3;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
/**
* Tests public field set/get.
*/
-@SuppressWarnings("boxing")
+@SuppressWarnings({"UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"})
public class PublicFieldsTest extends JexlTestCase {
// some constants
private static final String LOWER42 = "fourty-two";
@@ -49,6 +53,7 @@ public class PublicFieldsTest extends Je
super("PublicFieldsTest");
}
+ @Before
@Override
public void setUp() {
pub = new Struct();
@@ -56,64 +61,64 @@ public class PublicFieldsTest extends Je
ctxt.set("pub", pub);
}
- public void testGetInt() throws Exception {
+ @Test public void testGetInt() throws Exception {
JexlExpression get = JEXL.createExpression("pub.anInt");
- assertEquals(42, get.evaluate(ctxt));
+ Assert.assertEquals(42, get.evaluate(ctxt));
JEXL.setProperty(pub, "anInt", -42);
- assertEquals(-42, get.evaluate(ctxt));
+ Assert.assertEquals(-42, get.evaluate(ctxt));
}
- public void testSetInt() throws Exception {
+ @Test public void testSetInt() throws Exception {
JexlExpression set = JEXL.createExpression("pub.anInt = value");
ctxt.set("value", -42);
- assertEquals(-42, set.evaluate(ctxt));
- assertEquals(-42, JEXL.getProperty(pub, "anInt"));
+ Assert.assertEquals(-42, set.evaluate(ctxt));
+ Assert.assertEquals(-42, JEXL.getProperty(pub, "anInt"));
ctxt.set("value", 42);
- assertEquals(42, set.evaluate(ctxt));
- assertEquals(42, JEXL.getProperty(pub, "anInt"));
+ Assert.assertEquals(42, set.evaluate(ctxt));
+ Assert.assertEquals(42, JEXL.getProperty(pub, "anInt"));
try {
ctxt.set("value", UPPER42);
- assertEquals(null, set.evaluate(ctxt));
- fail("should have thrown");
+ Assert.assertEquals(null, set.evaluate(ctxt));
+ Assert.fail("should have thrown");
} catch(JexlException xjexl) {}
}
- public void testGetString() throws Exception {
+ @Test public void testGetString() throws Exception {
JexlExpression get = JEXL.createExpression("pub.aString");
- assertEquals(LOWER42, get.evaluate(ctxt));
+ Assert.assertEquals(LOWER42, get.evaluate(ctxt));
JEXL.setProperty(pub, "aString", UPPER42);
- assertEquals(UPPER42, get.evaluate(ctxt));
+ Assert.assertEquals(UPPER42, get.evaluate(ctxt));
}
- public void testSetString() throws Exception {
+ @Test public void testSetString() throws Exception {
JexlExpression set = JEXL.createExpression("pub.aString = value");
ctxt.set("value", UPPER42);
- assertEquals(UPPER42, set.evaluate(ctxt));
- assertEquals(UPPER42, JEXL.getProperty(pub, "aString"));
+ Assert.assertEquals(UPPER42, set.evaluate(ctxt));
+ Assert.assertEquals(UPPER42, JEXL.getProperty(pub, "aString"));
ctxt.set("value", LOWER42);
- assertEquals(LOWER42, set.evaluate(ctxt));
- assertEquals(LOWER42, JEXL.getProperty(pub, "aString"));
+ Assert.assertEquals(LOWER42, set.evaluate(ctxt));
+ Assert.assertEquals(LOWER42, JEXL.getProperty(pub, "aString"));
}
- public void testGetInnerDouble() throws Exception {
+ @Test public void testGetInnerDouble() throws Exception {
JexlExpression get = JEXL.createExpression("pub.inner.aDouble");
- assertEquals(42.0, get.evaluate(ctxt));
+ Assert.assertEquals(42.0, get.evaluate(ctxt));
JEXL.setProperty(pub, "inner.aDouble", -42);
- assertEquals(-42.0, get.evaluate(ctxt));
+ Assert.assertEquals(-42.0, get.evaluate(ctxt));
}
- public void testSetInnerDouble() throws Exception {
+ @Test public void testSetInnerDouble() throws Exception {
JexlExpression set = JEXL.createExpression("pub.inner.aDouble = value");
ctxt.set("value", -42.0);
- assertEquals(-42.0, set.evaluate(ctxt));
- assertEquals(-42.0, JEXL.getProperty(pub, "inner.aDouble"));
+ Assert.assertEquals(-42.0, set.evaluate(ctxt));
+ Assert.assertEquals(-42.0, JEXL.getProperty(pub, "inner.aDouble"));
ctxt.set("value", 42.0);
- assertEquals(42.0, set.evaluate(ctxt));
- assertEquals(42.0, JEXL.getProperty(pub, "inner.aDouble"));
+ Assert.assertEquals(42.0, set.evaluate(ctxt));
+ Assert.assertEquals(42.0, JEXL.getProperty(pub, "inner.aDouble"));
try {
ctxt.set("value", UPPER42);
- assertEquals(null, set.evaluate(ctxt));
- fail("should have thrown");
+ Assert.assertEquals(null, set.evaluate(ctxt));
+ Assert.fail("should have thrown");
} catch(JexlException xjexl) {}
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/RangeTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/RangeTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/RangeTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/RangeTest.java Wed Jun 10 16:30:16 2015
@@ -14,22 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.jexl3;
+package org.apache.commons.jexl3;
import java.util.Collection;
import java.util.Iterator;
import org.junit.Assert;
+import org.junit.Test;
/**
* Tests for ranges.
* @since 3.0
*/
+@SuppressWarnings({"UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"})
public class RangeTest extends JexlTestCase {
public RangeTest() {
super("RangeTest");
}
+ @Test
public void testIntegerRangeOne() throws Exception {
JexlExpression e = JEXL.createExpression("(1..1)");
JexlContext jc = new MapContext();
@@ -43,6 +46,7 @@ public class RangeTest extends JexlTestC
Assert.assertEquals(1, ((Number) a[0]).intValue());
}
+ @Test
public void testIntegerRange() throws Exception {
JexlExpression e = JEXL.createExpression("(1..32)");
JexlContext jc = new MapContext();
@@ -60,19 +64,19 @@ public class RangeTest extends JexlTestC
}
Assert.assertEquals(32, i);
- Integer[] aa = c.toArray(new Integer[32]);
+ Integer[] aa = c.<Integer>toArray(new Integer[32]);
Assert.assertEquals(32, aa.length);
for (int l = 0; l < 32; ++l) {
Assert.assertTrue(aa[l] == l + 1);
}
- aa = c.toArray(new Integer[2]);
+ aa = c.<Integer>toArray(new Integer[2]);
Assert.assertEquals(32, aa.length);
for (int l = 0; l < 32; ++l) {
Assert.assertTrue(aa[l] == l + 1);
}
- aa = c.toArray(new Integer[34]);
+ aa = c.<Integer>toArray(new Integer[34]);
Assert.assertEquals(34, aa.length);
for (int l = 0; l < 32; ++l) {
Assert.assertTrue(aa[l] == l + 1);
@@ -85,6 +89,7 @@ public class RangeTest extends JexlTestC
}
}
+ @Test
public void testLongRange() throws Exception {
JexlExpression e = JEXL.createExpression("(6789000001L..6789000032L)");
JexlContext jc = new MapContext();
@@ -102,19 +107,19 @@ public class RangeTest extends JexlTestC
}
Assert.assertEquals(6789000032L, i);
- Long[] aa = c.toArray(new Long[32]);
+ Long[] aa = c.<Long>toArray(new Long[32]);
Assert.assertEquals(32, aa.length);
for (int l = 0; l < 32; ++l) {
Assert.assertTrue(aa[l] == 6789000001L + l);
}
- aa = c.toArray(new Long[2]);
+ aa = c.<Long>toArray(new Long[2]);
Assert.assertEquals(32, aa.length);
for (int l = 0; l < 32; ++l) {
Assert.assertTrue(aa[l] == 6789000001L + l);
}
- aa = c.toArray(new Long[34]);
+ aa = c.<Long>toArray(new Long[34]);
Assert.assertEquals(34, aa.length);
for (int l = 0; l < 32; ++l) {
Assert.assertTrue(aa[l] == 6789000001L + l);
@@ -127,6 +132,7 @@ public class RangeTest extends JexlTestC
}
}
+ @Test
public void testIntegerSum() throws Exception {
JexlScript e = JEXL.createScript("var s = 0; for(var i : (1..5)) { s = s + i; }; s");
JexlContext jc = new MapContext();
@@ -135,6 +141,7 @@ public class RangeTest extends JexlTestC
Assert.assertEquals(15, ((Number) o).intValue());
}
+ @Test
public void testIntegerContains() throws Exception {
JexlScript e = JEXL.createScript("(x)->{ x =~ (1..10) }");
JexlContext jc = new MapContext();
@@ -147,6 +154,7 @@ public class RangeTest extends JexlTestC
Assert.assertEquals(Boolean.FALSE, o);
}
+ @Test
public void testLongSum() throws Exception {
JexlScript e = JEXL.createScript("var s = 0; for(var i : (6789000001L..6789000001L)) { s = s + i; }; s");
JexlContext jc = new MapContext();
@@ -155,6 +163,7 @@ public class RangeTest extends JexlTestC
Assert.assertEquals(6789000001L, ((Number) o).longValue());
}
+ @Test
public void testLongContains() throws Exception {
JexlScript e = JEXL.createScript("(x)->{ x =~ (90000000001L..90000000010L) }");
JexlContext jc = new MapContext();
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java Wed Jun 10 16:30:16 2015
@@ -23,6 +23,8 @@ import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import org.junit.Assert;
+import org.junit.Test;
/**
* Tests around asynchronous script execution and interrupts.
@@ -33,6 +35,7 @@ public class ScriptCallableTest extends
super("ScriptCallableTest");
}
+ @Test
public void testFuture() throws Exception {
JexlScript e = JEXL.createScript("while(true);");
FutureTask<Object> future = new FutureTask<Object>(e.callable(null));
@@ -41,16 +44,17 @@ public class ScriptCallableTest extends
executor.submit(future);
try {
future.get(100, TimeUnit.MILLISECONDS);
- fail("should have timed out");
+ Assert.fail("should have timed out");
} catch (TimeoutException xtimeout) {
// ok, ignore
}
Thread.sleep(100);
future.cancel(true);
- assertTrue(future.isCancelled());
+ Assert.assertTrue(future.isCancelled());
}
+ @Test
public void testCallable() throws Exception {
JexlScript e = JEXL.createScript("while(true);");
Callable<Object> c = e.callable(null);
@@ -59,14 +63,15 @@ public class ScriptCallableTest extends
Future<?> future = executor.submit(c);
try {
future.get(100, TimeUnit.MILLISECONDS);
- fail("should have timed out");
+ Assert.fail("should have timed out");
} catch (TimeoutException xtimeout) {
// ok, ignore
}
future.cancel(true);
- assertTrue(future.isCancelled());
+ Assert.assertTrue(future.isCancelled());
}
+ @Test
public void testCallableClosure() throws Exception {
JexlScript e = JEXL.createScript("function(t) {while(t);}");
Callable<Object> c = e.callable(null, Boolean.TRUE);
@@ -75,12 +80,12 @@ public class ScriptCallableTest extends
Future<?> future = executor.submit(c);
try {
future.get(100, TimeUnit.MILLISECONDS);
- fail("should have timed out");
+ Assert.fail("should have timed out");
} catch (TimeoutException xtimeout) {
// ok, ignore
}
future.cancel(true);
- assertTrue(future.isCancelled());
+ Assert.assertTrue(future.isCancelled());
}
public static class TestContext extends MapContext implements JexlContext.NamespaceResolver {
@@ -98,7 +103,7 @@ public class ScriptCallableTest extends
try {
Thread.sleep(1000 * s);
return s;
- } catch(InterruptedException xint) {
+ } catch (InterruptedException xint) {
Thread.currentThread().interrupt();
}
return -1;
@@ -106,15 +111,16 @@ public class ScriptCallableTest extends
public int runForever() {
boolean x = false;
- while(true) {
+ while (true) {
if (x) {
- break;
+ break;
}
}
return 1;
}
}
+ @Test
public void testNoWait() throws Exception {
JexlScript e = JEXL.createScript("wait(0)");
Callable<Object> c = e.callable(new TestContext());
@@ -122,10 +128,11 @@ public class ScriptCallableTest extends
ExecutorService executor = Executors.newFixedThreadPool(1);
Future<?> future = executor.submit(c);
Object t = future.get(2, TimeUnit.SECONDS);
- assertTrue(future.isDone());
- assertEquals(0, t);
+ Assert.assertTrue(future.isDone());
+ Assert.assertEquals(0, t);
}
+ @Test
public void testWait() throws Exception {
JexlScript e = JEXL.createScript("wait(1)");
Callable<Object> c = e.callable(new TestContext());
@@ -133,9 +140,10 @@ public class ScriptCallableTest extends
ExecutorService executor = Executors.newFixedThreadPool(1);
Future<?> future = executor.submit(c);
Object t = future.get(2, TimeUnit.SECONDS);
- assertEquals(1, t);
+ Assert.assertEquals(1, t);
}
+ @Test
public void testCancelWait() throws Exception {
JexlScript e = JEXL.createScript("wait(10)");
Callable<Object> c = e.callable(new TestContext());
@@ -144,14 +152,15 @@ public class ScriptCallableTest extends
Future<?> future = executor.submit(c);
try {
future.get(100, TimeUnit.MILLISECONDS);
- fail("should have timed out");
+ Assert.fail("should have timed out");
} catch (TimeoutException xtimeout) {
// ok, ignore
}
future.cancel(true);
- assertTrue(future.isCancelled());
+ Assert.assertTrue(future.isCancelled());
}
+ @Test
public void testCancelWaitInterrupt() throws Exception {
JexlScript e = JEXL.createScript("waitInterrupt(42)");
Callable<Object> c = e.callable(new TestContext());
@@ -160,14 +169,15 @@ public class ScriptCallableTest extends
Future<?> future = executor.submit(c);
try {
future.get(100, TimeUnit.MILLISECONDS);
- fail("should have timed out");
+ Assert.fail("should have timed out");
} catch (TimeoutException xtimeout) {
// ok, ignore
}
future.cancel(true);
- assertTrue(future.isCancelled());
+ Assert.assertTrue(future.isCancelled());
}
+ @Test
public void testCancelForever() throws Exception {
JexlScript e = JEXL.createScript("runForever()");
Callable<Object> c = e.callable(new TestContext());
@@ -176,14 +186,15 @@ public class ScriptCallableTest extends
Future<?> future = executor.submit(c);
try {
future.get(100, TimeUnit.MILLISECONDS);
- fail("should have timed out");
+ Assert.fail("should have timed out");
} catch (TimeoutException xtimeout) {
// ok, ignore
}
future.cancel(true);
- assertTrue(future.isCancelled());
+ Assert.assertTrue(future.isCancelled());
}
+ @Test
public void testCancelLoopWait() throws Exception {
JexlScript e = JEXL.createScript("while (true) { wait(10) }");
Callable<Object> c = e.callable(new TestContext());
@@ -192,11 +203,11 @@ public class ScriptCallableTest extends
Future<?> future = executor.submit(c);
try {
future.get(100, TimeUnit.MILLISECONDS);
- fail("should have timed out");
+ Assert.fail("should have timed out");
} catch (TimeoutException xtimeout) {
// ok, ignore
}
future.cancel(true);
- assertTrue(future.isCancelled());
+ Assert.assertTrue(future.isCancelled());
}
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptTest.java Wed Jun 10 16:30:16 2015
@@ -18,11 +18,14 @@ package org.apache.commons.jexl3;
import java.io.File;
import java.net.URL;
+import org.junit.Assert;
+import org.junit.Test;
/**
* Tests for JexlScript
* @since 1.1
*/
+@SuppressWarnings({"UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"})
public class ScriptTest extends JexlTestCase {
static final String TEST1 = "src/test/scripts/test1.jexl";
@@ -42,47 +45,46 @@ public class ScriptTest extends JexlTest
}
/**
* Create a new test case.
- * @param name case name
*/
- public ScriptTest(String name) {
- super(name);
+ public ScriptTest() {
+ super("ScriptTest");
}
/**
* Test creating a script from a string.
*/
- public void testSimpleScript() throws Exception {
+ @Test public void testSimpleScript() throws Exception {
String code = "while (x < 10) x = x + 1;";
JexlScript s = JEXL.createScript(code);
JexlContext jc = new MapContext();
jc.set("x", new Integer(1));
Object o = s.execute(jc);
- assertEquals("Result is wrong", new Integer(10), o);
- assertEquals("getText is wrong", code, s.getSourceText());
+ Assert.assertEquals("Result is wrong", new Integer(10), o);
+ Assert.assertEquals("getText is wrong", code, s.getSourceText());
}
- public void testScriptFromFile() throws Exception {
+ @Test public void testScriptFromFile() throws Exception {
File testScript = new File(TEST1);
JexlScript s = JEXL.createScript(testScript);
JexlContext jc = new MapContext();
jc.set("out", System.out);
Object result = s.execute(jc);
- assertNotNull("No result", result);
- assertEquals("Wrong result", new Integer(7), result);
+ Assert.assertNotNull("No result", result);
+ Assert.assertEquals("Wrong result", new Integer(7), result);
}
- public void testScriptFromURL() throws Exception {
+ @Test public void testScriptFromURL() throws Exception {
URL testUrl = new File("src/test/scripts/test1.jexl").toURI().toURL();
JexlScript s = JEXL.createScript(testUrl);
JexlContext jc = new MapContext();
jc.set("out", System.out);
Object result = s.execute(jc);
- assertNotNull("No result", result);
- assertEquals("Wrong result", new Integer(7), result);
+ Assert.assertNotNull("No result", result);
+ Assert.assertEquals("Wrong result", new Integer(7), result);
}
- public void testScriptUpdatesContext() throws Exception {
+ @Test public void testScriptUpdatesContext() throws Exception {
String jexlCode = "resultat.setCode('OK')";
JexlExpression e = JEXL.createExpression(jexlCode);
JexlScript s = JEXL.createScript(jexlCode);
@@ -93,10 +95,10 @@ public class ScriptTest extends JexlTest
resultatJexl.setCode("");
e.evaluate(jc);
- assertEquals("OK", resultatJexl.getCode());
+ Assert.assertEquals("OK", resultatJexl.getCode());
resultatJexl.setCode("");
s.execute(jc);
- assertEquals("OK", resultatJexl.getCode());
+ Assert.assertEquals("OK", resultatJexl.getCode());
}
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/SetLiteralTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/SetLiteralTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/SetLiteralTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/SetLiteralTest.java Wed Jun 10 16:30:16 2015
@@ -20,11 +20,14 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
+import org.junit.Assert;
+import org.junit.Test;
/**
* Tests for set literals
* @since 3.0
*/
+@SuppressWarnings({"UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"})
public class SetLiteralTest extends JexlTestCase {
public SetLiteralTest() {
@@ -35,60 +38,67 @@ public class SetLiteralTest extends Jexl
return new HashSet<Object>(Arrays.asList(args));
}
+ @Test
public void testSetLiteralWithStrings() throws Exception {
JexlExpression e = JEXL.createExpression("{ 'foo' , 'bar' }");
JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
Set<?> check = createSet("foo", "bar");
- assertTrue(Objects.equals(check, o));
+ Assert.assertTrue(Objects.equals(check, o));
}
+ @Test
public void testLiteralWithOneEntry() throws Exception {
JexlExpression e = JEXL.createExpression("{ 'foo' }");
JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
Set<?> check = createSet("foo");
- assertTrue(Objects.equals(check, o));
+ Assert.assertTrue(Objects.equals(check, o));
}
+ @Test
public void testSetLiteralWithStringsScript() throws Exception {
JexlScript e = JEXL.createScript("{ 'foo' , 'bar' }");
JexlContext jc = new MapContext();
Object o = e.execute(jc);
Set<?> check = createSet("foo", "bar");
- assertTrue(Objects.equals(check, o));
+ Assert.assertTrue(Objects.equals(check, o));
}
+ @Test
public void testSetLiteralWithOneEntryScript() throws Exception {
JexlScript e = JEXL.createScript("{ 'foo' }");
JexlContext jc = new MapContext();
Object o = e.execute(jc);
Set<?> check = createSet("foo");
- assertTrue(Objects.equals(check, o));
+ Assert.assertTrue(Objects.equals(check, o));
}
+ @Test
public void testSetLiteralWithOneEntryBlock() throws Exception {
JexlScript e = JEXL.createScript("{ { 'foo' }; }");
JexlContext jc = new MapContext();
Object o = e.execute(jc);
Set<?> check = createSet("foo");
- assertTrue(Objects.equals(check, o));
+ Assert.assertTrue(Objects.equals(check, o));
}
+ @Test
public void testSetLiteralWithNumbers() throws Exception {
JexlExpression e = JEXL.createExpression("{ 5.0 , 10 }");
JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
Set<?> check = createSet(new Double(5.0), new Integer(10));
- assertTrue(Objects.equals(check, o));
+ Assert.assertTrue(Objects.equals(check, o));
}
+ @Test
public void testSetLiteralWithNulls() throws Exception {
String[] exprs = {
"{ 10 }",
@@ -108,25 +118,27 @@ public class SetLiteralTest extends Jexl
for (int t = 0; t < exprs.length; ++t) {
JexlExpression e = JEXL.createExpression(exprs[t]);
Object o = e.evaluate(jc);
- assertTrue(exprs[t], Objects.equals(checks[t], o));
+ Assert.assertTrue(exprs[t], Objects.equals(checks[t], o));
}
}
+ @Test
public void testSizeOfSimpleSetLiteral() throws Exception {
JexlExpression e = JEXL.createExpression("size({ 'foo' , 'bar'})");
JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
- assertEquals(new Integer(2), o);
+ Assert.assertEquals(new Integer(2), o);
}
+ @Test
public void testNotEmptySimpleSetLiteral() throws Exception {
JexlExpression e = JEXL.createExpression("empty({ 'foo' , 'bar' })");
JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
- assertFalse(((Boolean) o).booleanValue());
+ Assert.assertFalse(((Boolean) o).booleanValue());
}
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/VarTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/VarTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/VarTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/VarTest.java Wed Jun 10 16:30:16 2015
@@ -24,17 +24,21 @@ import java.util.List;
import java.util.Set;
import org.apache.log4j.Logger;
import org.apache.log4j.LogManager;
+import org.junit.Assert;
+import org.junit.Test;
/**
* Tests local variables.
*/
+@SuppressWarnings({"UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"})
public class VarTest extends JexlTestCase {
static final Logger LOGGER = LogManager.getLogger(VarTest.class.getName());
- public VarTest(String testName) {
- super(testName);
+ public VarTest() {
+ super("VarTest");
}
+ @Test
public void testStrict() throws Exception {
JexlEvalContext env = new JexlEvalContext();
JexlContext ctxt = new ReadonlyContext(env, env);
@@ -45,14 +49,14 @@ public class VarTest extends JexlTestCas
e = JEXL.createScript("x");
try {
Object o = e.execute(ctxt);
- fail("should have thrown an unknown var exception");
+ Assert.fail("should have thrown an unknown var exception");
} catch(JexlException xjexl) {
// ok since we are strict and x does not exist
}
e = JEXL.createScript("x = 42");
try {
Object o = e.execute(ctxt);
- fail("should have thrown a readonly context exception");
+ Assert.fail("should have thrown a readonly context exception");
} catch(JexlException xjexl) {
// ok since we are strict and context is readonly
}
@@ -61,28 +65,31 @@ public class VarTest extends JexlTestCas
e = JEXL.createScript("x.theAnswerToEverything()");
try {
Object o = e.execute(ctxt);
- fail("should have thrown an unknown method exception");
+ Assert.fail("should have thrown an unknown method exception");
} catch(JexlException xjexl) {
// ok since we are strict and method does not exist
}
}
+ @Test
public void testLocalBasic() throws Exception {
JexlScript e = JEXL.createScript("var x; x = 42");
Object o = e.execute(null);
- assertEquals("Result is not 42", new Integer(42), o);
+ Assert.assertEquals("Result is not 42", new Integer(42), o);
}
+ @Test
public void testLocalSimple() throws Exception {
JexlScript e = JEXL.createScript("var x = 21; x + x");
Object o = e.execute(null);
- assertEquals("Result is not 42", new Integer(42), o);
+ Assert.assertEquals("Result is not 42", new Integer(42), o);
}
+ @Test
public void testLocalFor() throws Exception {
JexlScript e = JEXL.createScript("var y = 0; for(var x : [5, 17, 20]) { y = y + x; } y;");
Object o = e.execute(null);
- assertEquals("Result is not 42", new Integer(42), o);
+ Assert.assertEquals("Result is not 42", new Integer(42), o);
}
public static class NumbersContext extends MapContext implements JexlContext.NamespaceResolver {
@@ -96,20 +103,22 @@ public class VarTest extends JexlTestCas
}
}
+ @Test
public void testLocalForFunc() throws Exception {
JexlContext jc = new NumbersContext();
JexlScript e = JEXL.createScript("var y = 0; for(var x : numbers()) { y = y + x; } y;");
Object o = e.execute(jc);
- assertEquals("Result is not 42", new Integer(42), o);
+ Assert.assertEquals("Result is not 42", new Integer(42), o);
}
+ @Test
public void testLocalForFuncReturn() throws Exception {
JexlContext jc = new NumbersContext();
JexlScript e = JEXL.createScript("var y = 42; for(var x : numbers()) { if (x > 10) return x } y;");
Object o = e.execute(jc);
- assertEquals("Result is not 17", new Integer(17), o);
+ Assert.assertEquals("Result is not 17", new Integer(17), o);
- assertTrue(toString(e.getVariables()), e.getVariables().isEmpty());
+ Assert.assertTrue(toString(e.getVariables()), e.getVariables().isEmpty());
}
/**
@@ -188,6 +197,7 @@ public class VarTest extends JexlTestCas
return ls;
}
+ @Test
public void testRefs() throws Exception {
JexlScript e;
Set<List<String>> vars;
@@ -196,80 +206,81 @@ public class VarTest extends JexlTestCas
e = JEXL.createScript("e[f]");
vars = e.getVariables();
expect = mkref(new String[][]{{"e"},{"f"}});
- assertTrue(eq(expect, vars));
+ Assert.assertTrue(eq(expect, vars));
e = JEXL.createScript("e[f][g]");
vars = e.getVariables();
expect = mkref(new String[][]{{"e"},{"f"},{"g"}});
- assertTrue(eq(expect, vars));
+ Assert.assertTrue(eq(expect, vars));
e = JEXL.createScript("e['f'].goo");
vars = e.getVariables();
expect = mkref(new String[][]{{"e","f","goo"}});
- assertTrue(eq(expect, vars));
+ Assert.assertTrue(eq(expect, vars));
e = JEXL.createScript("e['f']");
vars = e.getVariables();
expect = mkref(new String[][]{{"e","f"}});
- assertTrue(eq(expect, vars));
+ Assert.assertTrue(eq(expect, vars));
e = JEXL.createScript("e[f]['g']");
vars = e.getVariables();
expect = mkref(new String[][]{{"e"},{"f"}});
- assertTrue(eq(expect, vars));
+ Assert.assertTrue(eq(expect, vars));
e = JEXL.createScript("e['f']['g']");
vars = e.getVariables();
expect = mkref(new String[][]{{"e","f","g"}});
- assertTrue(eq(expect, vars));
+ Assert.assertTrue(eq(expect, vars));
e = JEXL.createScript("a['b'].c['d'].e");
vars = e.getVariables();
expect = mkref(new String[][]{{"a", "b", "c", "d", "e"}});
- assertTrue(eq(expect, vars));
+ Assert.assertTrue(eq(expect, vars));
e = JEXL.createScript("a + b.c + b.c.d + e['f']");
vars = e.getVariables();
expect = mkref(new String[][]{{"a"}, {"b", "c"}, {"b", "c", "d"}, {"e", "f"}});
- assertTrue(eq(expect, vars));
+ Assert.assertTrue(eq(expect, vars));
e = JEXL.createScript("D[E[F]]");
vars = e.getVariables();
expect = mkref(new String[][]{{"D"}, {"E"}, {"F"}});
- assertTrue(eq(expect, vars));
+ Assert.assertTrue(eq(expect, vars));
e = JEXL.createScript("D[E[F[G[H]]]]");
vars = e.getVariables();
expect = mkref(new String[][]{{"D"}, {"E"}, {"F"}, {"G"}, {"H"}});
- assertTrue(eq(expect, vars));
+ Assert.assertTrue(eq(expect, vars));
e = JEXL.createScript(" A + B[C] + D[E[F]] + x[y[z]] ");
vars = e.getVariables();
expect = mkref(new String[][]{{"A"}, {"B"}, {"C"}, {"D"}, {"E"}, {"F"}, {"x"} , {"y"}, {"z"}});
- assertTrue(eq(expect, vars));
+ Assert.assertTrue(eq(expect, vars));
e = JEXL.createScript(" A + B[C] + D.E['F'] + x[y.z] ");
vars = e.getVariables();
expect = mkref(new String[][]{{"A"}, {"B"}, {"C"}, {"D", "E", "F"}, {"x"} , {"y", "z"}});
- assertTrue(eq(expect, vars));
+ Assert.assertTrue(eq(expect, vars));
e = JEXL.createScript("(A)");
vars = e.getVariables();
expect = mkref(new String[][]{{"A"}});
- assertTrue(eq(expect, vars));
+ Assert.assertTrue(eq(expect, vars));
e = JEXL.createScript("not(A)");
vars = e.getVariables();
expect = mkref(new String[][]{{"A"}});
- assertTrue(eq(expect, vars));
+ Assert.assertTrue(eq(expect, vars));
e = JEXL.createScript("not((A))");
vars = e.getVariables();
expect = mkref(new String[][]{{"A"}});
- assertTrue(eq(expect, vars));
+ Assert.assertTrue(eq(expect, vars));
}
+ @Test
public void testMix() throws Exception {
JexlScript e;
// x is a parameter, y a context variable, z a local variable
@@ -278,26 +289,86 @@ public class VarTest extends JexlTestCas
String[] parms = e.getParameters();
String[] locals = e.getLocalVariables();
- assertTrue(eq(mkref(new String[][]{{"y"}}), vars));
- assertEquals(1, parms.length);
- assertEquals("x", parms[0]);
- assertEquals(1, locals.length);
- assertEquals("z", locals[0]);
+ Assert.assertTrue(eq(mkref(new String[][]{{"y"}}), vars));
+ Assert.assertEquals(1, parms.length);
+ Assert.assertEquals("x", parms[0]);
+ Assert.assertEquals(1, locals.length);
+ Assert.assertEquals("z", locals[0]);
}
+ @Test
public void testLiteral() throws Exception {
JexlScript e = JEXL.createScript("x.y[['z', 't']]");
Set<List<String>> vars = e.getVariables();
- assertEquals(1, vars.size());
- assertTrue(eq(mkref(new String[][]{{"x", "y", "[ 'z', 't' ]"}}), vars));
+ Assert.assertEquals(1, vars.size());
+ Assert.assertTrue(eq(mkref(new String[][]{{"x", "y", "[ 'z', 't' ]"}}), vars));
e = JEXL.createScript("x.y[{'z': 't'}]");
vars = e.getVariables();
- assertEquals(1, vars.size());
- assertTrue(eq(mkref(new String[][]{{"x", "y", "{ 'z' : 't' }"}}), vars));
+ Assert.assertEquals(1, vars.size());
+ Assert.assertTrue(eq(mkref(new String[][]{{"x", "y", "{ 'z' : 't' }"}}), vars));
e = JEXL.createScript("x.y.'{ \\'z\\' : \\'t\\' }'");
vars = e.getVariables();
- assertEquals(1, vars.size());
- assertTrue(eq(mkref(new String[][]{{"x", "y", "{ 'z' : 't' }"}}), vars));
+ Assert.assertEquals(1, vars.size());
+ Assert.assertTrue(eq(mkref(new String[][]{{"x", "y", "{ 'z' : 't' }"}}), vars));
}
+
+ @Test
+ public void testSyntacticVariations() throws Exception {
+ JexlScript script = JEXL.createScript("sum(TOTAL) - partial.sum() + partial['sub'].avg() - sum(partial.sub)");
+ Set<List<String>> vars = script.getVariables();
+
+ Assert.assertTrue(vars.size() == 3);
+ }
+
+ public static class TheVarContext {
+ private int x;
+ private String color;
+
+ public void setX(int x) {
+ this.x = x;
+ }
+
+ public void setColor(String color) {
+ this.color = color;
+ }
+
+ public int getX() {
+ return x;
+ }
+
+ public String getColor() {
+ return color;
+ }
+ }
+
+ @Test
+ public void testObjectContext() throws Exception {
+ TheVarContext vars = new TheVarContext();
+ JexlContext jc = new ObjectContext<TheVarContext>(JEXL, vars);
+ try {
+ JexlScript script;
+ Object result;
+ script = JEXL.createScript("x = 3");
+ result = script.execute(jc);
+ Assert.assertEquals(3, vars.getX());
+ Assert.assertEquals(3, result);
+ script = JEXL.createScript("x == 3");
+ result = script.execute(jc);
+ Assert.assertTrue((Boolean) result);
+ Assert.assertTrue(jc.has("x"));
+
+ script = JEXL.createScript("color = 'blue'");
+ result = script.execute(jc);
+ Assert.assertEquals("blue", vars.getColor());
+ Assert.assertEquals("blue", result);
+ script = JEXL.createScript("color == 'blue'");
+ result = script.execute(jc);
+ Assert.assertTrue((Boolean) result);
+ Assert.assertTrue(jc.has("color"));
+ } catch (JexlException.Method ambiguous) {
+ Assert.fail("total() is solvable");
+ }
+ }
+
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/WhileTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/WhileTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/WhileTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/WhileTest.java Wed Jun 10 16:30:16 2015
@@ -14,36 +14,42 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.commons.jexl3;
+import org.junit.Assert;
+import org.junit.Test;
+
/**
* Tests for while statement.
* @since 1.1
*/
+@SuppressWarnings({"UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"})
public class WhileTest extends JexlTestCase {
- public WhileTest(String testName) {
- super(testName);
+ public WhileTest() {
+ super("WhileTest");
}
+ @Test
public void testSimpleWhileFalse() throws Exception {
JexlScript e = JEXL.createScript("while (false) ;");
JexlContext jc = new MapContext();
Object o = e.execute(jc);
- assertNull("Result is not null", o);
+ Assert.assertNull("Result is not null", o);
}
+ @Test
public void testWhileExecutesExpressionWhenLooping() throws Exception {
JexlScript e = JEXL.createScript("while (x < 10) x = x + 1;");
JexlContext jc = new MapContext();
jc.set("x", new Integer(1));
Object o = e.execute(jc);
- assertEquals("Result is wrong", new Integer(10), o);
+ Assert.assertEquals("Result is wrong", new Integer(10), o);
}
+ @Test
public void testWhileWithBlock() throws Exception {
JexlScript e = JEXL.createScript("while (x < 10) { x = x + 1; y = y * 2; }");
JexlContext jc = new MapContext();
@@ -51,8 +57,8 @@ public class WhileTest extends JexlTestC
jc.set("y", new Integer(1));
Object o = e.execute(jc);
- assertEquals("Result is wrong", new Integer(512), o);
- assertEquals("x is wrong", new Integer(10), jc.get("x"));
- assertEquals("y is wrong", new Integer(512), jc.get("y"));
+ Assert.assertEquals("Result is wrong", new Integer(512), o);
+ Assert.assertEquals("x is wrong", new Integer(10), jc.get("x"));
+ Assert.assertEquals("y is wrong", new Integer(512), jc.get("y"));
}
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/ArrayTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/ArrayTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/ArrayTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/ArrayTest.java Wed Jun 10 16:30:16 2015
@@ -17,7 +17,6 @@
package org.apache.commons.jexl3.examples;
-import junit.framework.TestCase;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.JexlEngine;
@@ -26,13 +25,14 @@ import org.apache.commons.jexl3.MapConte
import java.util.List;
import java.util.ArrayList;
import org.apache.commons.jexl3.JexlBuilder;
+import org.junit.Test;
/**
* Simple example to show how to access arrays.
*
* @since 1.0
*/
-public class ArrayTest extends TestCase {
+public class ArrayTest {
/**
* An example for array access.
*/
@@ -67,7 +67,7 @@ public class ArrayTest extends TestCase
* Unit test entry point.
* @throws Exception
*/
- public void testExample() throws Exception {
+ @Test public void testExample() throws Exception {
example(Output.JUNIT);
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/Util.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/Util.java?rev=1684706&r1=1684705&r2=1684706&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/Util.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/Util.java Wed Jun 10 16:30:16 2015
@@ -26,8 +26,7 @@ import org.apache.commons.jexl3.parser.A
import org.apache.commons.jexl3.parser.JexlNode;
/**
- *
- * @author henri
+ * Helper methods for debug sessions.
*/
public class Util {
/**