ZipInstallation implements Installation { @Override public void addContent(DataInVersion dataInVersion) { File downloadDirectory = null; try { downloadDirectory = createTemporaryFolder("download"); dataInVersion.storeIn(downloadDirectory); installNonArchivesFrom(downloadDirectory); installArchiveContentsFrom(downloadDirectory); FileUtils.deleteDirectory(downloadDirectory); } catch (Exception e) { report.installationFailed(e); FileUtils.deleteQuietly(downloadDirectory); } } ZipInstallation(Installation wrapped, ProgressReport report); @Override void addContent(DataInVersion dataInVersion); @Override void finish(); @Override void abort(); @Override boolean isRunning();  }
@Test public void unzipsArchivesAndForwardsEntriesToWrapped() throws Exception { installFromZip(); verify(wrapped).addContent(Matchers.isA(DataInVersion.class)); }
@Test public void reportsErrorsToReport() throws Exception { RuntimeException exception = new RuntimeException(); Mockito.doThrow(exception).when(dataInVersion).storeIn(isA(File.class)); installation.addContent(dataInVersion); verify(report).installationFailed(exception); }
@Test public void deletesTemporaryFilesEvenWhenAnErrorOccurs() throws Exception { RuntimeException exception = new RuntimeException(); Mockito.doThrow(exception).when(dataInVersion).storeIn(isA(File.class)); installation.addContent(dataInVersion); assertThatNoTemporariesRemain(); }