use of spoon.test.template.testclasses.SubstituteRootTemplate in project spoon by INRIA.
the class TemplateTest method testStatementTemplateRootSubstitution.
@Test
public void testStatementTemplateRootSubstitution() throws Exception {
// contract: the template engine supports substitution of root element
Launcher spoon = new Launcher();
spoon.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/SubstituteRootTemplate.java"));
spoon.buildModel();
Factory factory = spoon.getFactory();
CtClass<?> templateClass = factory.Class().get(SubstituteRootTemplate.class);
CtBlock<Void> templateParam = (CtBlock) templateClass.getMethod("sampleBlock").getBody();
CtClass<?> resultKlass = factory.Class().create("Result");
CtStatement result = new SubstituteRootTemplate(templateParam).apply(resultKlass);
assertEquals("java.lang.String s = \"Spoon is cool!\"", ((CtBlock) result).getStatement(0).toString());
}
Aggregations