@Test
public void testGenerate_customDirectory_byApp() throws Exception {

	File targetFilePattern = new File( this.folder.newFolder(), "${app}/${app}.paf" );
	// Copy a template
	String templateContent;
	InputStream in = getClass().getResourceAsStream( "/templates/basic-with-custom-output.txt.tpl" );
	try {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		Utils.copyStreamUnsafelyUseWithCaution( in, os );
		templateContent = os.toString( "UTF-8" ).replace( "%DIR%", targetFilePattern.getAbsolutePath());
	} finally {
		Utils.closeQuietly( in );
	}
	File dir = this.folder.newFolder();
	File tplFile = new File( dir, "basic-with-custom-output.txt.tpl" );
	Utils.writeStringInto( templateContent, tplFile );
	// Compile and verify it
	TemplateEntry te = new TemplateWatcher( null, dir, 100 ).compileTemplate( tplFile );
	Assert.assertNotNull( te );
	Assert.assertNull( te.getAppName());
	Assert.assertEquals( tplFile, te.getTemplateFile());
	Assert.assertEquals( targetFilePattern.getAbsolutePath(), te.getTargetFilePath());
	Assert.assertNotNull( te.getTemplate());
	// The file does not exist (yet)
	Application app =  GenerationTest.testApplicationForTemplates();
	File targetFile = new File( targetFilePattern.getParentFile().getParentFile(), app.getName() + "/" + app.getName() + ".paf" );
	Assert.assertFalse( targetFilePattern.exists());
	Assert.assertFalse( targetFile.exists());
	// Apply it to a given application
	Logger logger = Logger.getLogger( getClass().getName());
	File outputDir = this.folder.newFolder();
	Assert.assertEquals( 0, outputDir.listFiles().length );
	TemplateUtils.generate( app, outputDir, Collections.singleton( te ), logger );
	// Nothing was added in the out put directory
	Assert.assertEquals( 0, outputDir.listFiles().length );
	// It was directly written in the target file
	Assert.assertFalse( targetFilePattern.exists());
	Assert.assertTrue( targetFile.exists());
	String currentContent = Utils.readFileContent( targetFile );
	File expectedFile =  TestUtils.findTestFile( "/output/basic-with-custom-output.txt" );
	String expectedContent = Utils.readFileContent( expectedFile );
	Assert.assertEquals( expectedContent, currentContent );
}