AssetImporter implements DependencyImporter<Asset> { @Override public List<Asset> load(Identifiable component, Path resources) throws IOException { Path assetsPath = component instanceof Widget ? resources.resolve(component.getId()).resolve("assets") : resources.resolve("assets"); if (exists(assetsPath)) { List<Asset> assets = new ArrayList<>(); for (AssetType type : AssetType.values()) { Path path = assetsPath.resolve(type.getPrefix()); if (exists(path)) { assets.addAll(assetRepository.findAssetInPath((T) component, type, path)); } } return assets; } return new ArrayList<>(); } AssetImporter(AssetRepository<T> assetRepository); @Override List<Asset> load(Identifiable component, Path resources); @Override void save(List<Asset> elements, Path resources);  }
@Test public void should_not_thrown_excpetion_when_page_has_no_asset() throws Exception{ List<Asset> assets = pageAssetImporter.load(PageBuilder.aPage().build(), zipBaseDir); assertThat(assets).isEmpty(); }
@Test public void should_load_assets() throws Exception{ Page page = PageBuilder.aPage().build(); createDirectoryAsset("css"); Files.write(zipBaseDir.resolve("assets").resolve("css").resolve("myfile.css"), "<style>.maclass1{}</style>".getBytes()); List<Asset> assetsReturned = new ArrayList<>(); assetsReturned.add(new Asset().setName("myfile.css")); when(pageAssetRepository.findAssetInPath(page, AssetType.CSS, zipBaseDir.resolve("assets").resolve("css"))).thenReturn(assetsReturned); List<Asset> assets = pageAssetImporter.load(page, zipBaseDir); assertThat(assets).isNotEmpty(); }