use of spoon.support.JavaOutputProcessor in project spoon by INRIA.
the class DefaultPrettyPrinterTest method printClassCreatedWithSpoon.
@Test
public void printClassCreatedWithSpoon() throws Exception {
/* test that spoon is able to print a class that it created without setting manually the output (default configuration) */
final String nl = System.getProperty("line.separator");
Launcher launcher = new Launcher();
launcher.getEnvironment().setNoClasspath(true);
launcher.getEnvironment().setSourceOutputDirectory(File.createTempFile("foo", "").getParentFile());
launcher.buildModel();
Factory factory = launcher.getFactory();
CtClass<Object> ctClass = factory.Class().create("foo.Bar");
JavaOutputProcessor jop = launcher.createOutputWriter();
jop.setFactory(factory);
// JavaOutputProcessor is able to create the file even if we do not set the cu manually
jop.createJavaFile(ctClass);
String pathname = System.getProperty("java.io.tmpdir") + "/foo/Bar.java";
File javaFile = new File(pathname);
assertTrue(javaFile.exists());
assertEquals("package foo;" + nl + nl + nl + "class Bar {}" + nl + nl, IOUtils.toString(new FileInputStream(javaFile), "UTF-8"));
}
Aggregations