Search in sources :

Example 1 with ClassAccessTemplate

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

the class TemplateClassAccessTest method testClassAccessTest.

@Test
public void testClassAccessTest() throws Exception {
    // contract: the template engine supports class access substitution
    Launcher spoon = new Launcher();
    spoon.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/ClassAccessTemplate.java"));
    spoon.buildModel();
    Factory factory = spoon.getFactory();
    CtClass<?> resultKlass = factory.Class().create("Result");
    CtStatement result = new ClassAccessTemplate(String.class).apply(resultKlass);
    assertEquals("java.lang.String.class.getName()", result.toString());
    // I do not know if it makes sense to use null. But this kind of null handling is probably the best
    CtStatement result2 = new ClassAccessTemplate(null).apply(resultKlass);
    assertEquals("null.getName()", result2.toString());
}
Also used : CtStatement(spoon.reflect.code.CtStatement) ClassAccessTemplate(spoon.test.template.testclasses.ClassAccessTemplate) 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 CtStatement (spoon.reflect.code.CtStatement)1 Factory (spoon.reflect.factory.Factory)1 FileSystemFile (spoon.support.compiler.FileSystemFile)1 ClassAccessTemplate (spoon.test.template.testclasses.ClassAccessTemplate)1