Search in sources :

Example 1 with InvocationSubstitutionByExpressionTemplate

use of spoon.test.template.testclasses.InvocationSubstitutionByExpressionTemplate in project spoon by INRIA.

the class TemplateInvocationSubstitutionTest method testInvocationSubstitutionByExpression.

@Test
public void testInvocationSubstitutionByExpression() 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/InvocationSubstitutionByExpressionTemplate.java"));
    spoon.buildModel();
    Factory factory = spoon.getFactory();
    CtClass<?> resultKlass = factory.Class().create("Result");
    CtBlock<?> result = new InvocationSubstitutionByExpressionTemplate(factory.createLiteral("abc")).apply(resultKlass);
    assertEquals("java.lang.System.out.println(\"abc\".substring(1))", result.getStatement(0).toString());
    assertEquals("java.lang.System.out.println(\"abc\".substring(1))", result.getStatement(1).toString());
}
Also used : InvocationSubstitutionByExpressionTemplate(spoon.test.template.testclasses.InvocationSubstitutionByExpressionTemplate) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) FileSystemFile(spoon.support.compiler.FileSystemFile) Test(org.junit.Test)

Aggregations

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