Search in sources :

Example 1 with LoggerTemplateProcessor

use of spoon.test.template.testclasses.logger.LoggerTemplateProcessor in project spoon by INRIA.

the class TemplateTest method testExtensionBlock.

@Test
public void testExtensionBlock() throws Exception {
    final Launcher launcher = new Launcher();
    launcher.setArgs(new String[] { "--output-type", "nooutput" });
    launcher.addInputResource("./src/test/java/spoon/test/template/testclasses/logger/Logger.java");
    launcher.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/logger/LoggerTemplate.java"));
    launcher.addProcessor(new LoggerTemplateProcessor());
    launcher.getEnvironment().setSourceClasspath(System.getProperty("java.class.path").split(File.pathSeparator));
    try {
        launcher.run();
    } catch (ClassCastException ignored) {
        fail();
    }
    final CtClass<Logger> aLogger = launcher.getFactory().Class().get(Logger.class);
    final CtMethod aMethod = aLogger.getMethodsByName("enter").get(0);
    assertTrue(aMethod.getBody().getStatement(0) instanceof CtTry);
    final CtTry aTry = (CtTry) aMethod.getBody().getStatement(0);
    assertTrue(aTry.getFinalizer().getStatement(0) instanceof CtInvocation);
    assertEquals("spoon.test.template.testclasses.logger.Logger.exit(\"enter\")", aTry.getFinalizer().getStatement(0).toString());
    assertTrue(aTry.getBody().getStatement(0) instanceof CtInvocation);
    assertEquals("spoon.test.template.testclasses.logger.Logger.enter(\"Logger\", \"enter\")", aTry.getBody().getStatement(0).toString());
    assertTrue(aTry.getBody().getStatements().size() > 1);
}
Also used : CtInvocation(spoon.reflect.code.CtInvocation) LoggerTemplateProcessor(spoon.test.template.testclasses.logger.LoggerTemplateProcessor) Launcher(spoon.Launcher) FileSystemFile(spoon.support.compiler.FileSystemFile) Logger(spoon.test.template.testclasses.logger.Logger) CtTry(spoon.reflect.code.CtTry) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Launcher (spoon.Launcher)1 CtInvocation (spoon.reflect.code.CtInvocation)1 CtTry (spoon.reflect.code.CtTry)1 CtMethod (spoon.reflect.declaration.CtMethod)1 FileSystemFile (spoon.support.compiler.FileSystemFile)1 Logger (spoon.test.template.testclasses.logger.Logger)1 LoggerTemplateProcessor (spoon.test.template.testclasses.logger.LoggerTemplateProcessor)1