protected void assertJavascript(String expectedOutput, String jsonData, String code, String testInfo) throws IOException {
// build the code, something like
// data = <jsonData> ;
// <code>
final String jsCode = "data=" + jsonData + ";\n" + code;
final Context rhinoContext = Context.enter();
final ScriptableObject scope = rhinoContext.initStandardObjects();
// execute the script, out script variable maps to sw
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw, true);
ScriptableObject.putProperty(scope, "out", Context.javaToJS(pw, scope));
final int lineNumber = 1;
final Object securityDomain = null;
rhinoContext.evaluateString(scope, jsCode, getClass().getSimpleName(),
lineNumber, securityDomain);
// check script output
pw.flush();
final String result = sw.toString().trim();