Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 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,43 @@ public void copyFileWithNoFiltersAndLastModifiedDateOfZeroAndNoDestination()
assertFileContent( to, "Hello World!" );
}

@Test
public void copyRelativeSymbolicLinkFileWithNonExistingTargetWithNoFiltersAndNoDestination()
throws Exception
{
write(
"target.txt",
MODIFIED_YESTERDAY,
"Hello World!"
);
// must be a relative symbolic link to existing target
Path from = Files.createSymbolicLink( new File(tempFolder.getRoot(), "symLink").toPath(), Paths.get( "target.txt" ) );
File to = new File(
tempFolder.newFolder( "destDirectory" ),
"toSymLink"
);
// this creates a symlink in a new folder pointing to a non-existing relative target "./target.txt"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directory, not folder

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

// this should not fail
}

@Test
public void copySymbolicLinkFileWithNonExistingTargetWithNoFiltersAndNoDestination()
throws Exception
{
// link to non existing target
Path from = Files.createSymbolicLink( new File(tempFolder.getRoot(), "symLink").toPath(), Paths.get( "non-existing.txt" ) );
File to = new File(
tempFolder.getRoot(),
"toSymLink"
);
// this creates a symlink in a new folder pointing to a non-existing relative target "./non-existing.txt"
FileUtils.copyFile( from.toFile(), to, null, (FileUtils.FilterWrapper[]) null );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directory, not folder


// this should not fail
}

@Test
public void copyFileWithNoFiltersAndOutdatedDestination()
throws Exception
Expand Down