step.close();
}
}
private static String createUnitTest(final ScriptableObject table) {
Step step = MiniProfiler.step("API.createUnitTest");
try {
// recordReplay
if (table == null) {
return "";
}
final StringBuilder unitTest = new StringBuilder("@Test \n");
unitTest.append("public void replay").append(table.get("id"))
.append("Round").append(table.get("round"))
.append("() throws GameEngineException {\n");
unitTest.append("API api = new API();\n");
unitTest.append("ScriptableObject table=");
final NativeArray actions = (NativeArray) table.get("actions");
for (final Object a : actions) {
unitTest.append("api.").append(
((ScriptableObject) a).get("method"));
if (((ScriptableObject) a).get("method") != "createTable") {
unitTest.append("(table,");
}
final NativeArray args = (NativeArray) ((ScriptableObject) a)
.get("arguments");
for (final Object argO : args.toArray()) {
// test.append("\"");
StringBuilder arg = toString(argO);
// if string does not start with a quote
if (!arg.toString().startsWith("\"")) {
final String replaceAll = arg.toString().replace("\"",
"\\\"");
arg = new StringBuilder("\"");
arg.append(replaceAll);
arg.append("\"");
}
unitTest.append(arg);
// test.append("\"");
unitTest.append(",");
}
if (args.getIds().length > 0) {
unitTest.replace(unitTest.length() - 1, unitTest.length(),
"");
}
unitTest.append(");\n");
}
unitTest.append("}");
return unitTest.toString();
} finally {
step.close();
}
}