TemplateUtils { public static Collection<TemplateEntry> findTemplatesForApplication( String appName, Collection<TemplateEntry> templates ) { final Collection<TemplateEntry> result = new ArrayList<> (); for( TemplateEntry te : templates ) { if( te.getAppName() == null || te.getAppName().equals( appName )) result.add( te ); } return result; } private  TemplateUtils(); static String findApplicationName( final File templateDir, final File templateFile ); static void generate( Application app, File outputDirectory, Collection<TemplateEntry> templates, Logger logger ); static void deleteGeneratedFiles( Application app, File outputDirectory ); static Collection<TemplateEntry> findTemplatesForApplication( String appName, Collection<TemplateEntry> templates );  }
@Test public void testFindTemplatesForApplication() { List<TemplateEntry> templates = new ArrayList<> (); templates.add( new TemplateEntry( new File( "whatever1.tpl" ), null, null, null )); templates.add( new TemplateEntry( new File( "whatever2.tpl" ), null, null, null )); templates.add( new TemplateEntry( new File( "whatever3.tpl" ), null, null, "app1" )); templates.add( new TemplateEntry( new File( "whatever4.tpl" ), null, null, "app1" )); templates.add( new TemplateEntry( new File( "whatever5.tpl" ), null, null, "app2" )); Collection<TemplateEntry> filteredTemplates = TemplateUtils.findTemplatesForApplication( null, templates ); Assert.assertEquals( 2, filteredTemplates.size()); Assert.assertTrue( filteredTemplates.contains( templates.get( 0 ))); Assert.assertTrue( filteredTemplates.contains( templates.get( 1 ))); filteredTemplates = TemplateUtils.findTemplatesForApplication( "app2", templates ); Assert.assertEquals( 3, filteredTemplates.size()); Assert.assertTrue( filteredTemplates.contains( templates.get( 0 ))); Assert.assertTrue( filteredTemplates.contains( templates.get( 1 ))); Assert.assertTrue( filteredTemplates.contains( templates.get( 4 ))); filteredTemplates = TemplateUtils.findTemplatesForApplication( "app1", templates ); Assert.assertEquals( 4, filteredTemplates.size()); Assert.assertTrue( filteredTemplates.contains( templates.get( 0 ))); Assert.assertTrue( filteredTemplates.contains( templates.get( 1 ))); Assert.assertTrue( filteredTemplates.contains( templates.get( 2 ))); Assert.assertTrue( filteredTemplates.contains( templates.get( 3 ))); filteredTemplates = TemplateUtils.findTemplatesForApplication( "app3", templates ); Assert.assertEquals( 2, filteredTemplates.size()); Assert.assertTrue( filteredTemplates.contains( templates.get( 0 ))); Assert.assertTrue( filteredTemplates.contains( templates.get( 1 ))); }