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);
}
Aggregations