@Before
  public void setup() throws IOException, InterruptedException {
    File base = new File(System.getProperty("java.io.tmpdir"));
    backupDir = TestHelper.createBackupFolder(base);

    jenkinsHome = TestHelper.createBasicFolderStructure(base);
    File jobDir = TestHelper.createJob(jenkinsHome, TestHelper.TEST_JOB_NAME);
    TestHelper.addNewBuildToJob(jobDir);

    final FileCollector fc = new FileCollector();
    originalFiles = fc.getFilesAsString(jenkinsHome);
  }
  @Test
  public void testRestoreFromZipFileWithNextBuildNumber() throws Exception {
    // create a backed up structure with DIFF back ups
    final TestHudsonBackup tester = new TestHudsonBackup();
    tester.setup();
    tester.performHudsonDiffBackup(createMockPluginBackupNextBuildNumber());

    // remember the date to restore
    final File[] tmpFiles = backupDir.listFiles();
    Assert.assertEquals(2, tmpFiles.length);
    final Date backupDate = Utils.getDateFromBackupDirectory(tmpFiles[0]);

    // move backups to ZIP file
    Utils.moveOldBackupsToZipFile(backupDir, null);

    // now destroy the hudson directory and recreate the root dir
    FileUtils.deleteDirectory(jenkinsHome);
    jenkinsHome.mkdirs();

    final File[] files = backupDir.listFiles();
    Assert.assertEquals(1, files.length);
    final File zipFile = files[0];
    final BackupSet set = new BackupSet(zipFile);
    Assert.assertTrue(set.isValid());
    Assert.assertTrue(set.isInZipFile());

    final HudsonRestore restore =
        new HudsonRestore(jenkinsHome, backupDir.getAbsolutePath(), backupDate, true, false);
    restore.restore();

    final FileCollector fc = new FileCollector();
    final List<String> restoredFiles = fc.getFilesAsString(jenkinsHome);
    final int nrRestored = restoredFiles.size();
    Assert.assertEquals(
        originalFiles.size(), nrRestored + 2); // + 3 because original has more files that were not
    // backed up on purpose (secret.key, workspace/neverBackupme.txt)
    Assert.assertTrue(
        TestHelper.containsStringEndingWith(
            restoredFiles, HudsonBackup.NEXT_BUILD_NUMBER_FILE_NAME));
    Assert.assertFalse(TestHelper.containsStringEndingWith(restoredFiles, "secret.key"));
  }