插件开发工具库,推荐依赖该工具库。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

46 lines
1.3 KiB

package com.fanruan.api.util;
import com.fanruan.api.Prepare;
import com.fr.script.Calculator;
import com.fr.state.SateVariableManager;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-27
*/
public class RenderKitTest extends Prepare {
@Test
public void renderParameter4Tpl() throws Exception {
Map<String, Object> map = new HashMap<>();
map.put("age", 20);
map.put("name", "Alex");
map.put("salary", 100);
String text = "${name} is ${age} years old, he earned ${salary} dollars per month.";
Assert.assertEquals("Alex is 20 years old, he earned 100 dollars per month.", RenderKit.renderParameter4Tpl(text, map));
}
@Test
public void render() throws Exception{
Calculator c = Calculator.createCalculator();
Map<String, Object> map = new HashMap<>();
map.put("p1",1);
map.put("p2",2);
String s = "abc${p1}xyz${p2}";
Assert.assertEquals("abcxyz", RenderKit.render(s,c));
}
@Test
public void render2() throws Exception {
SateVariableManager.put("fineServletURL", "balala");
String t = RenderKit.render("${fineServletURL}");
Assert.assertEquals("balala", t);
}
}