PatchFileCreator { public static PreparationResult prepareAndValidate(File patchFile, File toDir, UpdaterUI ui) throws IOException, OperationCancelledException { Patch patch; ZipFile zipFile = new ZipFile(patchFile); try { InputStream in = Utils.getEntryInputStream(zipFile, PATCH_INFO_FILE_NAME); try { patch = new Patch(in); } finally { in.close(); } } finally { zipFile.close(); } ui.setDescription(patch.getOldBuild(), patch.getNewBuild()); List<ValidationResult> validationResults = patch.validate(toDir, ui); return new PreparationResult(patch, patchFile, toDir, validationResults); }  static Patch create(PatchSpec spec, File patchFile, UpdaterUI ui); static PreparationResult prepareAndValidate(File patchFile,
                                                     File toDir,
                                                     UpdaterUI ui); static boolean apply(PreparationResult preparationResult,
                              Map<String, ValidationResult.Option> options,
                              UpdaterUI ui); static Patch.ApplicationResult apply(PreparationResult preparationResult,
                                              Map<String, ValidationResult.Option> options,
                                              File backupDir,
                                              UpdaterUI ui); static void revert(PreparationResult preparationResult,
                            List<PatchAction> actionsToRevert,
                            File backupDir,
                            UpdaterUI ui);  }
@Test public void testCreatingAndApplying() throws Exception { Patch patch = createPatch(); assertAppliedAndRevertedCorrectly(patch, PatchFileCreator.prepareAndValidate(myFile, myOlderDir, TEST_UI)); }
@Test public void testCreatingAndApplyingStrict() throws Exception { myPatchSpec.setStrict(true); Patch patch = createPatch(); assertAppliedAndRevertedCorrectly(patch, PatchFileCreator.prepareAndValidate(myFile, myOlderDir, TEST_UI)); }
@Test public void testCreatingAndApplyingOnADifferentRoot() throws Exception { myPatchSpec.setRoot("bin/"); myPatchSpec.setStrict(true); Patch patch = createPatch(); File target = new File(myOlderDir, "bin"); assertAppliedAndRevertedCorrectly(patch, PatchFileCreator.prepareAndValidate(myFile, target, TEST_UI)); }
@Test public void testCreatingAndFailingOnADifferentRoot() throws Exception { myPatchSpec.setRoot("bin/"); myPatchSpec.setStrict(true); Patch patch = createPatch(); File target = new File(myOlderDir, "bin"); PatchFileCreator.PreparationResult preparationResult = PatchFileCreator.prepareAndValidate(myFile, target, TEST_UI); preparationResult.patch.getActions().add(new MyFailOnApplyPatchAction(patch)); assertNothingHasChanged(patch, preparationResult, new HashMap<String, ValidationResult.Option>()); }
@Test public void testReverting() throws Exception { Patch patch = createPatch(); PatchFileCreator.PreparationResult preparationResult = PatchFileCreator.prepareAndValidate(myFile, myOlderDir, TEST_UI); preparationResult.patch.getActions().add(new MyFailOnApplyPatchAction(patch)); assertNothingHasChanged(patch, preparationResult, new HashMap<String, ValidationResult.Option>()); }
@Test public void testConsideringOptions() throws Exception { Patch patch = createPatch(); PatchFileCreator.PreparationResult preparationResult = PatchFileCreator.prepareAndValidate(myFile, myOlderDir, TEST_UI); Map<String, ValidationResult.Option> options = new HashMap<String, ValidationResult.Option>(); for (PatchAction each : preparationResult.patch.getActions()) { options.put(each.getPath(), ValidationResult.Option.IGNORE); } assertNothingHasChanged(patch, preparationResult, options); }