use of spoon.test.template.testclasses.InvocationSubstitutionByStatementTemplate in project spoon by INRIA.
the class TemplateInvocationSubstitutionTest method testInvocationSubstitutionByStatement.
@Test
public void testInvocationSubstitutionByStatement() throws Exception {
// contract: the template engine supports substitution of any method invocation
Launcher spoon = new Launcher();
spoon.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/InvocationSubstitutionByStatementTemplate.java"));
spoon.buildModel();
Factory factory = spoon.getFactory();
CtBlock<?> templateArg = factory.Class().get(InvocationSubstitutionByStatementTemplate.class).getMethod("sample").getBody();
CtClass<?> resultKlass = factory.Class().create("Result");
CtStatement result = new InvocationSubstitutionByStatementTemplate(templateArg).apply(resultKlass);
assertEquals("throw new java.lang.RuntimeException(\"Failed\")", result.toString());
}
Aggregations