Skip to content

Commit

Permalink
Rename test method names to be clearer on use of symbolic links
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Nov 13, 2024
1 parent d7975e6 commit 8662f89
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testDeleteDirectoryNullArgument() {
}

@Test
public void testDeleteDirWithASymlinkDir() throws Exception {
public void testDeleteDirWithASymbolicLinkDir2() throws Exception {

final File realOuter = new File(top, "realouter");
assertTrue(realOuter.mkdirs());
Expand All @@ -60,7 +60,7 @@ public void testDeleteDirWithASymlinkDir() throws Exception {
assertEquals(1, randomDirectory.list().length);

final File symlinkDirectory = new File(realOuter, "fakeinner");
assertTrue(setupSymlink(randomDirectory, symlinkDirectory));
Files.createSymbolicLink(symlinkDirectory.toPath(), randomDirectory.toPath());

assertEquals(1, symlinkDirectory.list().length);

Expand All @@ -73,7 +73,7 @@ public void testDeleteDirWithASymlinkDir() throws Exception {
}

@Test
public void testDeleteDirWithASymlinkDir2() throws Exception {
public void testDeleteDirWithASymlinkDir() throws Exception {

final File realOuter = new File(top, "realouter");
assertTrue(realOuter.mkdirs());
Expand All @@ -91,7 +91,7 @@ public void testDeleteDirWithASymlinkDir2() throws Exception {
assertEquals(1, randomDirectory.list().length);

final File symlinkDirectory = new File(realOuter, "fakeinner");
Files.createSymbolicLink(symlinkDirectory.toPath(), randomDirectory.toPath());
assertTrue(setupSymlink(randomDirectory, symlinkDirectory));

assertEquals(1, symlinkDirectory.list().length);

Expand Down Expand Up @@ -135,7 +135,7 @@ public void testDeleteDirWithSymlinkFile() throws Exception {
}

@Test
public void testDeleteInvalidLinks() throws Exception {
public void testDeleteInvalidSymbolicLinks() throws Exception {
final File aFile = new File(top, "realParentDirA");
assertTrue(aFile.mkdir());
final File bFile = new File(aFile, "realChildDirB");
Expand All @@ -158,7 +158,7 @@ public void testDeleteInvalidLinks() throws Exception {
}

@Test
public void testDeleteParentSymlink() throws Exception {
public void testDeleteParentSymbolicLink2() throws Exception {
final File realParent = new File(top, "realparent");
assertTrue(realParent.mkdirs());

Expand All @@ -175,12 +175,12 @@ public void testDeleteParentSymlink() throws Exception {
assertEquals(1, randomDirectory.list().length);

final File symlinkDirectory = new File(realParent, "fakeinner");
assertTrue(setupSymlink(randomDirectory, symlinkDirectory));
Files.createSymbolicLink(symlinkDirectory.toPath(), randomDirectory.toPath());

assertEquals(1, symlinkDirectory.list().length);

final File symlinkParentDirectory = new File(top, "fakeouter");
assertTrue(setupSymlink(realParent, symlinkParentDirectory));
Files.createSymbolicLink(symlinkParentDirectory.toPath(), realParent.toPath());

// assert only the symlink is deleted, but not followed
FileUtils.deleteDirectory(symlinkParentDirectory);
Expand All @@ -191,7 +191,7 @@ public void testDeleteParentSymlink() throws Exception {
}

@Test
public void testDeleteParentSymlink2() throws Exception {
public void testDeleteParentSymlink() throws Exception {
final File realParent = new File(top, "realparent");
assertTrue(realParent.mkdirs());

Expand All @@ -208,12 +208,12 @@ public void testDeleteParentSymlink2() throws Exception {
assertEquals(1, randomDirectory.list().length);

final File symlinkDirectory = new File(realParent, "fakeinner");
Files.createSymbolicLink(symlinkDirectory.toPath(), randomDirectory.toPath());
assertTrue(setupSymlink(randomDirectory, symlinkDirectory));

assertEquals(1, symlinkDirectory.list().length);

final File symlinkParentDirectory = new File(top, "fakeouter");
Files.createSymbolicLink(symlinkParentDirectory.toPath(), realParent.toPath());
assertTrue(setupSymlink(realParent, symlinkParentDirectory));

// assert only the symlink is deleted, but not followed
FileUtils.deleteDirectory(symlinkParentDirectory);
Expand Down
42 changes: 21 additions & 21 deletions src/test/java/org/apache/commons/io/FileUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ private void consumeRemaining(final Iterator<File> iterator) {
}
}

private Path createCircularOsSymLink(final String linkName, final String targetName) throws IOException {
private Path createCircularOsSymbolicLink(final String linkName, final String targetName) throws IOException {
return Files.createSymbolicLink(Paths.get(linkName), Paths.get(targetName));
}

/**
* May throw java.nio.file.FileSystemException: C:\Users\...\FileUtilsTestCase\cycle: A required privilege is not held
* by the client. On Windows, you are fine if you run a terminal with admin karma.
*/
private void createCircularSymLink(final File file) throws IOException {
private void createCircularSymbolicLink(final File file) throws IOException {
assertTrue(file.exists());
final String linkName = file + "/cycle";
final String targetName = file + "/..";
Expand All @@ -218,7 +218,7 @@ private void createCircularSymLink(final File file) throws IOException {
// On Windows, you are fine if you run a terminal with admin karma.
Files.createSymbolicLink(linkPath, targetPath);
} catch (final UnsupportedOperationException e) {
createCircularOsSymLink(linkName, targetName);
createCircularOsSymbolicLink(linkName, targetName);
}
// Sanity check:
assertTrue(Files.isSymbolicLink(linkPath), () -> "Expected a sym link here: " + linkName);
Expand All @@ -245,7 +245,7 @@ private void createFilesForTestCopyDirectory(final File grandParentDir, final Fi
FileUtils.writeStringToFile(file6, "File 6 in grandChild2", "UTF8");
}

private Path createTempSymlinkedRelativeDir() throws IOException {
private Path createTempSymbolicLinkedRelativeDir() throws IOException {
final Path targetDir = tempDirPath.resolve("subdir");
final Path symlinkDir = tempDirPath.resolve("symlinked-dir");
Files.createDirectory(targetDir);
Expand Down Expand Up @@ -404,7 +404,7 @@ public void test_openOutputStream_existsButIsDirectory() {
*/
@Test
public void test_openOutputStream_intoExistingSymlinkedDir() throws Exception {
final Path symlinkedDir = createTempSymlinkedRelativeDir();
final Path symlinkedDir = createTempSymbolicLinkedRelativeDir();

final File file = symlinkedDir.resolve("test.txt").toFile();
try (FileOutputStream out = FileUtils.openOutputStream(file)) {
Expand Down Expand Up @@ -762,7 +762,7 @@ public void testContentEqualsIgnoreEOL() throws Exception {
* and should not be relied on.
*/
@Test
public void testCopyDir_symLink() throws Exception {
public void testCopyDir_SymbolicLink() throws Exception {
// Make a directory
final File realDirectory = new File(tempDirFile, "real_directory");
realDirectory.mkdir();
Expand Down Expand Up @@ -790,7 +790,7 @@ public void testCopyDir_symLink() throws Exception {
}

@Test
public void testCopyDir_symLinkCycle() throws Exception {
public void testCopyDir_SymbolicLinkCycle() throws Exception {
// Make a directory
final File topDirectory = new File(tempDirFile, "topDirectory");
topDirectory.mkdir();
Expand Down Expand Up @@ -824,7 +824,7 @@ public void testCopyDir_symLinkCycle() throws Exception {
* Tests IO-807.
*/
@Test
public void testCopyDirectory_brokenSymLink() throws IOException {
public void testCopyDirectory_brokenSymbolicLink() throws IOException {
// Make a file
final File sourceDirectory = new File(tempDirFile, "source_directory");
sourceDirectory.mkdir();
Expand Down Expand Up @@ -859,7 +859,7 @@ public void testCopyDirectory_brokenSymLink() throws IOException {
}

@Test
public void testCopyDirectory_symLink() throws IOException {
public void testCopyDirectory_SymbolicLink() throws IOException {
// Make a file
final File sourceDirectory = new File(tempDirFile, "source_directory");
sourceDirectory.mkdir();
Expand Down Expand Up @@ -890,7 +890,7 @@ public void testCopyDirectory_symLink() throws IOException {
* to a file outside the copied directory.
*/
@Test
public void testCopyDirectory_symLinkExternalFile() throws Exception {
public void testCopyDirectory_SymbolicLinkExternalFile() throws Exception {
// make a file
final File content = new File(tempDirFile, "hello.txt");
FileUtils.writeStringToFile(content, "HELLO WORLD", "UTF8");
Expand Down Expand Up @@ -1195,7 +1195,7 @@ public void testCopyDirectoryWithPotentialFalsePartialMatch() throws IOException
}

@Test
public void testCopyFile_symLink() throws Exception {
public void testCopyFile_SymbolicLink() throws Exception {
// Make a file
final File sourceDirectory = new File(tempDirFile, "source_directory");
sourceDirectory.mkdir();
Expand Down Expand Up @@ -1553,19 +1553,19 @@ public void testDeleteDirectoryFailsOnFile() {
assertThrows(IllegalArgumentException.class, () -> FileUtils.deleteDirectory(testFile1));
}

@Test
public void testDeleteDirectoryNoopIfAbsent() {
// Noop on non-existent entry
assertDoesNotThrow(() -> FileUtils.deleteDirectory(new File("does not exist.nope")));
}

@Test
public void testDeleteDirectoryIsSymLink() throws IOException {
final Path symlinkedDir = createTempSymlinkedRelativeDir();
final Path symlinkedDir = createTempSymbolicLinkedRelativeDir();
FileUtils.deleteDirectory(symlinkedDir.toFile());
assertFalse(Files.exists(symlinkedDir));
}

@Test
public void testDeleteDirectoryNoopIfAbsent() {
// Noop on non-existent entry
assertDoesNotThrow(() -> FileUtils.deleteDirectory(new File("does not exist.nope")));
}

@Test
public void testDeleteQuietlyDir() throws IOException {
final File testDirectory = new File(tempDirFile, "testDeleteQuietlyDir");
Expand Down Expand Up @@ -2889,7 +2889,7 @@ public void testSizeOfDirectory() throws Exception {
file.mkdir();

// Create a cyclic symlink
createCircularSymLink(file);
createCircularSymbolicLink(file);

assertEquals(TEST_DIRECTORY_SIZE, FileUtils.sizeOfDirectory(file), "Unexpected directory size");
}
Expand Down Expand Up @@ -2920,7 +2920,7 @@ public void testSizeOfDirectoryAsBigInteger() throws Exception {
file.delete();
file.mkdir();

createCircularSymLink(file);
createCircularSymbolicLink(file);

assertEquals(TEST_DIRECTORY_SIZE_BI, FileUtils.sizeOfDirectoryAsBigInteger(file), "Unexpected directory size");

Expand Down Expand Up @@ -3453,7 +3453,7 @@ public void testWriteStringToFileIntoNonExistentSubdir() throws Exception {
*/
@Test
public void testWriteStringToFileIntoSymlinkedDir() throws Exception {
final Path symlinkDir = createTempSymlinkedRelativeDir();
final Path symlinkDir = createTempSymbolicLinkedRelativeDir();

final File file = symlinkDir.resolve("file").toFile();
FileUtils.writeStringToFile(file, "Hello /u1234", StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class AbstractTempDirTest {
* @return Path for {@code tempDirPath/subdir}.
* @throws IOException if an I/O error occurs or the parent directory does not exist.
*/
protected static Path createTempSymlinkedRelativeDir(final Path rootDir) throws IOException {
protected static Path createTempSymbolicLinkedRelativeDir(final Path rootDir) throws IOException {
final Path targetDir = rootDir.resolve(SUB_DIR);
final Path symlinkDir = rootDir.resolve(SYMLINKED_DIR);
Files.createDirectory(targetDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void testEqualsHashCode() {
@Test
public void testIO850DirectoriesAndFiles() throws IOException {
final Path rootDir = Files.createDirectory(managedTempDirPath.resolve("IO850"));
createTempSymlinkedRelativeDir(rootDir);
createTempSymbolicLinkedRelativeDir(rootDir);
final Path targetDir = rootDir.resolve(SUB_DIR);
final Path symlinkDir = rootDir.resolve(SYMLINKED_DIR);
Files.write(targetDir.resolve("file0.txt"), "Hello".getBytes(StandardCharsets.UTF_8));
Expand All @@ -166,7 +166,7 @@ public void testIO850DirectoriesAndFiles() throws IOException {
@Test
public void testIO850DirectoriesOnly() throws IOException {
final Path rootDir = Files.createDirectory(managedTempDirPath.resolve("IO850"));
createTempSymlinkedRelativeDir(rootDir);
createTempSymbolicLinkedRelativeDir(rootDir);
final Path targetDir = rootDir.resolve(SUB_DIR);
final Path symlinkDir = rootDir.resolve(SYMLINKED_DIR);
final DeletingPathVisitor visitor = DeletingPathVisitor.withLongCounters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public class PathUtilsDeleteFileTest extends AbstractTempDirTest {

@Test
public void testDeleteBrokenLink() throws IOException {
public void testDeleteBrokenSymbolicLink() throws IOException {
assumeFalse(SystemUtils.IS_OS_WINDOWS);
final Path missingFile = tempDirPath.resolve("missing.txt");
final Path brokenLink = tempDirPath.resolve("broken.txt");
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/apache/commons/io/file/PathUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ public void testCreateDirectoriesNew() throws IOException {

@Test
public void testCreateDirectoriesSymlink() throws IOException {
final Path symlinkedDir = createTempSymlinkedRelativeDir(tempDirPath);
final Path symlinkedDir = createTempSymbolicLinkedRelativeDir(tempDirPath);
final String leafDirName = "child";
final Path newDirFollowed = PathUtils.createParentDirectories(symlinkedDir.resolve(leafDirName), PathUtils.NULL_LINK_OPTION);
assertEquals(Files.readSymbolicLink(symlinkedDir), newDirFollowed);
}

@Test
public void testCreateDirectoriesSymlinkClashing() throws IOException {
final Path symlinkedDir = createTempSymlinkedRelativeDir(tempDirPath);
final Path symlinkedDir = createTempSymbolicLinkedRelativeDir(tempDirPath);
assertEquals(symlinkedDir, PathUtils.createParentDirectories(symlinkedDir.resolve("child")));
}

Expand Down Expand Up @@ -436,7 +436,7 @@ public void testNewOutputStreamNewFileAppendTrue() throws IOException {

@Test
public void testNewOutputStreamNewFileInsideExistingSymlinkedDir() throws IOException {
final Path symlinkDir = createTempSymlinkedRelativeDir(tempDirPath);
final Path symlinkDir = createTempSymbolicLinkedRelativeDir(tempDirPath);
final Path file = symlinkDir.resolve("test.txt");
try (OutputStream outputStream = PathUtils.newOutputStream(file, new LinkOption[] {})) {
// empty
Expand Down

0 comments on commit 8662f89

Please sign in to comment.