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 2018/01/18 09:38:46 UTC
svn commit: r1821466 - in
/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3:
examples/ internal/introspection/ junit/ scripting/
Author: henrib
Date: Thu Jan 18 09:38:46 2018
New Revision: 1821466
URL: http://svn.apache.org/viewvc?rev=1821466&view=rev
Log:
JEXL:
Removing references to junit.framework, replaced by org.junit
Modified:
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/MethodPropertyTest.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/Output.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/MethodKeyTest.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/Asserter.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/AsserterTest.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineTest.java
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/MethodPropertyTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/MethodPropertyTest.java?rev=1821466&r1=1821465&r2=1821466&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/MethodPropertyTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/MethodPropertyTest.java Thu Jan 18 09:38:46 2018
@@ -17,19 +17,19 @@
package org.apache.commons.jexl3.examples;
-import junit.framework.TestCase;
import org.apache.commons.jexl3.JexlBuilder;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.JexlEngine;
import org.apache.commons.jexl3.MapContext;
+import org.junit.Test;
/**
* Simple example to show how to access method and properties.
*
* @since 1.0
*/
-public class MethodPropertyTest extends TestCase {
+public class MethodPropertyTest {
/**
* An example for method access.
*/
@@ -120,6 +120,7 @@ public class MethodPropertyTest extends
* Unit test entry point.
* @throws Exception
*/
+ @Test
public void testExample() throws Exception {
example(Output.JUNIT);
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/Output.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/Output.java?rev=1821466&r1=1821465&r2=1821466&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/Output.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/Output.java Thu Jan 18 09:38:46 2018
@@ -16,7 +16,8 @@
*/
package org.apache.commons.jexl3.examples;
-import junit.framework.TestCase;
+
+import org.junit.Assert;
/**
* Abstracts using a test within Junit or through a main method.
@@ -43,7 +44,7 @@ public abstract class Output {
public static final Output JUNIT = new Output() {
@Override
public void print(String expr, Object actual, Object expected) {
- TestCase.assertEquals(expr, expected, actual);
+ Assert.assertEquals(expr, expected, actual);
}
};
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/MethodKeyTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/MethodKeyTest.java?rev=1821466&r1=1821465&r2=1821466&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/MethodKeyTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/MethodKeyTest.java Thu Jan 18 09:38:46 2018
@@ -16,13 +16,13 @@
*/
package org.apache.commons.jexl3.internal.introspection;
-import junit.framework.TestCase;
+import org.junit.Assert;
import org.junit.Test;
/**
* Checks the CacheMap.MethodKey implementation
*/
-public class MethodKeyTest extends TestCase {
+public class MethodKeyTest {
// A set of classes (most of them primitives)
private static final Class<?>[] PRIMS = {
Boolean.TYPE,
@@ -75,25 +75,25 @@ public class MethodKeyTest extends TestC
"invokeIt"
};
/** from key to string */
- private static final java.util.Map< MethodKey, String> byKey;
+ private static final java.util.Map< MethodKey, String> BY_KEY;
/** form string to key */
- private static final java.util.Map<String, MethodKey> byString;
+ private static final java.util.Map<String, MethodKey> BY_STRING;
/** the list of keys we generated & test against */
- private static final MethodKey[] keyList;
+ private static final MethodKey[] KEY_LIST;
- /** Creates & inserts a key into the byKey & byString map */
+ /** * Creates & inserts a key into the BY_KEY & byString map */
private static void setUpKey(String name, Class<?>[] parms) {
MethodKey key = new MethodKey(name, parms);
String str = key.toString();
- byKey.put(key, str);
- byString.put(str, key);
+ BY_KEY.put(key, str);
+ BY_STRING.put(str, key);
}
/** Generate a list of method*(prims*), method(prims*, prims*), method*(prims*,prims*,prims*) */
static {
- byKey = new java.util.HashMap< MethodKey, String>();
- byString = new java.util.HashMap<String, MethodKey>();
+ BY_KEY = new java.util.HashMap< MethodKey, String>();
+ BY_STRING = new java.util.HashMap<String, MethodKey>();
for (int m = 0; m < METHODS.length; ++m) {
String method = METHODS[m];
for (int p0 = 0; p0 < PRIMS.length; ++p0) {
@@ -109,7 +109,7 @@ public class MethodKeyTest extends TestC
}
}
}
- keyList = byKey.keySet().toArray(new MethodKey[byKey.size()]);
+ KEY_LIST = BY_KEY.keySet().toArray(new MethodKey[BY_KEY.size()]);
}
/** Builds a string key */
@@ -124,8 +124,8 @@ public class MethodKeyTest extends TestC
/** Checks that a string key does exist */
void checkStringKey(String method, Class<?>... params) {
String key = makeStringKey(method, params);
- MethodKey out = byString.get(key);
- assertTrue(out != null);
+ MethodKey out = BY_STRING.get(key);
+ Assert.assertTrue(out != null);
}
/** Builds a method key */
@@ -136,30 +136,30 @@ public class MethodKeyTest extends TestC
/** Checks that a method key exists */
void checkKey(String method, Class<?>... params) {
MethodKey key = makeKey(method, params);
- String out = byKey.get(key);
- assertTrue(out != null);
+ String out = BY_KEY.get(key);
+ Assert.assertTrue(out != null);
}
@Test
public void testObjectKey() throws Exception {
- for (int k = 0; k < keyList.length; ++k) {
- MethodKey ctl = keyList[k];
+ for (int k = 0; k < KEY_LIST.length; ++k) {
+ MethodKey ctl = KEY_LIST[k];
MethodKey key = makeKey(ctl.getMethod(), ctl.getParameters());
- String out = byKey.get(key);
- assertTrue(out != null);
- assertTrue(ctl.toString() + " != " + out, ctl.toString().equals(out));
+ String out = BY_KEY.get(key);
+ Assert.assertTrue(out != null);
+ Assert.assertTrue(ctl.toString() + " != " + out, ctl.toString().equals(out));
}
}
@Test
public void testStringKey() throws Exception {
- for (int k = 0; k < keyList.length; ++k) {
- MethodKey ctl = keyList[k];
+ for (int k = 0; k < KEY_LIST.length; ++k) {
+ MethodKey ctl = KEY_LIST[k];
String key = makeStringKey(ctl.getMethod(), ctl.getParameters());
- MethodKey out = byString.get(key);
- assertTrue(out != null);
- assertTrue(ctl.toString() + " != " + key, ctl.equals(out));
+ MethodKey out = BY_STRING.get(key);
+ Assert.assertTrue(out != null);
+ Assert.assertTrue(ctl.toString() + " != " + key, ctl.equals(out));
}
}
@@ -168,11 +168,11 @@ public class MethodKeyTest extends TestC
@Test
public void testPerfKey() throws Exception {
for (int l = 0; l < LOOP; ++l) {
- for (int k = 0; k < keyList.length; ++k) {
- MethodKey ctl = keyList[k];
+ for (int k = 0; k < KEY_LIST.length; ++k) {
+ MethodKey ctl = KEY_LIST[k];
MethodKey key = makeKey(ctl.getMethod(), ctl.getParameters());
- String out = byKey.get(key);
- assertTrue(out != null);
+ String out = BY_KEY.get(key);
+ Assert.assertTrue(out != null);
}
}
}
@@ -180,11 +180,11 @@ public class MethodKeyTest extends TestC
@Test
public void testPerfString() throws Exception {
for (int l = 0; l < LOOP; ++l) {
- for (int k = 0; k < keyList.length; ++k) {
- MethodKey ctl = keyList[k];
+ for (int k = 0; k < KEY_LIST.length; ++k) {
+ MethodKey ctl = KEY_LIST[k];
String key = makeStringKey(ctl.getMethod(), ctl.getParameters());
- MethodKey out = byString.get(key);
- assertTrue(out != null);
+ MethodKey out = BY_STRING.get(key);
+ Assert.assertTrue(out != null);
}
}
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/Asserter.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/Asserter.java?rev=1821466&r1=1821465&r2=1821466&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/Asserter.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/Asserter.java Thu Jan 18 09:38:46 2018
@@ -16,11 +16,11 @@
*/
package org.apache.commons.jexl3.junit;
+import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
-import junit.framework.Assert;
import org.apache.commons.jexl3.JexlEvalContext;
import org.apache.commons.jexl3.JexlArithmetic;
@@ -28,6 +28,8 @@ import org.apache.commons.jexl3.JexlCont
import org.apache.commons.jexl3.JexlEngine;
import org.apache.commons.jexl3.JexlException;
import org.apache.commons.jexl3.JexlScript;
+import org.junit.Assert;
+import static org.junit.Assert.fail;
/**
* A utility class for performing JUnit based assertions using Jexl
@@ -99,16 +101,26 @@ public class Asserter extends Assert {
Object value = exp.execute(context);
if (expected instanceof BigDecimal) {
JexlArithmetic jexla = engine.getArithmetic();
- assertTrue("expression: " + expression, ((BigDecimal) expected).compareTo(jexla.toBigDecimal(value)) == 0);
+ Assert.assertTrue("expression: " + expression, ((BigDecimal) expected).compareTo(jexla.toBigDecimal(value)) == 0);
}
if (expected != null && value != null) {
- assertEquals("expression: " + expression + ", "
- + expected.getClass().getSimpleName()
- + " ?= "
- + value.getClass().getSimpleName(),
- expected, value);
+ if (expected.getClass().isArray() && value.getClass().isArray()) {
+ int esz = Array.getLength(expected);
+ int vsz = Array.getLength(value);
+ String report = "expression: " + expression;
+ Assert.assertEquals(report + ", array size", esz, vsz);
+ for (int i = 0; i < vsz; ++i) {
+ Assert.assertEquals(report + ", value@[]" + i, Array.get(expected, i), Array.get(value, i));
+ }
+ } else {
+ Assert.assertEquals("expression: " + expression + ", "
+ + expected.getClass().getSimpleName()
+ + " ?= "
+ + value.getClass().getSimpleName(),
+ expected, value);
+ }
} else {
- assertEquals("expression: " + expression, expected, value);
+ Assert.assertEquals("expression: " + expression, expected, value);
}
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/AsserterTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/AsserterTest.java?rev=1821466&r1=1821465&r2=1821466&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/AsserterTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/AsserterTest.java Thu Jan 18 09:38:46 2018
@@ -17,8 +17,6 @@
/* $Id$ */
package org.apache.commons.jexl3.junit;
-import junit.framework.AssertionFailedError;
-
import org.apache.commons.jexl3.Foo;
import org.apache.commons.jexl3.JexlTestCase;
import org.junit.Assert;
@@ -44,7 +42,7 @@ public class AsserterTest extends JexlTe
asserter.assertExpression("this.count", "Wrong Value");
Assert.fail("This method should have thrown an assertion exception");
}
- catch (AssertionFailedError e) {
+ catch (AssertionError e) {
// it worked!
}
}
@@ -66,7 +64,7 @@ public class AsserterTest extends JexlTe
asserter.assertExpression("bar.count", new Integer(5));
Assert.fail("This method should have thrown an assertion exception");
}
- catch (AssertionFailedError e) {
+ catch (AssertionError e) {
// it worked!
}
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineTest.java?rev=1821466&r1=1821465&r2=1821466&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineTest.java Thu Jan 18 09:38:46 2018
@@ -25,9 +25,10 @@ import java.util.Map;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
-public class JexlScriptEngineTest extends TestCase {
+public class JexlScriptEngineTest {
private static final List<String> NAMES = Arrays.asList("JEXL", "Jexl", "jexl",
"JEXL2", "Jexl2", "jexl2",
"JEXL3", "Jexl3", "jexl3");
@@ -38,87 +39,91 @@ public class JexlScriptEngineTest extend
public void testScriptEngineFactory() throws Exception {
JexlScriptEngineFactory factory = new JexlScriptEngineFactory();
- assertEquals("JEXL Engine", factory.getParameter(ScriptEngine.ENGINE));
- assertEquals("3.2", factory.getParameter(ScriptEngine.ENGINE_VERSION));
- assertEquals("JEXL", factory.getParameter(ScriptEngine.LANGUAGE));
- assertEquals("3.2", factory.getParameter(ScriptEngine.LANGUAGE_VERSION));
- assertNull(factory.getParameter("THREADING"));
- assertEquals(NAMES, factory.getParameter(ScriptEngine.NAME));
- assertEquals(EXTENSIONS, factory.getExtensions());
- assertEquals(MIMES, factory.getMimeTypes());
+ Assert.assertEquals("JEXL Engine", factory.getParameter(ScriptEngine.ENGINE));
+ Assert.assertEquals("3.2", factory.getParameter(ScriptEngine.ENGINE_VERSION));
+ Assert.assertEquals("JEXL", factory.getParameter(ScriptEngine.LANGUAGE));
+ Assert.assertEquals("3.2", factory.getParameter(ScriptEngine.LANGUAGE_VERSION));
+ Assert.assertNull(factory.getParameter("THREADING"));
+ Assert.assertEquals(NAMES, factory.getParameter(ScriptEngine.NAME));
+ Assert.assertEquals(EXTENSIONS, factory.getExtensions());
+ Assert.assertEquals(MIMES, factory.getMimeTypes());
- assertEquals("42;", factory.getProgram(new String[]{"42"}));
- assertEquals("str.substring(3,4)", factory.getMethodCallSyntax("str", "substring", new String[]{"3", "4"}));
+ Assert.assertEquals("42;", factory.getProgram(new String[]{"42"}));
+ Assert.assertEquals("str.substring(3,4)", factory.getMethodCallSyntax("str", "substring", new String[]{"3", "4"}));
}
+ @Test
public void testScriptingGetBy() throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
- assertNotNull("Manager should not be null", manager);
+ Assert.assertNotNull("Manager should not be null", manager);
for (String name : NAMES) {
ScriptEngine engine = manager.getEngineByName(name);
- assertNotNull("Engine should not be null (name)", engine);
+ Assert.assertNotNull("Engine should not be null (name)", engine);
}
for (String extension : EXTENSIONS) {
ScriptEngine engine = manager.getEngineByExtension(extension);
- assertNotNull("Engine should not be null (extension)", engine);
+ Assert.assertNotNull("Engine should not be null (extension)", engine);
}
for (String mime : MIMES) {
ScriptEngine engine = manager.getEngineByMimeType(mime);
- assertNotNull("Engine should not be null (mime)", engine);
+ Assert.assertNotNull("Engine should not be null (mime)", engine);
}
}
+ @Test
public void testScripting() throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
- assertNotNull("Manager should not be null", manager);
+ Assert.assertNotNull("Manager should not be null", manager);
ScriptEngine engine = manager.getEngineByName("jexl3");
final Integer initialValue = Integer.valueOf(123);
- assertEquals(initialValue,engine.eval("123"));
- assertEquals(initialValue,engine.eval("0;123"));// multiple statements
+ Assert.assertEquals(initialValue,engine.eval("123"));
+ Assert.assertEquals(initialValue,engine.eval("0;123"));// multiple statements
long time1 = System.currentTimeMillis();
Long time2 = (Long) engine.eval(
"sys=context.class.forName(\"java.lang.System\");"
+"now=sys.currentTimeMillis();"
);
- assertTrue("Must take some time to process this",time1 <= time2.longValue());
+ Assert.assertTrue("Must take some time to process this",time1 <= time2.longValue());
engine.put("value", initialValue);
- assertEquals(initialValue,engine.get("value"));
+ Assert.assertEquals(initialValue,engine.get("value"));
final Integer newValue = Integer.valueOf(124);
- assertEquals(newValue,engine.eval("old=value;value=value+1"));
- assertEquals(initialValue,engine.get("old"));
- assertEquals(newValue,engine.get("value"));
- assertEquals(engine.getContext(),engine.get(JexlScriptEngine.CONTEXT_KEY));
+ Assert.assertEquals(newValue,engine.eval("old=value;value=value+1"));
+ Assert.assertEquals(initialValue,engine.get("old"));
+ Assert.assertEquals(newValue,engine.get("value"));
+ Assert.assertEquals(engine.getContext(),engine.get(JexlScriptEngine.CONTEXT_KEY));
// Check behaviour of JEXL object
- assertEquals(engine.getContext().getReader(),engine.eval("JEXL.in"));
- assertEquals(engine.getContext().getWriter(),engine.eval("JEXL.out"));
- assertEquals(engine.getContext().getErrorWriter(),engine.eval("JEXL.err"));
- assertEquals(System.class,engine.eval("JEXL.System"));
+ Assert.assertEquals(engine.getContext().getReader(),engine.eval("JEXL.in"));
+ Assert.assertEquals(engine.getContext().getWriter(),engine.eval("JEXL.out"));
+ Assert.assertEquals(engine.getContext().getErrorWriter(),engine.eval("JEXL.err"));
+ Assert.assertEquals(System.class,engine.eval("JEXL.System"));
}
+ @Test
public void testNulls() throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
- assertNotNull("Manager should not be null", manager);
+ Assert.assertNotNull("Manager should not be null", manager);
ScriptEngine engine = manager.getEngineByName("jexl3");
- assertNotNull("Engine should not be null (name)", engine);
+ Assert.assertNotNull("Engine should not be null (name)", engine);
try {
engine.eval((String)null);
- fail("Should have caused NPE");
+ Assert.fail("Should have caused NPE");
} catch (NullPointerException e) {
// NOOP
}
try {
engine.eval((Reader)null);
- fail("Should have caused NPE");
+ Assert.fail("Should have caused NPE");
} catch (NullPointerException e) {
// NOOP
}
}
+ @Test
public void testScopes() throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
- assertNotNull("Manager should not be null", manager);
+ Assert.assertNotNull("Manager should not be null", manager);
ScriptEngine engine = manager.getEngineByName("JEXL");
- assertNotNull("Engine should not be null (JEXL)", engine);
+ Assert.assertNotNull("Engine should not be null (JEXL)", engine);
manager.put("global",Integer.valueOf(1));
engine.put("local", Integer.valueOf(10));
manager.put("both",Integer.valueOf(7));
@@ -127,30 +132,32 @@ public class JexlScriptEngineTest extend
engine.eval("global=global+1");
engine.eval("both=both+1"); // should update engine value only
engine.eval("newvar=42;");
- assertEquals(Integer.valueOf(2),manager.get("global"));
- assertEquals(Integer.valueOf(11),engine.get("local"));
- assertEquals(Integer.valueOf(7),manager.get("both"));
- assertEquals(Integer.valueOf(8),engine.get("both"));
- assertEquals(Integer.valueOf(42),engine.get("newvar"));
- assertNull(manager.get("newvar"));
+ Assert.assertEquals(Integer.valueOf(2),manager.get("global"));
+ Assert.assertEquals(Integer.valueOf(11),engine.get("local"));
+ Assert.assertEquals(Integer.valueOf(7),manager.get("both"));
+ Assert.assertEquals(Integer.valueOf(8),engine.get("both"));
+ Assert.assertEquals(Integer.valueOf(42),engine.get("newvar"));
+ Assert.assertNull(manager.get("newvar"));
}
+ @Test
public void testDottedNames() throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
- assertNotNull("Manager should not be null", manager);
+ Assert.assertNotNull("Manager should not be null", manager);
ScriptEngine engine = manager.getEngineByName("JEXL");
- assertNotNull("Engine should not be null (JEXL)", engine);
+ Assert.assertNotNull("Engine should not be null (JEXL)", engine);
engine.eval("this.is.a.test=null");
- assertNull(engine.get("this.is.a.test"));
- assertEquals(Boolean.TRUE, engine.eval("empty(this.is.a.test)"));
+ Assert.assertNull(engine.get("this.is.a.test"));
+ Assert.assertEquals(Boolean.TRUE, engine.eval("empty(this.is.a.test)"));
final Object mymap = engine.eval("testmap={ 'key1' : 'value1', 'key2' : 'value2' }");
- assertTrue(mymap instanceof Map<?, ?>);
- assertEquals(2,((Map<?, ?>)mymap).size());
+ Assert.assertTrue(mymap instanceof Map<?, ?>);
+ Assert.assertEquals(2,((Map<?, ?>)mymap).size());
}
+ @Test
public void testDirectNew() throws Exception {
ScriptEngine engine = new JexlScriptEngine();
final Integer initialValue = Integer.valueOf(123);
- assertEquals(initialValue,engine.eval("123"));
+ Assert.assertEquals(initialValue,engine.eval("123"));
}
}