Skip to content

Commit

Permalink
[MSHARED-1112] Test case for NoSuchFileException while copying symbolic
Browse files Browse the repository at this point in the history
link with relative non-existing target
  • Loading branch information
kwin committed Jul 26, 2022
1 parent 873ebb0 commit 94fa38a
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import java.io.Writer;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -445,15 +447,14 @@ public void copyFileWithNoFiltersAndLastModifiedDateOfZeroAndNoDestination()
{
File from = write(
"from.txt",
MODIFIED_YESTERDAY,
0,
"Hello World!"
);
File to = new File(
tempFolder.getRoot(),
"to.txt"
);

from.setLastModified( 0 );
FileUtils.copyFile( from, to, null, (FileUtils.FilterWrapper[]) null );

assertTrue(
Expand All @@ -463,6 +464,32 @@ public void copyFileWithNoFiltersAndLastModifiedDateOfZeroAndNoDestination()
assertFileContent( to, "Hello World!" );
}

@Test
public void copyRelativeSymbolicLinkFileWithNonExistingTargetWithNoFiltersAndNoDestination()
throws Exception
{

File target = write(
"target.txt",
MODIFIED_YESTERDAY,
"Hello World!"
);
// must be a relative symbolic link
Path from = Files.createSymbolicLink( new File(tempFolder.getRoot(), "symLink").toPath(), Paths.get( "target.txt" ) );
File to = new File(
tempFolder.newFolder( "destDirectory" ),
"toSymLink"
);

FileUtils.copyFile( from.toFile(), to, null, (FileUtils.FilterWrapper[]) null );

assertTrue(
"toSymLink did not exist so should have been written",
to.lastModified() >= MODIFIED_TODAY
);
assertFileContent( to, "Hello World!" );
}

@Test
public void copyFileWithNoFiltersAndOutdatedDestination()
throws Exception
Expand Down

0 comments on commit 94fa38a

Please sign in to comment.