IconUtils { public static String findIconUrl( AbstractApplication app ) { StringBuilder sb = new StringBuilder(); File iconFile = findIcon( app ); if( iconFile != null ) { sb.append( "/" ); sb.append( app.getName()); if( app instanceof ApplicationTemplate ) { sb.append( "/" ); sb.append(((ApplicationTemplate) app).getVersion()); } sb.append( "/" ); sb.append( iconFile.getName()); } return sb.toString(); } private  IconUtils(); static String encodeIconUrl( String name, String version, File iconFile ); static Map.Entry<String,String> decodeIconUrl( String path ); static File findIcon( AbstractApplication app ); static String findIconUrl( AbstractApplication app ); static String findMimeType( File imgFile ); static File findIcon( File rootDirectory ); static final String MIME_JPG; static final String MIME_PNG; static final String MIME_SVG; static final String MIME_GIF; static final String MIME_BINARY; }
@Test public void testFindIconUrl() throws Exception { ApplicationTemplate tpl = new ApplicationTemplate( "tpl" ).version( "v1" ).directory( this.folder.newFolder()); File descDir = new File( tpl.getDirectory(), Constants.PROJECT_DIR_DESC ); Assert.assertTrue( descDir.mkdirs()); Assert.assertTrue( new File( descDir, "tp.jpg" ).createNewFile()); Application app = new Application( "app", tpl ).directory( this.folder.newFolder()); descDir = new File( app.getDirectory(), Constants.PROJECT_DIR_DESC ); Assert.assertTrue( descDir.mkdirs()); Assert.assertTrue( new File( descDir, "whatever.jpg" ).createNewFile()); Assert.assertEquals( "/tpl/v1/tp.jpg", IconUtils.findIconUrl( tpl )); Assert.assertEquals( "/app/whatever.jpg", IconUtils.findIconUrl( app )); Utils.deleteFilesRecursively( descDir ); Assert.assertEquals( "", IconUtils.findIconUrl( app )); }