|
8 | 8 | import java.nio.file.Files; |
9 | 9 | import java.nio.file.Path; |
10 | 10 | import java.nio.file.Paths; |
11 | | -import java.nio.file.attribute.PosixFilePermission; |
12 | | -import java.util.HashSet; |
13 | | -import java.util.Set; |
14 | 11 | import java.util.stream.Stream; |
15 | 12 | import org.junit.jupiter.api.AfterEach; |
16 | | -import org.junit.jupiter.api.Assumptions; |
17 | 13 | import org.junit.jupiter.api.Test; |
18 | 14 | import org.junit.jupiter.api.io.TempDir; |
19 | 15 | import org.slf4j.Logger; |
@@ -48,25 +44,13 @@ void validateOrCreateTargetDirectory_DirectoryDoesNotExist_CreatesDirectory() |
48 | 44 | @Test |
49 | 45 | void validateOrCreateTargetDirectory_DirectoryNotWritable_ThrowsException() throws IOException { |
50 | 46 | Path readOnlyDirectory = Files.createDirectory(Paths.get(tempDir.toString(), "readOnlyDir")); |
| 47 | + readOnlyDirectory.toFile().setWritable(false); |
51 | 48 |
|
52 | | - // Try to make it read-only using POSIX if supported |
53 | | - try { |
54 | | - Set<PosixFilePermission> perms = new HashSet<>(); |
55 | | - perms.add(PosixFilePermission.OWNER_READ); |
56 | | - perms.add(PosixFilePermission.OWNER_EXECUTE); |
57 | | - Files.setPosixFilePermissions(readOnlyDirectory, perms); |
58 | | - } catch (UnsupportedOperationException | IOException e) { |
59 | | - // Fall back for systems without POSIX support |
60 | | - readOnlyDirectory.toFile().setWritable(false); |
61 | | - } |
62 | | - // Verify it is actually non-writable |
63 | | - boolean isWritable = Files.isWritable(readOnlyDirectory); |
64 | | - Assumptions.assumeFalse(isWritable, "Directory is still writable; skipping test."); |
65 | | - |
66 | | - // Test |
67 | 49 | assertThrows( |
68 | 50 | DirectoryValidationException.class, |
69 | | - () -> DirectoryUtils.validateOrCreateTargetDirectory(readOnlyDirectory.toString())); |
| 51 | + () -> { |
| 52 | + DirectoryUtils.validateOrCreateTargetDirectory(readOnlyDirectory.toString()); |
| 53 | + }); |
70 | 54 | } |
71 | 55 |
|
72 | 56 | @Test |
|
0 commit comments