public void testPlaceHolders() {
boolean[] autoRemovable = new boolean[]{false, true};
for (int i = 0; i < autoRemovable.length; i++) {
boolean autoMode = autoRemovable[i];
JavaSource js = getPlaceHolderSource(autoMode);
if (autoMode) {
assertStringEquals("package com.foo;\n" +
"\n" +
"public class Bar {\n" +
" public static void main(java.lang.String[] pArgs) throws java.lang.Exception {\n" +
" for (int i = 1; i < 10; i++) {\n" +
" }\n" +
" }\n" +
"\n" +
"}\n", js.asString());
} else {
boolean gotException = false;
try {
js.asString();
} catch (IllegalStateException e) {
gotException = true;
}
assertTrue(gotException);
}
js = getPlaceHolderSource(autoMode);
JavaMethod main = js.getMethod("main", new JavaQName[]{JavaQNameImpl.getInstance(String[].class)});
PlaceHolder test = main.getPlaceHolder("test");
assertNotNull(test);
test.remove();
main.addLine("// I am here");
String expect = "package com.foo;\n" +
"\n" +
"public class Bar {\n" +
" public static void main(java.lang.String[] pArgs) throws java.lang.Exception {\n" +
" for (int i = 1; i < 10; i++) {\n" +
" // I am here\n" +
" }\n" +
" }\n" +
"\n" +
"}\n";
String got = js.asString();
assertStringEquals(expect, got);
}
}