Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java (original) +++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java Wed Jun 10 16:30:16 2015 @@ -18,27 +18,29 @@ package org.apache.commons.jexl3; import org.apache.commons.jexl3.internal.Engine; import java.math.BigDecimal; -import java.math.BigInteger; import java.math.MathContext; import java.util.HashMap; import java.util.Map; import org.apache.commons.jexl3.internal.introspection.Uberspect; +import java.io.File; +import java.net.URL; +import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Set; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; /** * Test cases for reported issue . */ -@SuppressWarnings("boxing") +@SuppressWarnings({"boxing", "UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"}) public class IssuesTest extends JexlTestCase { public IssuesTest() { super("IssuesTest", null); } + @Before @Override public void setUp() throws Exception { // ensure jul logging is only error to avoid warning in silent mode @@ -46,6 +48,7 @@ public class IssuesTest extends JexlTest } // JEXL-49: blocks not parsed (fixed) + @Test public void test49() throws Exception { JexlEngine jexl = new Engine(); Map<String, Object> vars = new HashMap<String, Object>(); @@ -53,7 +56,7 @@ public class IssuesTest extends JexlTest String stmt = "a = 'b'; c = 'd';"; JexlScript expr = jexl.createScript(stmt); /* Object value = */ expr.execute(ctxt); - assertTrue("JEXL-49 is not fixed", vars.get("a").equals("b") && vars.get("c").equals("d")); + Assert.assertTrue("JEXL-49 is not fixed", vars.get("a").equals("b") && vars.get("c").equals("d")); } // JEXL-48: bad assignment detection @@ -82,6 +85,7 @@ public class IssuesTest extends JexlTest } } + @Test public void test48() throws Exception { JexlEngine jexl = new Engine(); JexlEvalContext jc = new JexlEvalContext(); @@ -93,16 +97,17 @@ public class IssuesTest extends JexlTest JexlExpression e = jexl.createExpression(jexlExp); jc.set("foo", new Foo()); /* Object o = */ e.evaluate(jc); - fail("Should have failed due to invalid assignment"); + Assert.fail("Should have failed due to invalid assignment"); } catch (JexlException.Assignment xparse) { String dbg = xparse.toString(); } catch (JexlException xjexl) { - fail("Should have thrown a parse exception"); + Assert.fail("Should have thrown a parse exception"); } } // JEXL-47: C style comments (single & multi line) (fixed in Parser.jjt) // JEXL-44: comments dont allow double quotes (fixed in Parser.jjt) + @Test public void test47() throws Exception { JexlEngine jexl = new Engine(); JexlEvalContext ctxt = new JexlEvalContext(); @@ -111,19 +116,20 @@ public class IssuesTest extends JexlTest JexlExpression expr = jexl.createExpression("true//false\n"); Object value = expr.evaluate(ctxt); - assertTrue("should be true", ((Boolean) value).booleanValue()); + Assert.assertTrue("should be true", ((Boolean) value).booleanValue()); expr = jexl.createExpression("/*true*/false"); value = expr.evaluate(ctxt); - assertFalse("should be false", ((Boolean) value).booleanValue()); + Assert.assertFalse("should be false", ((Boolean) value).booleanValue()); expr = jexl.createExpression("/*\"true\"*/false"); value = expr.evaluate(ctxt); - assertFalse("should be false", ((Boolean) value).booleanValue()); + Assert.assertFalse("should be false", ((Boolean) value).booleanValue()); } // JEXL-42: NullPointerException evaluating an expression // fixed in JexlArithmetic by allowing add operator to deal with string, null + @Test public void test42() throws Exception { JexlEngine jexl = new JexlBuilder().create(); JxltEngine uel = jexl.createJxltEngine(); @@ -135,7 +141,7 @@ public class IssuesTest extends JexlTest JxltEngine.Expression expr = uel.createExpression("${ax+(bx)}"); Object value = expr.evaluate(ctxt); - assertTrue("should be ok", "ok".equals(value)); + Assert.assertTrue("should be ok", "ok".equals(value)); } // JEXL-40: failed to discover all methods (non public class implements public method) @@ -151,6 +157,7 @@ public class IssuesTest extends JexlTest } } + @Test public void test40() throws Exception { JexlEngine jexl = new Engine(); JexlEvalContext ctxt = new JexlEvalContext(); @@ -161,36 +168,38 @@ public class IssuesTest extends JexlTest JexlExpression expr = jexl.createExpression("derived.foo()"); Object value = expr.evaluate(ctxt); - assertTrue("should be true", ((Boolean) value).booleanValue()); + Assert.assertTrue("should be true", ((Boolean) value).booleanValue()); } // JEXL-52: can be implemented by deriving Interpreter.{g,s}etAttribute; later + @Test public void test52base() throws Exception { Engine jexl = (Engine) createEngine(false); Uberspect uber = (Uberspect) jexl.getUberspect(); // most likely, call will be in an Interpreter, getUberspect String[] names = uber.getMethodNames(Another.class); - assertTrue("should find methods", names.length > 0); + Assert.assertTrue("should find methods", names.length > 0); int found = 0; for (String name : names) { if ("foo".equals(name) || "goo".equals(name)) { found += 1; } } - assertTrue("should have foo & goo", found == 2); + Assert.assertTrue("should have foo & goo", found == 2); names = uber.getFieldNames(Another.class); - assertTrue("should find fields", names.length > 0); + Assert.assertTrue("should find fields", names.length > 0); found = 0; for (String name : names) { if ("name".equals(name)) { found += 1; } } - assertTrue("should have name", found == 1); + Assert.assertTrue("should have name", found == 1); } // JEXL-10/JEXL-11: variable checking, null operand is error + @Test public void test11() throws Exception { JexlEngine jexl = createEngine(false); JexlEvalContext ctxt = new JexlEvalContext(); @@ -211,7 +220,7 @@ public class IssuesTest extends JexlTest try { JexlExpression expr = jexl.createExpression(exprs[e]); /* Object value = */ expr.evaluate(ctxt); - fail(exprs[e] + " : should have failed due to null argument"); + Assert.fail(exprs[e] + " : should have failed due to null argument"); } catch (JexlException xjexl) { // expected } @@ -219,6 +228,7 @@ public class IssuesTest extends JexlTest } // JEXL-62 + @Test public void test62() throws Exception { JexlEngine jexl = createEngine(false); MapContext vars = new MapContext(); @@ -229,27 +239,28 @@ public class IssuesTest extends JexlTest JexlScript jscript; jscript = jexl.createScript("dummy.hashCode()"); - assertEquals(jscript.getSourceText(), null, jscript.execute(ctxt)); // OK + Assert.assertEquals(jscript.getSourceText(), null, jscript.execute(ctxt)); // OK ctxt.set("dummy", "abcd"); - assertEquals(jscript.getSourceText(), Integer.valueOf("abcd".hashCode()), jscript.execute(ctxt)); // OK + Assert.assertEquals(jscript.getSourceText(), Integer.valueOf("abcd".hashCode()), jscript.execute(ctxt)); // OK jscript = jexl.createScript("dummy.hashCode"); - assertEquals(jscript.getSourceText(), null, jscript.execute(ctxt)); // OK + Assert.assertEquals(jscript.getSourceText(), null, jscript.execute(ctxt)); // OK JexlExpression jexpr; vars.clear(); jexpr = jexl.createExpression("dummy.hashCode()"); - assertEquals(jexpr.toString(), null, jexpr.evaluate(ctxt)); // OK + Assert.assertEquals(jexpr.toString(), null, jexpr.evaluate(ctxt)); // OK ctxt.set("dummy", "abcd"); - assertEquals(jexpr.toString(), Integer.valueOf("abcd".hashCode()), jexpr.evaluate(ctxt)); // OK + Assert.assertEquals(jexpr.toString(), Integer.valueOf("abcd".hashCode()), jexpr.evaluate(ctxt)); // OK jexpr = jexl.createExpression("dummy.hashCode"); - assertEquals(jexpr.toString(), null, jexpr.evaluate(ctxt)); // OK + Assert.assertEquals(jexpr.toString(), null, jexpr.evaluate(ctxt)); // OK } // JEXL-73 + @Test public void test73() throws Exception { JexlEngine jexl = createEngine(false); JexlEvalContext ctxt = new JexlEvalContext(); @@ -260,25 +271,26 @@ public class IssuesTest extends JexlTest e = jexl.createExpression("c.e"); try { /* Object o = */ e.evaluate(ctxt); - fail("c.e not declared as variable"); + Assert.fail("c.e not declared as variable"); } catch (JexlException.Variable xjexl) { String msg = xjexl.getMessage(); - assertTrue(msg.indexOf("c.e") > 0); + Assert.assertTrue(msg.indexOf("c.e") > 0); } ctxt.set("c", "{ 'a' : 3, 'b' : 5}"); ctxt.set("e", Integer.valueOf(2)); try { /* Object o = */ e.evaluate(ctxt); - fail("c.e not accessible as property"); + Assert.fail("c.e not accessible as property"); } catch (JexlException.Property xjexl) { String msg = xjexl.getMessage(); - assertTrue(msg.indexOf("e") > 0); + Assert.assertTrue(msg.indexOf("e") > 0); } } // JEXL-87 + @Test public void test87() throws Exception { JexlEngine jexl = createEngine(false); JexlEvalContext ctxt = new JexlEvalContext(); @@ -289,16 +301,17 @@ public class IssuesTest extends JexlTest ctxt.set("l", java.math.BigInteger.valueOf(7)); ctxt.set("r", java.math.BigInteger.valueOf(2)); - assertEquals(java.math.BigInteger.valueOf(3), divide.evaluate(ctxt)); - assertTrue(jexl.getArithmetic().equals(1, modulo.evaluate(ctxt))); + Assert.assertEquals(java.math.BigInteger.valueOf(3), divide.evaluate(ctxt)); + Assert.assertTrue(jexl.getArithmetic().equals(1, modulo.evaluate(ctxt))); ctxt.set("l", java.math.BigDecimal.valueOf(7)); ctxt.set("r", java.math.BigDecimal.valueOf(2)); - assertEquals(java.math.BigDecimal.valueOf(3.5), divide.evaluate(ctxt)); - assertTrue(jexl.getArithmetic().equals(1, modulo.evaluate(ctxt))); + Assert.assertEquals(java.math.BigDecimal.valueOf(3.5), divide.evaluate(ctxt)); + Assert.assertTrue(jexl.getArithmetic().equals(1, modulo.evaluate(ctxt))); } // JEXL-90 + @Test public void test90() throws Exception { JexlEngine jexl = createEngine(false); JexlEvalContext ctxt = new JexlEvalContext(); @@ -315,7 +328,7 @@ public class IssuesTest extends JexlTest for (int f = 0; f < fexprs.length; ++f) { try { jexl.createScript(fexprs[f]); - fail(fexprs[f] + ": Should have failed in parse"); + Assert.fail(fexprs[f] + ": Should have failed in parse"); } catch (JexlException xany) { // expected to fail in createExpression } @@ -332,12 +345,13 @@ public class IssuesTest extends JexlTest ctxt.set("y", Boolean.TRUE); for (int e = 0; e < exprs.length; ++e) { JexlScript s = jexl.createScript(exprs[e]); - assertEquals(Integer.valueOf(2), s.execute(ctxt)); + Assert.assertEquals(Integer.valueOf(2), s.execute(ctxt)); } debuggerCheck(jexl); } // JEXL-44 + @Test public void test44() throws Exception { JexlEngine jexl = createEngine(false); JexlEvalContext ctxt = new JexlEvalContext(); @@ -345,15 +359,16 @@ public class IssuesTest extends JexlTest ctxt.setSilent(false); JexlScript script; script = jexl.createScript("'hello world!'//commented"); - assertEquals("hello world!", script.execute(ctxt)); + Assert.assertEquals("hello world!", script.execute(ctxt)); script = jexl.createScript("'hello world!';//commented\n'bye...'"); - assertEquals("bye...", script.execute(ctxt)); + Assert.assertEquals("bye...", script.execute(ctxt)); script = jexl.createScript("'hello world!'## commented"); - assertEquals("hello world!", script.execute(ctxt)); + Assert.assertEquals("hello world!", script.execute(ctxt)); script = jexl.createScript("'hello world!';## commented\n'bye...'"); - assertEquals("bye...", script.execute(ctxt)); + Assert.assertEquals("bye...", script.execute(ctxt)); } + @Test public void test97() throws Exception { JexlEngine jexl = createEngine(false); JexlEvalContext ctxt = new JexlEvalContext(); @@ -370,11 +385,11 @@ public class IssuesTest extends JexlTest long start = System.nanoTime(); script = jexl.createExpression(input); Object value = script.evaluate(ctxt); - assertEquals(Integer.valueOf(11), value); + Assert.assertEquals(Integer.valueOf(11), value); long end = System.nanoTime(); double millisec = (end - start) / 1e6; double limit = 200.0; // Allow plenty of slack - assertTrue("Expected parse to take less than " + limit + "ms, actual " + millisec, millisec < limit); + Assert.assertTrue("Expected parse to take less than " + limit + "ms, actual " + millisec, millisec < limit); } public static class fn98 { @@ -383,6 +398,7 @@ public class IssuesTest extends JexlTest } } + @Test public void test98() throws Exception { String[] exprs = { "fn:replace('DOMAIN\\somename', '\\\\', '\\\\\\\\')", @@ -394,10 +410,11 @@ public class IssuesTest extends JexlTest JexlEngine jexl = new JexlBuilder().namespaces(funcs).create(); for (String expr : exprs) { Object value = jexl.createExpression(expr).evaluate(null); - assertEquals(expr, "DOMAIN\\\\somename", value); + Assert.assertEquals(expr, "DOMAIN\\\\somename", value); } } + @Test public void test100() throws Exception { JexlEngine jexl = new JexlBuilder().cache(4).create(); JexlContext ctxt = new MapContext(); @@ -406,13 +423,13 @@ public class IssuesTest extends JexlTest Object value; for (int l = 0; l < 2; ++l) { value = jexl.createExpression("foo[0]").evaluate(ctxt); - assertEquals(42, value); + Assert.assertEquals(42, value); value = jexl.createExpression("foo[0] = 43").evaluate(ctxt); - assertEquals(43, value); + Assert.assertEquals(43, value); value = jexl.createExpression("foo.0").evaluate(ctxt); - assertEquals(43, value); + Assert.assertEquals(43, value); value = jexl.createExpression("foo.0 = 42").evaluate(ctxt); - assertEquals(42, value); + Assert.assertEquals(42, value); } } @@ -444,19 +461,21 @@ public class IssuesTest extends JexlTest } } + @Test public void test105() throws Exception { JexlContext context = new MapContext(); JexlExpression selectExp = new Engine().createExpression("[a.propA]"); context.set("a", new A105("a1", "p1")); Object[] r = (Object[]) selectExp.evaluate(context); - assertEquals("p1", r[0]); + Assert.assertEquals("p1", r[0]); //selectExp = new Engine().createExpression("[a.propA]"); context.set("a", new A105("a2", "p2")); r = (Object[]) selectExp.evaluate(context); - assertEquals("p2", r[0]); + Assert.assertEquals("p2", r[0]); } + @Test public void test106() throws Exception { JexlEvalContext context = new JexlEvalContext(); context.setStrict(true, true); @@ -465,20 +484,21 @@ public class IssuesTest extends JexlTest JexlEngine jexl = new Engine(); try { Object value = jexl.createExpression("a / b").evaluate(context); - assertNotNull(value); + Assert.assertNotNull(value); } catch (JexlException xjexl) { - fail("should not occur"); + Assert.fail("should not occur"); } context.setMathContext(MathContext.UNLIMITED); context.setMathScale(2); try { jexl.createExpression("a / b").evaluate(context); - fail("should fail"); + Assert.fail("should fail"); } catch (JexlException xjexl) { //ok to fail } } + @Test public void test107() throws Exception { String[] exprs = { "'Q4'.toLowerCase()", "q4", @@ -498,65 +518,68 @@ public class IssuesTest extends JexlTest JexlExpression expr = jexl.createExpression(exprs[e]); Object expected = exprs[e + 1]; Object value = expr.evaluate(context); - assertEquals(expected, value); + Assert.assertEquals(expected, value); expr = jexl.createExpression(expr.getParsedText()); value = expr.evaluate(context); - assertEquals(expected, value); + Assert.assertEquals(expected, value); } } + @Test public void test108() throws Exception { JexlScript expr; Object value; JexlEngine jexl = new Engine(); expr = jexl.createScript("size([])"); value = expr.execute(null); - assertEquals(0, value); + Assert.assertEquals(0, value); expr = jexl.createScript(expr.getParsedText()); value = expr.execute(null); - assertEquals(0, value); + Assert.assertEquals(0, value); expr = jexl.createScript("if (true) { [] } else { {:} }"); value = expr.execute(null); - assertTrue(value.getClass().isArray()); + Assert.assertTrue(value.getClass().isArray()); expr = jexl.createScript(expr.getParsedText()); value = expr.execute(null); - assertTrue(value.getClass().isArray()); + Assert.assertTrue(value.getClass().isArray()); expr = jexl.createScript("size({:})"); value = expr.execute(null); - assertEquals(0, value); + Assert.assertEquals(0, value); expr = jexl.createScript(expr.getParsedText()); value = expr.execute(null); - assertEquals(0, value); + Assert.assertEquals(0, value); expr = jexl.createScript("if (false) { [] } else { {:} }"); value = expr.execute(null); - assertTrue(value instanceof Map<?, ?>); + Assert.assertTrue(value instanceof Map<?, ?>); expr = jexl.createScript(expr.getParsedText()); value = expr.execute(null); - assertTrue(value instanceof Map<?, ?>); + Assert.assertTrue(value instanceof Map<?, ?>); } + @Test public void test109() throws Exception { JexlEngine jexl = new Engine(); Object value; JexlContext context = new MapContext(); context.set("foo.bar", 40); value = jexl.createExpression("foo.bar + 2").evaluate(context); - assertEquals(42, value); + Assert.assertEquals(42, value); } + @Test public void test110() throws Exception { JexlEngine jexl = new Engine(); String[] names = {"foo"}; Object value; JexlContext context = new MapContext(); value = jexl.createScript("foo + 2", names).execute(context, 40); - assertEquals(42, value); + Assert.assertEquals(42, value); context.set("frak.foo", -40); value = jexl.createScript("frak.foo - 2", names).execute(context, 40); - assertEquals(-42, value); + Assert.assertEquals(-42, value); } static public class RichContext extends ObjectContext<A105> { @@ -565,15 +588,17 @@ public class IssuesTest extends JexlTest } } + @Test public void testRichContext() throws Exception { A105 a105 = new A105("foo", "bar"); JexlEngine jexl = new Engine(); Object value; JexlContext context = new RichContext(jexl, a105); value = jexl.createScript("uppercase(nameA + propA)").execute(context); - assertEquals("FOOBAR", value); + Assert.assertEquals("FOOBAR", value); } + @Test public void test111() throws Exception { JexlEngine jexl = new Engine(); Object value; @@ -584,44 +609,45 @@ public class IssuesTest extends JexlTest context.set("x", 1); context.set("y", 10); value = expr.evaluate(context); - assertEquals("FirstValue=9", value); + Assert.assertEquals("FirstValue=9", value); context.set("x", 1.0d); context.set("y", 10.0d); value = expr.evaluate(context); - assertEquals("FirstValue=9.0", value); + Assert.assertEquals("FirstValue=9.0", value); context.set("x", 1); context.set("y", 10.0d); value = expr.evaluate(context); - assertEquals("FirstValue=9.0", value); + Assert.assertEquals("FirstValue=9.0", value); context.set("x", 1.0d); context.set("y", 10); value = expr.evaluate(context); - assertEquals("FirstValue=9.0", value); + Assert.assertEquals("FirstValue=9.0", value); context.set("x", -10); context.set("y", 1); value = expr.evaluate(context); - assertEquals("SecondValue=-10", value); + Assert.assertEquals("SecondValue=-10", value); context.set("x", -10.0d); context.set("y", 1.0d); value = expr.evaluate(context); - assertEquals("SecondValue=-10.0", value); + Assert.assertEquals("SecondValue=-10.0", value); context.set("x", -10); context.set("y", 1.0d); value = expr.evaluate(context); - assertEquals("SecondValue=-10", value); + Assert.assertEquals("SecondValue=-10", value); context.set("x", -10.0d); context.set("y", 1); value = expr.evaluate(context); - assertEquals("SecondValue=-10.0", value); + Assert.assertEquals("SecondValue=-10.0", value); } + @Test public void testScaleIssue() throws Exception { JexlEngine jexlX = new Engine(); String expStr1 = "result == salary/month * work.percent/100.00"; @@ -633,31 +659,33 @@ public class IssuesTest extends JexlTest ctx.set("work.percent", new BigDecimal("100.00")); // will fail because default scale is 5 - assertFalse((Boolean) exp1.evaluate(ctx)); + Assert.assertFalse((Boolean) exp1.evaluate(ctx)); // will succeed with scale = 2 ctx.setMathScale(2); - assertTrue((Boolean) exp1.evaluate(ctx)); + Assert.assertTrue((Boolean) exp1.evaluate(ctx)); } + @Test public void test112() throws Exception { Object result; JexlEngine jexl = new Engine(); result = jexl.createScript(Integer.toString(Integer.MAX_VALUE)).execute(null); - assertEquals(Integer.MAX_VALUE, result); + Assert.assertEquals(Integer.MAX_VALUE, result); result = jexl.createScript(Integer.toString(Integer.MIN_VALUE + 1)).execute(null); - assertEquals(Integer.MIN_VALUE + 1, result); + Assert.assertEquals(Integer.MIN_VALUE + 1, result); result = jexl.createScript(Integer.toString(Integer.MIN_VALUE)).execute(null); - assertEquals(Integer.MIN_VALUE, result); + Assert.assertEquals(Integer.MIN_VALUE, result); } + @Test public void test117() throws Exception { JexlEngine jexl = new Engine(); JexlExpression e = jexl.createExpression("TIMESTAMP > 20100102000000"); JexlContext ctx = new MapContext(); ctx.set("TIMESTAMP", new Long("20100103000000")); Object result = e.evaluate(ctx); - assertTrue((Boolean) result); + Assert.assertTrue((Boolean) result); } public static class Foo125 { @@ -676,13 +704,15 @@ public class IssuesTest extends JexlTest } } + @Test public void test125() throws Exception { JexlEngine jexl = new Engine(); JexlExpression e = jexl.createExpression("method()"); JexlContext jc = new Foo125Context(jexl, new Foo125()); - assertEquals("OK", e.evaluate(jc)); + Assert.assertEquals("OK", e.evaluate(jc)); } + @Test public void test130a() throws Exception { String myName = "Test.Name"; Object myValue = "Test.Value"; @@ -692,9 +722,10 @@ public class IssuesTest extends JexlTest myMapContext.set(myName, myValue); Object myObjectWithTernaryConditional = myJexlEngine.createScript(myName + "?:null").execute(myMapContext); - assertEquals(myValue, myObjectWithTernaryConditional); + Assert.assertEquals(myValue, myObjectWithTernaryConditional); } + @Test public void test130b() throws Exception { String myName = "Test.Name"; Object myValue = new Object() { @@ -709,133 +740,10 @@ public class IssuesTest extends JexlTest myMapContext.set(myName, myValue); Object myObjectWithTernaryConditional = myJexlEngine.createScript(myName + "?:null").execute(myMapContext); - assertEquals(myValue, myObjectWithTernaryConditional); - } - - public void testBigdOp() throws Exception { - BigDecimal sevendot475 = new BigDecimal("7.475"); - BigDecimal SO = new BigDecimal("325"); - JexlContext jc = new MapContext(); - jc.set("SO", SO); - - JexlEngine jexl = new Engine(); - String expr = "2.3*SO/100"; - - Object evaluate = jexl.createExpression(expr).evaluate(jc); - assertEquals(sevendot475, (BigDecimal) evaluate); - } - - public static class Arithmetic132 extends JexlArithmetic { - public Arithmetic132() { - super(false); - } - - protected double divideZero(BigDecimal x) { - int ls = x.signum(); - if (ls < 0) { - return Double.NEGATIVE_INFINITY; - } else if (ls > 0) { - return Double.POSITIVE_INFINITY; - } else { - return Double.NaN; - } - } - - protected double divideZero(BigInteger x) { - int ls = x.signum(); - if (ls < 0) { - return Double.NEGATIVE_INFINITY; - } else if (ls > 0) { - return Double.POSITIVE_INFINITY; - } else { - return Double.NaN; - } - } - - @Override - public Object divide(Object left, Object right) { - if (left == null && right == null) { - return controlNullNullOperands(); - } - // if either are bigdecimal use that type - if (left instanceof BigDecimal || right instanceof BigDecimal) { - BigDecimal l = toBigDecimal(left); - BigDecimal r = toBigDecimal(right); - if (BigDecimal.ZERO.equals(r)) { - return divideZero(l); - } - BigDecimal result = l.divide(r, getMathContext()); - return narrowBigDecimal(left, right, result); - } - // if either are floating point (double or float) use double - if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) { - double l = toDouble(left); - double r = toDouble(right); - return new Double(l / r); - } - // otherwise treat as integers - BigInteger l = toBigInteger(left); - BigInteger r = toBigInteger(right); - if (BigInteger.ZERO.equals(r)) { - return divideZero(l); - } - BigInteger result = l.divide(r); - return narrowBigInteger(left, right, result); - } - - @Override - public Object mod(Object left, Object right) { - if (left == null && right == null) { - return controlNullNullOperands(); - } - // if either are bigdecimal use that type - if (left instanceof BigDecimal || right instanceof BigDecimal) { - BigDecimal l = toBigDecimal(left); - BigDecimal r = toBigDecimal(right); - if (BigDecimal.ZERO.equals(r)) { - return divideZero(l); - } - BigDecimal remainder = l.remainder(r, getMathContext()); - return narrowBigDecimal(left, right, remainder); - } - // if either are floating point (double or float) use double - if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) { - double l = toDouble(left); - double r = toDouble(right); - return new Double(l % r); - } - // otherwise treat as integers - BigInteger l = toBigInteger(left); - BigInteger r = toBigInteger(right); - BigInteger result = l.mod(r); - if (BigInteger.ZERO.equals(r)) { - return divideZero(l); - } - return narrowBigInteger(left, right, result); - } - } - - public void test132a() throws Exception { - Map<String, Object> ns = new HashMap<String, Object>(); - ns.put("math", Math.class); - JexlEngine jexl = new JexlBuilder().arithmetic(new Arithmetic132()).namespaces(ns).create(); - - Object evaluate = jexl.createExpression("1/0").evaluate(null); - assertTrue(Double.isInfinite((Double) evaluate)); - - evaluate = jexl.createExpression("-1/0").evaluate(null); - assertTrue(Double.isInfinite((Double) evaluate)); - - evaluate = jexl.createExpression("1.0/0.0").evaluate(null); - assertTrue(Double.isInfinite((Double) evaluate)); - - evaluate = jexl.createExpression("-1.0/0.0").evaluate(null); - assertTrue(Double.isInfinite((Double) evaluate)); - - evaluate = jexl.createExpression("math:abs(-42)").evaluate(null); - assertEquals(42, evaluate); + Assert.assertEquals(myValue, myObjectWithTernaryConditional); } + @Test public void test135() throws Exception { JexlEngine jexl = new Engine(); JexlContext jc = new MapContext(); @@ -847,39 +755,39 @@ public class IssuesTest extends JexlTest script = jexl.createScript("var y = state[3]; y"); result = script.execute(jc, foo); - assertEquals(42, result); + Assert.assertEquals(42, result); jc.set("a", 3); script = jexl.createScript("var y = state[a]; y"); result = script.execute(jc, foo); - assertEquals(42, result); + Assert.assertEquals(42, result); jc.set("a", 2); script = jexl.createScript("var y = state[a + 1]; y"); result = script.execute(jc, foo); - assertEquals(42, result); + Assert.assertEquals(42, result); jc.set("a", 2); jc.set("b", 1); script = jexl.createScript("var y = state[a + b]; y"); result = script.execute(jc, foo); - assertEquals(42, result); + Assert.assertEquals(42, result); script = jexl.createScript("var y = state[3]; y", "state"); result = script.execute(null, foo, 3); - assertEquals(42, result); + Assert.assertEquals(42, result); script = jexl.createScript("var y = state[a]; y", "state", "a"); result = script.execute(null, foo, 3); - assertEquals(42, result); + Assert.assertEquals(42, result); script = jexl.createScript("var y = state[a + 1]; y", "state", "a"); result = script.execute(null, foo, 2); - assertEquals(42, result); + Assert.assertEquals(42, result); script = jexl.createScript("var y = state[a + b]; y", "state", "a", "b"); result = script.execute(null, foo, 2, 1); - assertEquals(42, result); + Assert.assertEquals(42, result); } @Test @@ -898,23 +806,10 @@ public class IssuesTest extends JexlTest expr = jexl.createExpression("fn01(IDX)"); result = expr.evaluate(jc); - assertEquals("EXPR01 result", 22, result); + Assert.assertEquals("EXPR01 result", 22, result); } - public void test137() throws Exception { - JexlEngine jexl = new Engine(); - JexlContext jc = new MapContext(); - JexlScript script; - JexlExpression expr; - Object result; - - script = jexl.createScript("(x)->{ x }"); - Assert.assertArrayEquals(new String[]{"x"}, script.getParameters()); - result = script.execute(null, 42); - Assert.assertEquals(42, result); - } - -// public void test138() throws Exception { +// @Test public void test138() throws Exception { // MapContext ctxt = new MapContext(); // ctxt.set("tz", java.util.TimeZone.class); // String source = "" @@ -929,19 +824,9 @@ public class IssuesTest extends JexlTest // JexlEngine jexl = new Engine(); // JexlScript script = jexl.createScript(source); // Object result = script.execute(ctxt); -// Assert.assertNotNull(result); +// Assert.Assert.assertNotNull(result); // } - public void test142() throws Exception { - JexlEngine jexl = new Engine(); - JexlContext jc = new MapContext(); - JexlScript script; - Object result; - - script = jexl.createScript("map['']", "map"); - result = script.execute(jc, Collections.singletonMap("", 42)); - Assert.assertEquals(42, result); - } - + @Test public void test143() throws Exception { JexlEngine jexl = new Engine(); JexlContext jc = new MapContext(); @@ -956,9 +841,10 @@ public class IssuesTest extends JexlTest Assert.assertEquals(8, result); } + @Test public void test144() throws Exception { JexlEngine jexl = new Engine(); - JexlContext jc = new MapContext();//ObjectContext<Foo125>(jexl, new Foo125()); + JexlContext jc = new MapContext(); JexlScript script; Object result; script = jexl.createScript("var total = 10; total('tt')"); @@ -968,29 +854,6 @@ public class IssuesTest extends JexlTest } catch (JexlException.Method ambiguous) { Assert.assertEquals("total", ambiguous.getMethod()); } - jc = new ObjectContext<Foo125>(jexl, new Foo125()); - try { - result = script.execute(jc); - } catch (JexlException.Method ambiguous) { - Assert.fail("total() is solvable"); - } - } - - public void test145() throws Exception { - JexlEngine jexl = new Engine(); - JexlContext jc = new MapContext(); - 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 void test143apache() throws Exception { - JexlEngine jexl = new Engine(); - JexlExpression e = jexl.createExpression("9223372036854775806.5B"); - JexlContext context = new MapContext(); - String res = String.valueOf(e.evaluate(context)); - Assert.assertEquals("9223372036854775806.5", res); } /** @@ -1024,7 +887,8 @@ public class IssuesTest extends JexlTest } } - public void test144apache() throws Exception { + @Test + public void test144a() throws Exception { JexlEngine JEXL = new Engine(); JexlContext jc = new MapContext(); jc.set("quuxClass", Quux144.class); @@ -1034,60 +898,43 @@ public class IssuesTest extends JexlTest // test with a string Quux144 quux = (Quux144) create.evaluate(jc); - assertNotNull("quux is null", quux); + Assert.assertNotNull("quux is null", quux); // test with a nonempty string array Object o = assignArray.evaluate(jc); - assertEquals("Result is not a string array", String[].class, o.getClass()); + Assert.assertEquals("Result is not a string array", String[].class, o.getClass()); o = checkArray.evaluate(jc); - assertEquals("The array elements are equal", Arrays.asList("hello", "world"), Arrays.asList((String[]) o)); + Assert.assertEquals("The array elements are equal", Arrays.asList("hello", "world"), Arrays.asList((String[]) o)); // test with a null array assignArray = JEXL.createExpression("quux.arr = null"); o = assignArray.evaluate(jc); - assertNull("Result is not null", o); + Assert.assertNull("Result is not null", o); o = checkArray.evaluate(jc); - assertNull("Result is not null", o); + Assert.assertNull("Result is not null", o); // test with an empty array assignArray = JEXL.createExpression("quux.arr = [ ]"); o = assignArray.evaluate(jc); - assertNotNull("Result is null", o); + Assert.assertNotNull("Result is null", o); o = checkArray.evaluate(jc); - assertEquals("The array elements are not equal", Arrays.asList(new String[0]), Arrays.asList((String[]) o)); - assertEquals("The array size is not zero", 0, ((String[]) o).length); + Assert.assertEquals("The array elements are not equal", Arrays.asList(new String[0]), Arrays.asList((String[]) o)); + Assert.assertEquals("The array size is not zero", 0, ((String[]) o).length); // test with an empty array on the overloaded setter for different types. // so, the assignment should fail with logging 'The ambiguous property, arr2, should have failed.' try { assignArray = JEXL.createExpression("quux.arr2 = [ ]"); o = assignArray.evaluate(jc); - fail("The arr2 property shouldn't be set due to its ambiguity (overloaded setters with different types)."); + Assert.fail("The arr2 property shouldn't be set due to its ambiguity (overloaded setters with different types)."); } catch (JexlException.Property e) { //System.out.println("Expected ambiguous property setting exception: " + e); } - assertNull("The arr2 property value should remain as null, not an empty array.", quux.arr2); + Assert.assertNull("The arr2 property value should remain as null, not an empty array.", quux.arr2); } - public void test147() throws Exception { - JexlEngine JEXL = new Engine(); - JexlContext jc = new MapContext(); - JexlExpression e147 = JEXL.createExpression("quux = [one, two]"); - - jc.set("one", 1); - jc.set("two", 2); - int[] o1 = (int[]) e147.evaluate(jc); - assertEquals(1, o1[0]); - assertEquals(2, o1[1]); - - jc.set("one", 10); - jc.set("two", 20); - int[] o2 = (int[]) e147.evaluate(jc); - assertEquals(10, o2[0]); - assertEquals(20, o2[1]); - } - - public void test148() throws Exception { + @Test + public void test147b() throws Exception { String[] scripts = {"var x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x.one", // results to 1 "x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x.one",// results to 1 "x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x['one']",//results to 1 @@ -1095,6 +942,22 @@ public class IssuesTest extends JexlTest }; JexlEngine JEXL = new Engine(); + JexlContext jc = new MapContext(); + for (String s : scripts) { + Object o = JEXL.createScript(s).execute(jc); + Assert.assertEquals(1, o); + } + } + + @Test + public void test147c() throws Exception { + String[] scripts = { + "var x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x.one", + "x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x.one", + "x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x['one']", + "var x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x['one']" + }; + JexlEngine JEXL = new Engine(); for (String s : scripts) { JexlContext jc = new MapContext(); Object o = JEXL.createScript(s).execute(jc); @@ -1102,4 +965,76 @@ public class IssuesTest extends JexlTest } } + @Test + public void test5115a() throws Exception { + String str = "{\n" + + " var x = \"A comment\";\n" + + " var y = \"A comment\";\n" + + "}"; + try { + JexlEngine JEXL = new Engine(); + JexlScript s = JEXL.createScript(str); + } catch (JexlException.Parsing xparse) { + throw xparse; + } + } + + @Test + public void test5115b() throws Exception { + String str = "{\n" + + " var x = \"A comment\";\n" + + "}"; + try { + JexlEngine JEXL = new Engine(); + JexlScript s = JEXL.createScript(str); + } catch (JexlException.Parsing xparse) { + throw xparse; + } + } + + static final String TESTA = "src/test/scripts/testA.jexl"; + + @Test + public void test5115c() throws Exception { + URL testUrl = new File(TESTA).toURI().toURL(); + try { + JexlEngine JEXL = new Engine(); + JexlScript s = JEXL.createScript(testUrl); + } catch (JexlException.Parsing xparse) { + throw xparse; + } + } + + public static class Utils { + public <T> List<T> asList(T[] array) { + return Arrays.asList(array); + } + + public List<Integer> asList(int[] array) { + List<Integer> l = new ArrayList<Integer>(array.length); + for (int i : array) { + l.add(i); + } + return l; + } + } + + @Test + public void test148a() throws Exception { + JexlEngine jexl = new Engine(); + JexlContext jc = new MapContext(); + jc.set("u", new Utils()); + + String src = "u.asList(['foo', 'bar'])"; + JexlScript e = jexl.createScript(src); + Object o = e.execute(jc); + Assert.assertTrue(o instanceof List); + Assert.assertEquals(Arrays.asList("foo", "bar"), o); + + src = "u.asList([1, 2])"; + e = jexl.createScript(src); + o = e.execute(jc); + Assert.assertTrue(o instanceof List); + Assert.assertEquals(Arrays.asList(1, 2), o); + } }
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JXLTTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JXLTTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JXLTTest.java (original) +++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JXLTTest.java Wed Jun 10 16:30:16 2015 @@ -27,18 +27,23 @@ import java.io.Writer; import java.util.Arrays; import java.util.List; import java.util.Set; -import junit.framework.Assert; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; /** * Test cases for the UnifiedEL. */ +@SuppressWarnings({"UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"}) public class JXLTTest extends JexlTestCase { private static final JexlEngine ENGINE = new JexlBuilder().silent(false).cache(128).strict(true).create(); private static final JxltEngine JXLT = ENGINE.createJxltEngine(); private static final Logger LOG = LogManager.getLogger(JxltEngine.class); - private MapContext vars = new MapContext(); + private final MapContext vars = new MapContext(); private JexlEvalContext context = null; + @Before @Override public void setUp() throws Exception { // ensure jul logging is only error @@ -46,8 +51,9 @@ public class JXLTTest extends JexlTestCa context = new JexlEvalContext(vars); } + @After @Override - protected void tearDown() throws Exception { + public void tearDown() throws Exception { debuggerCheck(ENGINE); super.tearDown(); } @@ -90,43 +96,43 @@ public class JXLTTest extends JexlTestCa } } - public JXLTTest(String testName) { - super(testName); + public JXLTTest() { + super("JXLTTest"); } - public void testStatement() throws Exception { + @Test public void testStatement() throws Exception { Froboz froboz = new Froboz(32); context.set("froboz", froboz); JxltEngine.Expression check = JXLT.createExpression("${ froboz.plus10() }"); Object o = check.evaluate(context); - assertEquals("Result is not 32", new Integer(32), o); - assertEquals("Result is not 42", 42, froboz.getValue()); + Assert.assertEquals("Result is not 32", new Integer(32), o); + Assert.assertEquals("Result is not 42", 42, froboz.getValue()); Set<List<String>> evars = check.getVariables(); - assertEquals(1, evars.size()); + Assert.assertEquals(1, evars.size()); } - public void testAssign() throws Exception { + @Test public void testAssign() throws Exception { JxltEngine.Expression assign = JXLT.createExpression("${froboz.value = 10}"); JxltEngine.Expression check = JXLT.createExpression("${froboz.value}"); Object o = assign.evaluate(context); - assertEquals("Result is not 10", new Integer(10), o); + Assert.assertEquals("Result is not 10", new Integer(10), o); o = check.evaluate(context); - assertEquals("Result is not 10", new Integer(10), o); + Assert.assertEquals("Result is not 10", new Integer(10), o); } - public void testComposite() throws Exception { + @Test public void testComposite() throws Exception { String source = "Dear ${p} ${name};"; JxltEngine.Expression expr = JXLT.createExpression(source); context.set("p", "Mr"); context.set("name", "Doe"); - assertTrue("expression should be immediate", expr.isImmediate()); + Assert.assertTrue("expression should be immediate", expr.isImmediate()); Object o = expr.evaluate(context); - assertEquals("Dear Mr Doe;", o); + Assert.assertEquals("Dear Mr Doe;", o); context.set("p", "Ms"); context.set("name", "Jones"); o = expr.evaluate(context); - assertEquals("Dear Ms Jones;", o); - assertEquals(source, getSource(expr.toString())); + Assert.assertEquals("Dear Ms Jones;", o); + Assert.assertEquals(source, getSource(expr.toString())); } boolean contains(Set<List<String>> set, List<String> list) { @@ -138,156 +144,156 @@ public class JXLTTest extends JexlTestCa return false; } - public void testPrepareEvaluate() throws Exception { + @Test public void testPrepareEvaluate() throws Exception { final String source = "Dear #{p} ${name};"; JxltEngine.Expression expr = JXLT.createExpression("Dear #{p} ${name};"); - assertTrue("expression should be deferred", expr.isDeferred()); + Assert.assertTrue("expression should be deferred", expr.isDeferred()); Set<List<String>> evars = expr.getVariables(); - assertEquals(1, evars.size()); - assertTrue(contains(evars, Arrays.asList("name"))); + Assert.assertEquals(1, evars.size()); + Assert.assertTrue(contains(evars, Arrays.asList("name"))); context.set("name", "Doe"); JxltEngine.Expression phase1 = expr.prepare(context); String as = phase1.asString(); - assertEquals("Dear ${p} Doe;", as); + Assert.assertEquals("Dear ${p} Doe;", as); Set<List<String>> evars1 = phase1.getVariables(); - assertEquals(1, evars1.size()); - assertTrue(contains(evars1, Arrays.asList("p"))); + Assert.assertEquals(1, evars1.size()); + Assert.assertTrue(contains(evars1, Arrays.asList("p"))); vars.clear(); context.set("p", "Mr"); context.set("name", "Should not be used in 2nd phase"); Object o = phase1.evaluate(context); - assertEquals("Dear Mr Doe;", o); + Assert.assertEquals("Dear Mr Doe;", o); String p1 = getSource(phase1.toString()); - assertEquals(source, getSource(phase1.toString())); - assertEquals(source, getSource(expr.toString())); + Assert.assertEquals(source, getSource(phase1.toString())); + Assert.assertEquals(source, getSource(expr.toString())); } - public void testNested() throws Exception { + @Test public void testNested() throws Exception { final String source = "#{${hi}+'.world'}"; JxltEngine.Expression expr = JXLT.createExpression(source); Set<List<String>> evars = expr.getVariables(); - assertEquals(1, evars.size()); - assertTrue(contains(evars, Arrays.asList("hi"))); + Assert.assertEquals(1, evars.size()); + Assert.assertTrue(contains(evars, Arrays.asList("hi"))); context.set("hi", "greeting"); context.set("greeting.world", "Hello World!"); - assertTrue("expression should be deferred", expr.isDeferred()); + Assert.assertTrue("expression should be deferred", expr.isDeferred()); Object o = expr.evaluate(context); - assertEquals("Hello World!", o); + Assert.assertEquals("Hello World!", o); - assertEquals(source, getSource(expr.toString())); + Assert.assertEquals(source, getSource(expr.toString())); } - public void testImmediate() throws Exception { + @Test public void testImmediate() throws Exception { JexlContext none = null; final String source = "${'Hello ' + 'World!'}"; JxltEngine.Expression expr = JXLT.createExpression(source); JxltEngine.Expression prepared = expr.prepare(none); - assertEquals("prepare should return same expression", "Hello World!", prepared.asString()); + Assert.assertEquals("prepare should return same expression", "Hello World!", prepared.asString()); Object o = expr.evaluate(none); - assertTrue("expression should be immediate", expr.isImmediate()); - assertEquals("Hello World!", o); + Assert.assertTrue("expression should be immediate", expr.isImmediate()); + Assert.assertEquals("Hello World!", o); - assertEquals(source, getSource(expr.toString())); + Assert.assertEquals(source, getSource(expr.toString())); } - public void testConstant() throws Exception { + @Test public void testConstant() throws Exception { JexlContext none = null; final String source = "Hello World!"; JxltEngine.Expression expr = JXLT.createExpression(source); - assertTrue("prepare should return same expression", expr.prepare(none) == expr); + Assert.assertTrue("prepare should return same expression", expr.prepare(none) == expr); Object o = expr.evaluate(none); - assertTrue("expression should be immediate", expr.isImmediate()); - assertEquals("Hello World!", o); + Assert.assertTrue("expression should be immediate", expr.isImmediate()); + Assert.assertEquals("Hello World!", o); - assertEquals(source, getSource(expr.toString())); + Assert.assertEquals(source, getSource(expr.toString())); } - public void testConstant2() throws Exception { + @Test public void testConstant2() throws Exception { JexlContext none = null; final String source = "${size({'map':123,'map2':456})}"; JxltEngine.Expression expr = JXLT.createExpression(source); - //assertTrue("prepare should return same expression", expr.prepare(none) == expr); + //Assert.assertTrue("prepare should return same expression", expr.prepare(none) == expr); Object o = expr.evaluate(none); - assertTrue("expression should be immediate", expr.isImmediate()); - assertEquals(2, o); + Assert.assertTrue("expression should be immediate", expr.isImmediate()); + Assert.assertEquals(2, o); - assertEquals(source, getSource(expr.toString())); + Assert.assertEquals(source, getSource(expr.toString())); } - public void testConstant3() throws Exception { + @Test public void testConstant3() throws Exception { JexlContext none = null; final String source = "#{size({'map':123,'map2':456})}"; JxltEngine.Expression expr = JXLT.createExpression(source); - //assertTrue("prepare should return same expression", expr.prepare(none) == expr); + //Assert.assertTrue("prepare should return same expression", expr.prepare(none) == expr); Object o = expr.evaluate(none); - assertTrue("expression should be deferred", expr.isDeferred()); - assertEquals(2, o); + Assert.assertTrue("expression should be deferred", expr.isDeferred()); + Assert.assertEquals(2, o); - assertEquals(source, getSource(expr.toString())); + Assert.assertEquals(source, getSource(expr.toString())); } - public void testConstant4() throws Exception { + @Test public void testConstant4() throws Exception { JexlContext none = null; final String source = "#{ ${size({'1':2,'2': 3})} }"; JxltEngine.Expression expr = JXLT.createExpression(source); - //assertTrue("prepare should return same expression", expr.prepare(none) == expr); + //Assert.assertTrue("prepare should return same expression", expr.prepare(none) == expr); Object o = expr.evaluate(none); - assertTrue("expression should be deferred", expr.isDeferred()); - assertEquals(2, o); + Assert.assertTrue("expression should be deferred", expr.isDeferred()); + Assert.assertEquals(2, o); - assertEquals(source, getSource(expr.toString())); + Assert.assertEquals(source, getSource(expr.toString())); } - public void testDeferred() throws Exception { + @Test public void testDeferred() throws Exception { JexlContext none = null; final String source = "#{'world'}"; JxltEngine.Expression expr = JXLT.createExpression(source); - assertTrue("expression should be deferred", expr.isDeferred()); + Assert.assertTrue("expression should be deferred", expr.isDeferred()); String as = expr.prepare(none).asString(); - assertEquals("prepare should return immediate version", "${'world'}", as); + Assert.assertEquals("prepare should return immediate version", "${'world'}", as); Object o = expr.evaluate(none); - assertEquals("world", o); + Assert.assertEquals("world", o); - assertEquals(source, getSource(expr.toString())); + Assert.assertEquals(source, getSource(expr.toString())); } - public void testEscape() throws Exception { + @Test public void testEscape() throws Exception { JexlContext none = null; JxltEngine.Expression expr; Object o; // $ and # are escapable in TemplateEngine expr = JXLT.createExpression("\\#{'world'}"); o = expr.evaluate(none); - assertEquals("#{'world'}", o); + Assert.assertEquals("#{'world'}", o); expr = JXLT.createExpression("\\${'world'}"); o = expr.evaluate(none); - assertEquals("${'world'}", o); + Assert.assertEquals("${'world'}", o); } - public void testEscapeString() throws Exception { + @Test public void testEscapeString() throws Exception { JxltEngine.Expression expr = JXLT.createExpression("\\\"${'world\\'s finest'}\\\""); JexlContext none = null; Object o = expr.evaluate(none); - assertEquals("\"world's finest\"", o); + Assert.assertEquals("\"world's finest\"", o); } - public void testNonEscapeString() throws Exception { + @Test public void testNonEscapeString() throws Exception { JxltEngine.Expression expr = JXLT.createExpression("c:\\some\\windows\\path"); JexlContext none = null; Object o = expr.evaluate(none); - assertEquals("c:\\some\\windows\\path", o); + Assert.assertEquals("c:\\some\\windows\\path", o); } - public void testMalformed() throws Exception { + @Test public void testMalformed() throws Exception { try { JxltEngine.Expression expr = JXLT.createExpression("${'world'"); JexlContext none = null; expr.evaluate(none); - fail("should be malformed"); + Assert.fail("should be malformed"); } catch (JxltEngine.Exception xjexl) { // expected String xmsg = xjexl.getMessage(); @@ -295,12 +301,12 @@ public class JXLTTest extends JexlTestCa } } - public void testMalformedNested() throws Exception { + @Test public void testMalformedNested() throws Exception { try { JxltEngine.Expression expr = JXLT.createExpression("#{${hi} world}"); JexlContext none = null; expr.evaluate(none); - fail("should be malformed"); + Assert.fail("should be malformed"); } catch (JxltEngine.Exception xjexl) { // expected String xmsg = xjexl.getMessage(); @@ -308,13 +314,13 @@ public class JXLTTest extends JexlTestCa } } - public void testMalformedNested2() throws Exception { + @Test public void testMalformedNested2() throws Exception { try { JxltEngine.Expression expr = JXLT.createExpression("#{${hi} world}"); JexlContext ctxt = new MapContext(); ctxt.set("hi", "hello"); expr.evaluate(ctxt); - fail("should be malformed"); + Assert.fail("should be malformed"); } catch (JxltEngine.Exception xjexl) { // expected String xmsg = xjexl.getMessage(); @@ -323,12 +329,12 @@ public class JXLTTest extends JexlTestCa } - public void testBadContextNested() throws Exception { + @Test public void testBadContextNested() throws Exception { try { JxltEngine.Expression expr = JXLT.createExpression("#{${hi}+'.world'}"); JexlContext none = null; expr.evaluate(none); - fail("should be malformed"); + Assert.fail("should be malformed"); } catch (JxltEngine.Exception xjexl) { // expected String xmsg = xjexl.getMessage(); @@ -336,11 +342,11 @@ public class JXLTTest extends JexlTestCa } } - public void testCharAtBug() throws Exception { + @Test public void testCharAtBug() throws Exception { context.set("foo", "abcdef"); JxltEngine.Expression expr = JXLT.createExpression("${foo.substring(2,4)/*comment*/}"); Object o = expr.evaluate(context); - assertEquals("cd", o); + Assert.assertEquals("cd", o); context.set("bar", "foo"); try { @@ -348,14 +354,14 @@ public class JXLTTest extends JexlTestCa expr = JXLT.createExpression("#{${bar}+'.charAt(-2)'}"); expr = expr.prepare(context); o = expr.evaluate(context); - assertEquals(null, o); + Assert.assertEquals(null, o); } finally { context.setSilent(false); } } - public void testTemplate0() throws Exception { + @Test public void testTemplate0() throws Exception { String source = " $$ if(x) {\nx is ${x}\n $$ } else {\n${'no x'}\n$$ }\n"; StringWriter strw; String output; @@ -366,53 +372,53 @@ public class JXLTTest extends JexlTestCa strw = new StringWriter(); t.evaluate(context, strw); output = strw.toString(); - assertEquals("x is 42\n", output); + Assert.assertEquals("x is 42\n", output); strw = new StringWriter(); context.set("x", ""); t.evaluate(context, strw); output = strw.toString(); - assertEquals("no x\n", output); + Assert.assertEquals("no x\n", output); String dstr = t.toString(); - assertNotNull(dstr); + Assert.assertNotNull(dstr); } - public void testTemplate10() throws Exception { + @Test public void testTemplate10() throws Exception { String source = "$$(x)->{ if(x) {\nx is ${x}\n$$ } else {\n${'no x'}\n$$ } }\n"; StringWriter strw; String output; JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(source), (String[])null); String dstr = t.asString(); - assertNotNull(dstr); + Assert.assertNotNull(dstr); strw = new StringWriter(); t.evaluate(context, strw, 42); output = strw.toString(); - assertEquals("x is 42\n", output); + Assert.assertEquals("x is 42\n", output); } - public void testTemplate1() throws Exception { + @Test public void testTemplate1() throws Exception { String source = "$$ if(x) {\nx is ${x}\n$$ } else {\n${'no x'}\n$$ }\n"; StringWriter strw; String output; JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(source), "x"); String dstr = t.asString(); - assertNotNull(dstr); + Assert.assertNotNull(dstr); strw = new StringWriter(); t.evaluate(context, strw, 42); output = strw.toString(); - assertEquals("x is 42\n", output); + Assert.assertEquals("x is 42\n", output); strw = new StringWriter(); t.evaluate(context, strw, ""); output = strw.toString(); - assertEquals("no x\n", output); + Assert.assertEquals("no x\n", output); } - public void testPrepareTemplate() throws Exception { + @Test public void testPrepareTemplate() throws Exception { String source = "$$ for(var x : list) {\n" + "${l10n}=#{x}\n" @@ -420,9 +426,9 @@ public class JXLTTest extends JexlTestCa int[] args = {42}; JxltEngine.Template tl10n = JXLT.createTemplate(source, "list"); String dstr = tl10n.asString(); - assertNotNull(dstr); + Assert.assertNotNull(dstr); Set<List<String>> vars = tl10n.getVariables(); - assertFalse(vars.isEmpty()); + Assert.assertFalse(vars.isEmpty()); context.set("l10n", "valeur"); JxltEngine.Template tpFR = tl10n.prepare(context); context.set("l10n", "value"); @@ -433,16 +439,16 @@ public class JXLTTest extends JexlTestCa strw = new StringWriter(); tpFR.evaluate(context, strw, args); String outFR = strw.toString(); - assertEquals("valeur=42\n", outFR); + Assert.assertEquals("valeur=42\n", outFR); context.set("l10n", null); strw = new StringWriter(); tpEN.evaluate(context, strw, args); String outEN = strw.toString(); - assertEquals("value=42\n", outEN); + Assert.assertEquals("value=42\n", outEN); } - public void test42() throws Exception { + @Test public void test42() throws Exception { String test42 = "$$ for(var x : list) {\n" + "$$ if (x == 42) {\n" @@ -464,10 +470,10 @@ public class JXLTTest extends JexlTestCa + "The value 5 is under fourty-two\n" + "Life, the universe, and everything\n" + "The value 169 is over fourty-two\n"; - assertEquals(out42, output); + Assert.assertEquals(out42, output); String dstr = t.asString(); - assertNotNull(dstr); + Assert.assertNotNull(dstr); } public static class FrobozWriter extends PrintWriter { @@ -487,15 +493,15 @@ public class JXLTTest extends JexlTestCa } } - public void testWriter() throws Exception { + @Test public void testWriter() throws Exception { Froboz froboz = new Froboz(42); Writer writer = new FrobozWriter(new StringWriter()); JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader("$$$jexl.print(froboz)"), "froboz"); t.evaluate(context, writer, froboz); - assertEquals("froboz{42}", writer.toString()); + Assert.assertEquals("froboz{42}", writer.toString()); } - public void testReport() throws Exception { + @Test public void testReport() throws Exception { String rpt = "<report>\n" + "\n" @@ -510,10 +516,10 @@ public class JXLTTest extends JexlTestCa t.evaluate(context, strw); String output = strw.toString(); String ctl = "<report>\n\n\n 11\n</report>\n"; - assertEquals(ctl, output); + Assert.assertEquals(ctl, output); } - public void testReport1() throws Exception { + @Test public void testReport1() throws Exception { String rpt = "<report>\n" + "this is ${x}\n" @@ -533,28 +539,28 @@ public class JXLTTest extends JexlTestCa count += 1; } } - assertEquals(6, count); + Assert.assertEquals(6, count); } - public void testOneLiner() throws Exception { + @Test public void testOneLiner() throws Exception { JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader("fourty-two")); StringWriter strw = new StringWriter(); t.evaluate(context, strw); String output = strw.toString(); - assertEquals("fourty-two", output); + Assert.assertEquals("fourty-two", output); } - public void testOneLinerVar() throws Exception { + @Test public void testOneLinerVar() throws Exception { JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader("fourty-${x}")); StringWriter strw = new StringWriter(); context.set("x", "two"); t.evaluate(context, strw); String output = strw.toString(); - assertEquals("fourty-two", output); + Assert.assertEquals("fourty-two", output); } // -// public void testDeferredTemplate() throws Exception { +// @Test public void testDeferredTemplate() throws Exception { // JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader( // "select * from \n"+ // "##for(var c : tables) {\n"+ @@ -569,7 +575,7 @@ public class JXLTTest extends JexlTestCa // context.set("w" ,"x=1"); // t.evaluate(context, strw); // String output = strw.toString(); -// assertEquals("fourty-two", output); +// Assert.assertEquals("fourty-two", output); // // } } Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTest.java?rev=1684706&r1=1684705&r2=1684706&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTest.java (original) +++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTest.java Wed Jun 10 16:30:16 2015 @@ -31,23 +31,27 @@ import java.util.Map; import java.util.Set; import org.apache.commons.jexl3.parser.Parser; +import org.junit.Assert; +import org.junit.Test; /** - * Simple testcases + * Simple testcases * - * @since 1.0 + * @since 1.0 */ +@SuppressWarnings({"UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"}) public class JexlTest extends JexlTestCase { protected static final String METHOD_STRING = "Method string"; protected static final String GET_METHOD_STRING = "GetMethod string"; - public JexlTest(String testName) { - super(testName); + public JexlTest() { + super("JexlTest"); } /** - * test a simple property expression + * test a simple property expression */ + @Test public void testProperty() throws Exception { /* * tests a simple property expression @@ -59,10 +63,11 @@ public class JexlTest extends JexlTestCa jc.set("foo", new Foo()); Object o = e.evaluate(jc); - assertTrue("o not instanceof String", o instanceof String); - assertEquals("o incorrect", GET_METHOD_STRING, o); + Assert.assertTrue("o not instanceof String", o instanceof String); + Assert.assertEquals("o incorrect", GET_METHOD_STRING, o); } + @Test public void testBoolean() throws Exception { JexlContext jc = new MapContext(); jc.set("foo", new Foo()); @@ -77,6 +82,7 @@ public class JexlTest extends JexlTestCa assertExpression(jc, "true ne false", Boolean.TRUE); } + @Test public void testStringLit() throws Exception { /* * tests a simple property expression @@ -86,6 +92,7 @@ public class JexlTest extends JexlTestCa assertExpression(jc, "foo.get(\"woogie\")", "Repeat : woogie"); } + @Test public void testExpression() throws Exception { JexlContext jc = new MapContext(); jc.set("foo", new Foo()); @@ -145,6 +152,7 @@ public class JexlTest extends JexlTestCa assertExpression(jc, "num < bint", Boolean.TRUE); } + @Test public void testEmpty() throws Exception { JexlEvalContext jc = new JexlEvalContext(); jc.setStrict(false); @@ -168,6 +176,7 @@ public class JexlTest extends JexlTestCa assertExpression(jc, "not empty longstring", Boolean.TRUE); } + @Test public void testSize() throws Exception { JexlEvalContext jc = new JexlEvalContext(); jc.setStrict(false); @@ -221,6 +230,7 @@ public class JexlTest extends JexlTestCa assertExpression(jc, "list.get(list.size() - 1)", "5"); } + @Test public void testSizeAsProperty() throws Exception { JexlContext jc = new MapContext(); Map<String, Object> map = new HashMap<String, Object>(); @@ -237,8 +247,9 @@ public class JexlTest extends JexlTestCa } /** - * test the new function e.g constructor invocation + * test the new function e.g constructor invocation */ + @Test public void testNew() throws Exception { JexlContext jc = new MapContext(); jc.set("double", Double.class); @@ -247,18 +258,19 @@ public class JexlTest extends JexlTestCa Object value; expr = JEXL.createExpression("new(double, 1)"); value = expr.evaluate(jc); - assertEquals(expr.toString(), new Double(1.0), value); + Assert.assertEquals(expr.toString(), new Double(1.0), value); expr = JEXL.createExpression("new('java.lang.Float', 100)"); value = expr.evaluate(jc); - assertEquals(expr.toString(), new Float(100.0), value); + Assert.assertEquals(expr.toString(), new Float(100.0), value); expr = JEXL.createExpression("new(foo).quux"); value = expr.evaluate(jc); - assertEquals(expr.toString(), "Repeat : quux", value); + Assert.assertEquals(expr.toString(), "Repeat : quux", value); } /** - * test some simple mathematical calculations + * test some simple mathematical calculations */ + @Test public void testCalculations() throws Exception { JexlEvalContext jc = new JexlEvalContext(); jc.setStrict(false); @@ -282,8 +294,9 @@ public class JexlTest extends JexlTestCa } /** - * test some simple conditions + * test some simple conditions */ + @Test public void testConditions() throws Exception { JexlEvalContext jc = new JexlEvalContext(); jc.set("foo", new Integer(2)); @@ -329,8 +342,9 @@ public class JexlTest extends JexlTestCa } /** - * test some simple conditions + * test some simple conditions */ + @Test public void testNotConditions() throws Exception { JexlContext jc = new MapContext(); @@ -360,8 +374,9 @@ public class JexlTest extends JexlTestCa } /** - * test some simple conditions + * test some simple conditions */ + @Test public void testNotConditionsWithDots() throws Exception { JexlContext jc = new MapContext(); @@ -374,8 +389,9 @@ public class JexlTest extends JexlTestCa } /** - * test some simple conditions + * test some simple conditions */ + @Test public void testComparisons() throws Exception { JexlContext jc = new MapContext(); jc.set("foo", "the quick and lazy fox"); @@ -386,8 +402,9 @@ public class JexlTest extends JexlTestCa } /** - * test some null conditions + * test some null conditions */ + @Test public void testNull() throws Exception { JexlEvalContext jc = new JexlEvalContext(); jc.setStrict(false); @@ -405,6 +422,7 @@ public class JexlTest extends JexlTestCa /** * test quoting in strings */ + @Test public void testStringQuoting() throws Exception { JexlContext jc = new MapContext(); assertExpression(jc, "'\"Hello\"'", "\"Hello\""); @@ -412,8 +430,9 @@ public class JexlTest extends JexlTestCa } /** - * test some blank strings + * test some blank strings */ + @Test public void testBlankStrings() throws Exception { JexlContext jc = new MapContext(); jc.set("bar", ""); @@ -425,8 +444,9 @@ public class JexlTest extends JexlTestCa } /** - * test some blank strings + * test some blank strings */ + @Test public void testLogicExpressions() throws Exception { JexlContext jc = new MapContext(); jc.set("foo", "abc"); @@ -444,8 +464,9 @@ public class JexlTest extends JexlTestCa } /** - * test variables with underscore names + * test variables with underscore names */ + @Test public void testVariableNames() throws Exception { JexlContext jc = new MapContext(); jc.set("foo_bar", "123"); @@ -454,8 +475,9 @@ public class JexlTest extends JexlTestCa } /** - * test the use of dot notation to lookup map entries + * test the use of dot notation to lookup map entries */ + @Test public void testMapDot() throws Exception { Map<String, String> foo = new HashMap<String, String>(); foo.put("bar", "123"); @@ -467,8 +489,9 @@ public class JexlTest extends JexlTestCa } /** - * Tests string literals + * Tests string literals */ + @Test public void testStringLiterals() throws Exception { JexlContext jc = new MapContext(); jc.set("foo", "bar"); @@ -478,14 +501,15 @@ public class JexlTest extends JexlTestCa } /** - * test the use of an int based property + * test the use of an int based property */ + @Test public void testIntProperty() throws Exception { Foo foo = new Foo(); // lets check the square function first.. - assertEquals(4, foo.square(2)); - assertEquals(4, foo.square(-2)); + Assert.assertEquals(4, foo.square(2)); + Assert.assertEquals(4, foo.square(-2)); JexlContext jc = new MapContext(); jc.set("foo", foo); @@ -496,8 +520,9 @@ public class JexlTest extends JexlTestCa } /** - * test the -1 comparison bug + * test the -1 comparison bug */ + @Test public void testNegativeIntComparison() throws Exception { JexlContext jc = new MapContext(); Foo foo = new Foo(); @@ -511,6 +536,7 @@ public class JexlTest extends JexlTestCa /** * Attempts to recreate bug http://jira.werken.com/ViewIssue.jspa?key=JELLY-8 */ + @Test public void testCharAtBug() throws Exception { JexlEvalContext jc = new JexlEvalContext(); jc.setSilent(true); @@ -523,6 +549,7 @@ public class JexlTest extends JexlTestCa } + @Test public void testEmptyDottedVariableName() throws Exception { JexlContext jc = new MapContext(); @@ -531,6 +558,7 @@ public class JexlTest extends JexlTestCa assertExpression(jc, "empty(this.is.a.test)", Boolean.TRUE); } + @Test public void testEmptySubListOfMap() throws Exception { JexlContext jc = new MapContext(); Map<String, ArrayList<?>> m = new HashMap<String, ArrayList<?>>(); @@ -541,6 +569,7 @@ public class JexlTest extends JexlTestCa assertExpression(jc, "empty( aMap.aList )", Boolean.TRUE); } + @Test public void testCoercionWithComparisionOperators() throws Exception { JexlContext jc = new MapContext(); @@ -563,6 +592,7 @@ public class JexlTest extends JexlTestCa * Test that 'and' only evaluates the second item if needed * @throws Exception if there are errors */ + @Test public void testBooleanShortCircuitAnd() throws Exception { // handle false for the left arg of 'and' Foo tester = new Foo(); @@ -571,19 +601,20 @@ public class JexlTest extends JexlTestCa jc.set("foo", tester); JexlExpression expr = JEXL.createExpression("first and foo.trueAndModify"); expr.evaluate(jc); - assertTrue("Short circuit failure: rhs evaluated when lhs FALSE", !tester.getModified()); + Assert.assertTrue("Short circuit failure: rhs evaluated when lhs FALSE", !tester.getModified()); // handle true for the left arg of 'and' tester = new Foo(); jc.set("first", Boolean.TRUE); jc.set("foo", tester); expr.evaluate(jc); - assertTrue("Short circuit failure: rhs not evaluated when lhs TRUE", tester.getModified()); + Assert.assertTrue("Short circuit failure: rhs not evaluated when lhs TRUE", tester.getModified()); } /** * Test that 'or' only evaluates the second item if needed * @throws Exception if there are errors */ + @Test public void testBooleanShortCircuitOr() throws Exception { // handle false for the left arg of 'or' Foo tester = new Foo(); @@ -592,19 +623,20 @@ public class JexlTest extends JexlTestCa jc.set("foo", tester); JexlExpression expr = JEXL.createExpression("first or foo.trueAndModify"); expr.evaluate(jc); - assertTrue("Short circuit failure: rhs not evaluated when lhs FALSE", tester.getModified()); + Assert.assertTrue("Short circuit failure: rhs not evaluated when lhs FALSE", tester.getModified()); // handle true for the left arg of 'or' tester = new Foo(); jc.set("first", Boolean.TRUE); jc.set("foo", tester); expr.evaluate(jc); - assertTrue("Short circuit failure: rhs evaluated when lhs TRUE", !tester.getModified()); + Assert.assertTrue("Short circuit failure: rhs evaluated when lhs TRUE", !tester.getModified()); } /** * Simple test of '+' as a string concatenation operator * @throws Exception */ + @Test public void testStringConcatenation() throws Exception { JexlContext jc = new MapContext(); jc.set("first", "Hello"); @@ -612,20 +644,22 @@ public class JexlTest extends JexlTestCa assertExpression(jc, "first + ' ' + second", "Hello World"); } + @Test public void testToString() throws Exception { String code = "abcd"; JexlExpression expr = JEXL.createExpression(code); - assertEquals("Bad expression value", code, expr.toString()); + Assert.assertEquals("Bad expression value", code, expr.toString()); } /** * Make sure bad syntax throws ParseException * @throws Exception on errors */ + @Test public void testBadParse() throws Exception { try { assertExpression(new MapContext(), "empty()", null); - fail("Bad expression didn't throw ParseException"); + Assert.fail("Bad expression didn't throw ParseException"); } catch (JexlException pe) { // expected behaviour } @@ -635,6 +669,7 @@ public class JexlTest extends JexlTestCa * Test the ## comment in a string * @throws Exception */ + @Test public void testComment() throws Exception { assertExpression(new MapContext(), "## double or nothing\n 1 + 1", Integer.valueOf("2")); } @@ -643,6 +678,7 @@ public class JexlTest extends JexlTestCa * Test assignment. * @throws Exception */ + @Test public void testAssignment() throws Exception { JexlContext jc = new MapContext(); jc.set("aString", "Hello"); @@ -652,14 +688,15 @@ public class JexlTest extends JexlTestCa parser.parse(null, "aString = 'World';", null, false, false); assertExpression(jc, "hello = 'world'", "world"); - assertEquals("hello variable not changed", "world", jc.get("hello")); + Assert.assertEquals("hello variable not changed", "world", jc.get("hello")); assertExpression(jc, "result = 1 + 1", new Integer(2)); - assertEquals("result variable not changed", new Integer(2), jc.get("result")); + Assert.assertEquals("result variable not changed", new Integer(2), jc.get("result")); // todo: make sure properties can be assigned to, fall back to flat var if no property // assertExpression(jc, "foo.property1 = '99'", "99"); - // assertEquals("property not set", "99", foo.getProperty1()); + // Assert.assertEquals("property not set", "99", foo.getProperty1()); } + @Test public void testAntPropertiesWithMethods() throws Exception { JexlContext jc = new MapContext(); String value = "Stinky Cheese"; @@ -675,6 +712,7 @@ public class JexlTest extends JexlTestCa // assertExpression(jc, "commons-logging", version); } + @Test public void testUnicodeSupport() throws Exception { JexlContext jc = new MapContext(); assertExpression(jc, "'x' == '\\u0032?ytkownik'", Boolean.FALSE); @@ -716,6 +754,7 @@ public class JexlTest extends JexlTestCa } @SuppressWarnings("boxing") + @Test public void testDuck() throws Exception { JexlEngine jexl = JEXL; JexlContext jc = new MapContext(); @@ -724,25 +763,26 @@ public class JexlTest extends JexlTestCa Object result; expr = jexl.createExpression("duck.zero"); result = expr.evaluate(jc); - assertEquals(expr.toString(), 0, result); + Assert.assertEquals(expr.toString(), 0, result); expr = jexl.createExpression("duck.one"); result = expr.evaluate(jc); - assertEquals(expr.toString(), 1, result); + Assert.assertEquals(expr.toString(), 1, result); expr = jexl.createExpression("duck.user = 20"); result = expr.evaluate(jc); - assertEquals(expr.toString(), 20, result); + Assert.assertEquals(expr.toString(), 20, result); expr = jexl.createExpression("duck.user"); result = expr.evaluate(jc); - assertEquals(expr.toString(), 20, result); + Assert.assertEquals(expr.toString(), 20, result); expr = jexl.createExpression("duck.user = 'zero'"); result = expr.evaluate(jc); - assertEquals(expr.toString(), "zero", result); + Assert.assertEquals(expr.toString(), "zero", result); expr = jexl.createExpression("duck.user"); result = expr.evaluate(jc); - assertEquals(expr.toString(), 0, result); + Assert.assertEquals(expr.toString(), 0, result); } @SuppressWarnings("boxing") + @Test public void testArray() throws Exception { int[] array = {100, 101, 102}; JexlEngine jexl = JEXL; @@ -752,13 +792,13 @@ public class JexlTest extends JexlTestCa Object result; expr = jexl.createExpression("array.1"); result = expr.evaluate(jc); - assertEquals(expr.toString(), 101, result); + Assert.assertEquals(expr.toString(), 101, result); expr = jexl.createExpression("array[1] = 1010"); result = expr.evaluate(jc); - assertEquals(expr.toString(), 1010, result); + Assert.assertEquals(expr.toString(), 1010, result); expr = jexl.createExpression("array.0"); result = expr.evaluate(jc); - assertEquals(expr.toString(), 100, result); + Assert.assertEquals(expr.toString(), 100, result); } /** @@ -768,6 +808,6 @@ public class JexlTest extends JexlTestCa protected void assertExpression(JexlContext jc, String expression, Object expected) throws Exception { JexlExpression e = JEXL.createExpression(expression); Object actual = e.evaluate(jc); - assertEquals(expression, expected, actual); + Assert.assertEquals(expression, expected, actual); } -} \ No newline at end of file +} Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTestCase.java?rev=1684706&r1=1684705&r2=1684706&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTestCase.java (original) +++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTestCase.java Wed Jun 10 16:30:16 2015 @@ -21,15 +21,16 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import junit.framework.TestCase; import org.apache.commons.jexl3.internal.Util; +import org.junit.After; +import org.junit.Assert; /** * Implements runTest methods to dynamically instantiate and invoke a test, * wrapping the call with setUp(), tearDown() calls. * Eases the implementation of main methods to debug. */ -public class JexlTestCase extends TestCase { +public class JexlTestCase { /** No parameters signature for test run. */ private static final Class<?>[] noParms = {}; /** String parameter signature for test run. */ @@ -43,12 +44,16 @@ public class JexlTestCase extends TestCa } protected JexlTestCase(String name, JexlEngine jexl) { - super(name); + //super(name); JEXL = jexl; } - @Override - protected void tearDown() throws Exception { + public void setUp() throws Exception { + // nothing to do + } + + @After + public void tearDown() throws Exception { debuggerCheck(JEXL); } @@ -80,7 +85,7 @@ public class JexlTestCase extends TestCa method = this.getClass().getDeclaredMethod(name, noParms); } catch(Exception xany) { - fail("no such test: " + name); + Assert.fail("no such test: " + name); return; } try { @@ -112,7 +117,7 @@ public class JexlTestCase extends TestCa clazz = (Class<JexlTestCase>) Class.forName(testClassName); } catch(ClassNotFoundException xclass) { - fail("no such class: " + testClassName); + Assert.fail("no such class: " + testClassName); return; } // find ctor & instantiate @@ -127,12 +132,12 @@ public class JexlTestCase extends TestCa test = clazz.newInstance(); } catch(Exception xany) { - fail("cant instantiate test: " + xany); + Assert.fail("cant instantiate test: " + xany); return; } } catch(Exception xany) { - fail("cant instantiate test: " + xany); + Assert.fail("cant instantiate test: " + xany); return; } // Run the test