コード例 #1
0
  private static void assertFiles(
      String dirPath, Set<String> expectedFiles, boolean excludeNonExistingFiles)
      throws IOException {
    LogTransaction.waitForDeletions();

    File dir = new File(dirPath).getCanonicalFile();
    File[] files = dir.listFiles();
    if (files != null) {
      for (File file : files) {
        if (file.isDirectory()) continue;

        String filePath = file.getPath();
        assertTrue(
            String.format("%s not in [%s]", filePath, expectedFiles),
            expectedFiles.contains(filePath));
        expectedFiles.remove(filePath);
      }
    }

    if (excludeNonExistingFiles) {
      for (String filePath : expectedFiles) {
        File file = new File(filePath);
        if (!file.exists()) expectedFiles.remove(filePath);
      }
    }

    assertTrue(expectedFiles.toString(), expectedFiles.isEmpty());
  }
コード例 #2
0
  // Check either that a temporary file is expected to exist (in the existingFiles) or that
  // it does not exist any longer (on Windows we need to check File.exists() because a list
  // might return a file as existing even if it does not)
  private static void assertFiles(Iterable<String> existingFiles, Set<File> temporaryFiles) {
    for (String filePath : existingFiles) {
      File file = new File(filePath);
      assertTrue(filePath, temporaryFiles.contains(file));
      temporaryFiles.remove(file);
    }

    for (File file : temporaryFiles) {
      if (!file.exists()) temporaryFiles.remove(file);
    }

    assertTrue(temporaryFiles.toString(), temporaryFiles.isEmpty());
  }