Search in sources :

Example 1 with InvocationSubstitutionByStatementTemplate

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());
}
Also used : CtStatement(spoon.reflect.code.CtStatement) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) FileSystemFile(spoon.support.compiler.FileSystemFile) InvocationSubstitutionByStatementTemplate(spoon.test.template.testclasses.InvocationSubstitutionByStatementTemplate) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Launcher (spoon.Launcher)1 CtStatement (spoon.reflect.code.CtStatement)1 Factory (spoon.reflect.factory.Factory)1 FileSystemFile (spoon.support.compiler.FileSystemFile)1 InvocationSubstitutionByStatementTemplate (spoon.test.template.testclasses.InvocationSubstitutionByStatementTemplate)1