Ejemplo n.º 1
0
 private void visit(Set<String> names, String prefix, File file) {
   for (File child : file.listFiles()) {
     if (child.isFile()) {
       names.add(prefix + child.getName());
     } else if (child.isDirectory()) {
       visit(names, prefix + child.getName() + "/", child);
     }
   }
 }
Ejemplo n.º 2
0
  /** Asserts that this file contains exactly the given set of descendants. */
  public TestFile assertHasDescendants(String... descendants) {
    Set<String> actual = new TreeSet<String>();
    assertIsDir();
    visit(actual, "", this);
    Set<String> expected = new TreeSet<String>(Arrays.asList(descendants));

    Set<String> extras = new TreeSet<String>(actual);
    extras.removeAll(expected);
    Set<String> missing = new TreeSet<String>(expected);
    missing.removeAll(actual);

    assertEquals(
        String.format(
            "For dir: %s, extra files: %s, missing files: %s, expected: %s",
            this, extras, missing, expected),
        expected,
        actual);

    return this;
  }