@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); }
@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); }
@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); } }
@org.junit.Test public void testGetTestDir() throws Exception { Path path = getTestDir(); assertNotNull("TestPath returned NULL", path); assertNotNull("Actual path element of Path may not be NULL", path); infoPrintf("Test location path scheme =%s\n", path.getFileSystem().getScheme()); infoPrintf("Test location path location =%s\n", path.getFileSystem().getLocation()); infoPrintf("Test location path =%s\n", path.getRelativePath().getAbsolutePath()); infoPrintf("Test location toString() =%s\n", path.toString()); infoPrintf("Test location getFileName() =%s\n", path.getRelativePath().getFileName()); assertTrue( "Root test location must exists (won't create here):" + path, getFiles().exists(path)); }