|
4 | 4 |
|
5 | 5 | import java.io.File; |
6 | 6 | import java.io.IOException; |
7 | | -import java.nio.file.Files; |
8 | | -import java.nio.file.LinkOption; |
9 | | -import java.nio.file.Path; |
10 | | -import java.nio.file.Paths; |
| 7 | +import java.nio.file.*; |
11 | 8 | import java.util.concurrent.ThreadLocalRandom; |
12 | 9 |
|
13 | 10 | import static org.junit.Assert.assertFalse; |
@@ -47,8 +44,18 @@ public void givenFile_whenExists_thenFilesShouldReturnTrue() throws IOException |
47 | 44 | public void givenSymbolicLink_whenTargetDoesNotExists_thenFollowOrNotBasedOnTheOptions() throws IOException { |
48 | 45 | Path target = Files.createTempFile("baeldung", "target"); |
49 | 46 | Path symbol = Paths.get("test-link-" + ThreadLocalRandom.current().nextInt()); |
| 47 | + Path symbolicLink = null; |
| 48 | + |
| 49 | + try { |
| 50 | + symbolicLink = Files.createSymbolicLink(symbol, target); |
| 51 | + } catch (FileSystemException ex) { |
| 52 | + System.out.println("Your OS security policy prevents the current user from creating symbolic links.\n" + |
| 53 | + "Most probably you're running Windows with UAC.\n" + |
| 54 | + "If this is the case, please see - https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/create-symbolic-links\n" + |
| 55 | + "You must change your security settings to run this test under Windows."); |
| 56 | + return; |
| 57 | + } |
50 | 58 |
|
51 | | - Path symbolicLink = Files.createSymbolicLink(symbol, target); |
52 | 59 | assertTrue(Files.exists(symbolicLink)); |
53 | 60 | assertTrue(Files.isSymbolicLink(symbolicLink)); |
54 | 61 | assertFalse(Files.isSymbolicLink(target)); |
|
0 commit comments