import java.io.File;
import java.util.List;
import java.util.ArrayList;
import javax.script.Invocable;
import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;
import org.apache.commons.io.FileUtils;
public abstract class AbstractJavaScriptTest {
private List<String> scriptFiles = new ArrayList<String>();
private ScriptEngine engine;
public AbstractJavaScriptTest() {
engine = new ScriptEngineManager().getEngineByName("JavaScript");
}
protected void addScript(String name) {
scriptFiles.add(name);
}
protected void initScripts() throws java.io.IOException, javax.script.ScriptException {
for(String scriptFile: scriptFiles) {
engine.eval(FileUtils.readFileToString(new File("src/main/javascript/" + scriptFile)));
}
}
protected <T extends Bird> T getJs(String identifier, Class<T> c) {
Invocable inv = (Invocable) engine;
return (T) inv.getInterface(engine.get(identifier), c);
}
}