use of spoon.test.template.testclasses.constructors.TemplateWithFieldsAndMethods_Wrong in project spoon by INRIA.
the class TemplateTest method testTemplateWithWrongUsedStringParam.
@Test
public void testTemplateWithWrongUsedStringParam() throws Exception {
Launcher spoon = new Launcher();
Factory factory = spoon.createFactory();
spoon.createCompiler(factory, SpoonResourceHelper.resources("./src/test/java/spoon/test/template/testclasses/constructors/C1.java"), SpoonResourceHelper.resources("./src/test/java/spoon/test/template/testclasses/constructors/TemplateWithFieldsAndMethods_Wrong.java")).build();
CtClass<?> c1 = factory.Class().get(C1.class);
new TemplateWithFieldsAndMethods_Wrong("testparam").apply(c1);
CtMethod<?> m = c1.getMethod("methodToBeInserted");
assertNotNull(m);
// contract: printing of code which contains invalid field reference, fails with nice exception
try {
m.getBody().getStatement(0).toString();
} catch (SpoonException e) {
assertTrue("The error description doesn't contain name of invalid field. There is:\n" + e.getMessage(), e.getMessage().indexOf("testparam") >= 0);
}
}
Aggregations