AssetExportStep implements ExportStep<Page> { @Override public void execute(Zipper zipper, Page page) throws IOException { for (Asset pageAsset : page.getAssets()) { if (!pageAsset.isExternal()) { zipper.addDirectoryToZip( pageAssetRepository.findAssetPath(page.getId(), pageAsset.getName(), pageAsset.getType()), ALL_DIRECTORIES, ALL_FILES, String.format("%s/assets/%s/%s", RESOURCES, pageAsset.getType().getPrefix(), pageAsset.getName()) ); } } } @Inject  AssetExportStep(AssetRepository<Page> pageAssetRepository); @Override void execute(Zipper zipper, Page page);  }
@Test public void should_call_zipper_when_page_has_no_asset() throws Exception { assetExportStep.execute(zipper, aPage().build()); Mockito.verifyZeroInteractions(zipper); }
@Test public void should_export_asset_when_page_has_asset() throws Exception { when(pageAssetRepository.findAssetPath("pageId", "myfile.css", AssetType.CSS)).thenReturn(assetPath); Page page = aPage().withId("pageId").withAsset( anAsset().withName("myfile.css").withType(AssetType.CSS)).build(); assetExportStep.execute(zipper, page); verify(zipper).addDirectoryToZip(assetPath, ALL_DIRECTORIES, ALL_FILES, "resources/assets/css/myfile.css"); }
@Test public void should_not_export_external_assets() throws Exception { Page page = aPage().withAsset( anAsset().withName("http: assetExportStep.execute(zipper, page); verifyZeroInteractions(zipper); }