BAEL-1933 Added code examples and unit tests for creating symbolic links (#4608)

* BAEL-1933 Added code examples and unit tests for creating symbolic links

* Fixed PMD violation on unit test naming

* Fixed review comments

* Applied baeldung-eclipse formatter settings
This commit is contained in:
Timoteo Ponce
2018-07-05 15:02:31 -04:00
committed by Predrag Maric
parent f06f061075
commit 234107f519
2 changed files with 90 additions and 0 deletions
@@ -0,0 +1,36 @@
package com.baeldung.symlink;
import static org.junit.Assert.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.Test;
public class SymLinkExampleUnitTest {
@Test
public void whenUsingFiles_thenCreateSymbolicLink() throws IOException {
SymLinkExample example = new SymLinkExample();
Path filePath = example.createTextFile();
Path linkPath = Paths.get(".", "symbolic_link.txt");
example.createSymbolicLink(linkPath, filePath);
assertTrue(Files.isSymbolicLink(linkPath));
}
@Test
public void whenUsingFiles_thenCreateHardLink() throws IOException {
SymLinkExample example = new SymLinkExample();
Path filePath = example.createTextFile();
Path linkPath = Paths.get(".", "hard_link.txt");
example.createHardLink(linkPath, filePath);
assertFalse(Files.isSymbolicLink(linkPath));
assertEquals(filePath.toFile()
.length(),
linkPath.toFile()
.length());
}
}