コード例 #1
0
  @org.junit.Test
  public void testCreateListAndDelete3SubdirsWithAttributes() throws Exception {

    // PRE:
    Files files = getFiles();
    Path testDirPath = createUniqueTestSubdir(getTestDir(), "testSubdir5");
    assertDirIsEmpty(files, testDirPath);

    // TEST:
    Path dir1 = createSubdir(testDirPath, "subDir1");
    Path dir2 = createSubdir(testDirPath, "subDir2");
    Path dir3 = createSubdir(testDirPath, "subDir3");

    DirectoryStream<PathAttributesPair> dirStream =
        getFiles().newAttributesDirectoryStream(testDirPath);
    Iterator<PathAttributesPair> iterator = dirStream.iterator();

    int count = 0;

    while (iterator.hasNext()) {
      PathAttributesPair el = iterator.next();
      Path path = el.path();
      infoPrintf(" -(Path)Path     =%s:'%s'\n", path.getFileSystem().getScheme(), path);
      infoPrintf(" -(Path)getPath()=%s:'%s'\n", path.getFileSystem().getLocation(), path);
      count++;
    }

    infoPrintf("Directory has:%d entries\n", count);
    assertEquals("Directory must have 3 sub directories\n", 3, count);

    // POST:
    deletePaths(new Path[] {dir1, dir2, dir3, testDirPath}, true);
  }
コード例 #2
0
  @org.junit.Test
  public void testCreateListAndDelete3FilesWithAttributes() throws Exception {

    // PRE:
    Files files = getFiles();
    Path testDirPath = createUniqueTestSubdir(getTestDir(), "testSubdir4");
    assertDirIsEmpty(files, testDirPath);

    // TEST:
    Path file1 = createFile(testDirPath, "file1");
    Path file2 = createFile(testDirPath, "file2");
    Path file3 = createFile(testDirPath, "file3");

    DirectoryStream<PathAttributesPair> dirStream =
        getFiles().newAttributesDirectoryStream(testDirPath);
    Iterator<PathAttributesPair> iterator = dirStream.iterator();

    // Regression test: this has failed before. Issue #91
    int count = 0;

    while (iterator.hasNext()) {
      PathAttributesPair el = iterator.next();
      Path path = el.path();
      infoPrintf(" -(Path)Path     =%s:'%s'\n", path.getFileSystem().getScheme(), path);
      infoPrintf(" -(Path)getPath()=%s:'%s'\n", path.getFileSystem().getLocation(), path);
      count++;
    }

    infoPrintf("Directory has:%d entries\n", count);
    assertEquals("Directory must have 3 file entries\n", 3, count);

    // POST:
    deletePaths(new Path[] {file1, file2, file3, testDirPath}, true);
  }
コード例 #3
0
  public void assertDirIsEmpty(Files files, Path dirPath) throws Exception {

    DirectoryStream<Path> dirStream = files.newDirectoryStream(dirPath);
    Iterator<Path> iterator = dirStream.iterator();
    assertFalse(
        "Method hasNext() from empty directory iterator must return false.", iterator.hasNext());
  }
コード例 #4
0
  @org.junit.Test
  public void testNewDirectoryAttributesStreamTestDir() throws Exception {

    Path path = getTestDir();
    DirectoryStream<PathAttributesPair> dirStream = getFiles().newAttributesDirectoryStream(path);
    Iterator<PathAttributesPair> iterator = dirStream.iterator();

    // Just test whether it works and directory is readable (other tests will fail if this doesn't
    // work).
    while (iterator.hasNext()) {
      PathAttributesPair pathEl = iterator.next();
      infoPrintf(" -(PathAttributesPair)path='%s'\n", pathEl.path());
    }
  }
コード例 #5
0
  @org.junit.Test
  public void testNewDirectoryStreamTestDir() throws Exception {

    Path path = getTestDir();
    DirectoryStream<Path> dirStream = getFiles().newDirectoryStream(path);
    Iterator<Path> iterator = dirStream.iterator();

    // Just test whether it works and directory is readable (other tests will fail if this doesn't
    // work).
    while (iterator.hasNext()) {
      Path pathEl = iterator.next();
      infoPrintf(" -(Path)Path     =%s:'%s'\n", pathEl.getFileSystem().getScheme(), pathEl);
      infoPrintf(" -(Path)getPath()=%s:'%s'\n", pathEl.getFileSystem().getLocation(), pathEl);
    }
  }