PathImporter { public ImportReport importFromPath(Path extractDir, final ArtifactImporter importer) { return importFromPath(extractDir, importer, new Function<Import, ImportReport>() { @Override public ImportReport apply(Import anImport) { return importer.doImport(anImport); } }); } @Inject  PathImporter(ImportStore importStore); ImportReport importFromPath(Path extractDir, final ArtifactImporter importer); ImportReport forceImportFromPath(Path extractDir, final ArtifactImporter importer);  }
@Test public void should_import_zip_file() throws Exception { ImportReport expectedReport = anImportReportFor(aPage()).withStatus(IMPORTED).build(); when(importer.doImport(aMockedImport())).thenReturn(expectedReport); ImportReport report = pathImporter.importFromPath(unzipedPath, importer); assertThat(expectedReport).isEqualTo(report); }
@Test public void should_remove_import_from_store_if_report_status_is_imported() throws Exception { Import anImport = aMockedImport(); when(importer.doImport(anImport)).thenReturn(anImportReportFor(aPage()).withStatus(IMPORTED).build()); pathImporter.importFromPath(unzipedPath, importer); verify(importStore).remove(anImport.getUUID()); }
@Test public void should_remove_import_from_store_if_an_error_occurs_when_importing() throws Exception { Import anImport = aMockedImport(); when(importer.doImport(anImport)).thenThrow(ImportException.class); try { pathImporter.importFromPath(unzipedPath, importer); failBecauseExceptionWasNotThrown(ImportException.class); } catch (Exception e) { verify(importStore).remove(anImport.getUUID()); } }
@Test(expected = ImportException.class) public void should_throw_import_exception_when_an_import_error_occurs() throws Exception { when(importStore.store(importer, unzipedPath)).thenReturn(new Import(importer, "a-uuid", unzipedPath)); doThrow(new ImportException(ImportException.Type.PAGE_NOT_FOUND, "an Error message")).when(importer).doImport(any(Import.class)); pathImporter.importFromPath(unzipedPath, importer); }