提交 0e4f9852 编写于 作者: Q qiao tian

单元测试优化

上级 babe0f18
......@@ -9,12 +9,34 @@ import java.lang.reflect.Method;
public class RecursivelyRunnerTest {
static final String TEST_EXPRESS = "eval('10+10')+eval('20')+eval('30-10')";
static final ExpressRunner globalRunner = new ExpressRunner();
static{
globalRunner.addFunction("eval",new GlobalEvalOperator());
}
@Test
public void testErrorRecursivelyInvoke() throws Exception{
try {
Object r = globalRunner.execute(TEST_EXPRESS, null, null, true, false);
System.out.println(r);
}catch (Exception e){
// e.printStackTrace();
System.out.println("符合预期,嵌套调用同一个ExpressRunner不支持!");
}
}
@Test
public void testEvalOperator() throws Exception{
ExpressRunner runner = new ExpressRunner();
runner.addFunction("eval",new EvalOperator());
String express = "eval('10')+eval('20')+eval('30')";
Object r = runner.execute(express, null, null, true, false);
Object r = runner.execute(TEST_EXPRESS, null, null, true, false);
System.out.println(r);
}
......@@ -31,12 +53,22 @@ public class RecursivelyRunnerTest {
runner.addFunctionOfServiceMethod(name, subRunner, name, m.getParameterTypes(), null);
}
String express = "eval('10')+eval('20')+eval('30')";
Object r = runner.execute(express, null, null, true, false);
Object r = runner.execute(TEST_EXPRESS, null, null, true, false);
System.out.println(r);
}
public static class GlobalEvalOperator extends Operator{
@Override
public Object executeInner(Object[] list) throws Exception {
Object result = globalRunner.execute((String) list[0], new DefaultContext(), null, true, false);
return result;
}
}
public static class EvalOperator extends Operator{
private ExpressRunner subRun = new ExpressRunner();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册