Skip to content

Commit

Permalink
devonfw#139: added comments to test
Browse files Browse the repository at this point in the history
  • Loading branch information
MattesMrzik committed Dec 4, 2023
1 parent 24f3307 commit 496e434
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions cli/src/test/java/com/devonfw/tools/ide/io/FileAccessImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.context.IdeTestContextMock;

/**
* Test of {@link FileAccessImpl}.
*/
public class FileAccessImplTest extends AbstractIdeContextTest {

private boolean windowsJunctionsAreUsed(IdeContext context, Path dir) {
Expand All @@ -30,6 +33,9 @@ private boolean windowsJunctionsAreUsed(IdeContext context, Path dir) {
return false;
}

/**
* Test of {@link FileAccessImpl#symlink(Path, Path, boolean)} with "relative = false".
*/
@Test
public void testSymlinkNotRelative(@TempDir Path tempDir) {

Expand All @@ -51,6 +57,10 @@ public void testSymlinkNotRelative(@TempDir Path tempDir) {
assertSymlinksWork(dir, readLinks);
}

/**
* Test of {@link FileAccessImpl#symlink(Path, Path, boolean)} with "relative = true". But Windows junctions are used
* and therefore the fallback from relative to absolute paths is tested.
*/
@Test
public void testSymlinkAbsoluteAsFallback(@TempDir Path tempDir) {

Expand All @@ -76,6 +86,10 @@ public void testSymlinkAbsoluteAsFallback(@TempDir Path tempDir) {
assertSymlinksWork(dir, readLinks);
}

/**
* Test of {@link FileAccessImpl#symlink(Path, Path, boolean)} with "relative = false". Furthermore, it is tested that
* the links are broken after moving them.
*/
@Test
public void testAbsoluteLinksBreakAfterMoving(@TempDir Path tempDir) throws IOException {

Expand All @@ -84,7 +98,8 @@ public void testAbsoluteLinksBreakAfterMoving(@TempDir Path tempDir) throws IOEx
FileAccess fileAccess = new FileAccessImpl(context);
Path dir = tempDir.resolve("parent");
createDirs(fileAccess, dir);
createSymlinks(fileAccess, dir, false);
boolean relative = false;
createSymlinks(fileAccess, dir, relative);
boolean readLinks = !windowsJunctionsAreUsed(context, tempDir);

// act
Expand All @@ -96,6 +111,10 @@ public void testAbsoluteLinksBreakAfterMoving(@TempDir Path tempDir) throws IOEx
assertSymlinksAreBroken(sibling, readLinks);
}

/**
* Test of {@link FileAccessImpl#symlink(Path, Path, boolean)} with "relative = true". Furthermore, it is tested that
* the links still work after moving them.
*/
@Test
public void testRelativeLinksWorkAfterMoving(@TempDir Path tempDir) {

Expand All @@ -108,7 +127,8 @@ public void testRelativeLinksWorkAfterMoving(@TempDir Path tempDir) {
FileAccess fileAccess = new FileAccessImpl(context);
Path dir = tempDir.resolve("parent");
createDirs(fileAccess, dir);
createSymlinks(fileAccess, dir, true);
boolean relative = true;
createSymlinks(fileAccess, dir, relative);
boolean readLinks = true; // junctions are not used, so links can be read with Files.readSymbolicLink(link);

// act
Expand All @@ -120,6 +140,10 @@ public void testRelativeLinksWorkAfterMoving(@TempDir Path tempDir) {
assertSymlinksWork(sibling, readLinks);
}

/**
* Test of {@link FileAccessImpl#symlink(Path, Path, boolean)} when Windows junctions are used and the source is a
* file.
*/
@Test
public void testWindowsJunctionsCanNotPointToFiles(@TempDir Path tempDir) throws IOException {

Expand Down

0 comments on commit 496e434

Please sign in to comment.