ImportClassPath.java 1.9 KB
Newer Older
T
tianqiao 已提交
1 2 3 4 5
package com.ql.util.express.bugfix;

import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import com.ql.util.express.IExpressContext;
6
import org.junit.Assert;
T
tianqiao 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
import org.junit.Test;

/**
 * Created by tianqiao on 17/6/23.
 */
public class ImportClassPath {
    
    @Test
    public void test() {
    
        ExpressRunner runner = new ExpressRunner();
        String exp ="return new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\").format(new Date())";
        IExpressContext<String, Object> context = new DefaultContext<String, Object>();
        Object result = null;
        try {
            result = runner.execute(exp,context,null,false,false);
            System.out.println(result);
        } catch (Exception e) {
25 26 27 28 29
            System.out.println("SimpleDateFormat 没有定义,此处应该报错");
            //e.printStackTrace();
            Assert.assertTrue(true);
            return;
            
T
tianqiao 已提交
30
        }
31
        Assert.assertTrue(false);
T
tianqiao 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    }
    
    @Test
    public void test2() throws Exception {
        
        ExpressRunner runner = new ExpressRunner();
        String exp ="return new java.text.SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\").format(new Date())";
        IExpressContext<String, Object> context = new DefaultContext<String, Object>();
        Object result = null;
        result = runner.execute(exp,context,null,false,false);
        System.out.println(result);
    }
    
    @Test
    public void test3() throws Exception {
        
        ExpressRunner runner = new ExpressRunner();
        String exp ="import java.text.SimpleDateFormat; return new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\").format(new Date())";
        IExpressContext<String, Object> context = new DefaultContext<String, Object>();
        Object result = null;
        result = runner.execute(exp,context,null,false,false);
        System.out.println(result);
    }
}