|
45 | 45 | import org.junit.jupiter.api.TestInfo; |
46 | 46 | import org.junit.jupiter.api.TestInstance; |
47 | 47 | import org.junit.jupiter.api.TestMethodOrder; |
| 48 | +import org.junit.jupiter.api.condition.DisabledOnOs; |
| 49 | +import org.junit.jupiter.api.condition.OS; |
48 | 50 | import org.junit.jupiter.api.extension.ExtensionConfigurationException; |
49 | 51 | import org.junit.jupiter.api.extension.ParameterResolutionException; |
50 | 52 | import org.junit.jupiter.api.io.TempDir; |
@@ -84,11 +86,27 @@ void tempDirectoryDoesNotPreventUserFromDeletingTempDir() { |
84 | 86 |
|
85 | 87 | @Test |
86 | 88 | @DisplayName("is capable of removal of a read-only file") |
87 | | - void nonWritableFileDoesNotCauseFailureTestCase() { |
| 89 | + void nonWritableFileDoesNotCauseFailure() { |
88 | 90 | executeTestsForClass(NonWritableFileDoesNotCauseFailureTestCase.class).testEvents()// |
89 | 91 | .assertStatistics(stats -> stats.started(1).succeeded(1)); |
90 | 92 | } |
91 | 93 |
|
| 94 | + @Test |
| 95 | + @DisabledOnOs(OS.WINDOWS) |
| 96 | + @DisplayName("is capable of removal of a read-only file in a read-only dir") |
| 97 | + void readOnlyFileInReadOnlyDirDoesNotCauseFailure() { |
| 98 | + executeTestsForClass(ReadOnlyFileInReadOnlyDirDoesNotCauseFailureTestCase.class).testEvents()// |
| 99 | + .assertStatistics(stats -> stats.started(1).succeeded(1)); |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + @DisabledOnOs(OS.WINDOWS) |
| 104 | + @DisplayName("is capable of removal of a read-only file in a dir in a read-only dir") |
| 105 | + void readOnlyFileInNestedReadOnlyDirDoesNotCauseFailure() { |
| 106 | + executeTestsForClass(ReadOnlyFileInDirInReadOnlyDirDoesNotCauseFailureTestCase.class).testEvents()// |
| 107 | + .assertStatistics(stats -> stats.started(1).succeeded(1)); |
| 108 | + } |
| 109 | + |
92 | 110 | @Test |
93 | 111 | @DisplayName("can be used via instance field inside nested test classes") |
94 | 112 | void canBeUsedViaInstanceFieldInsideNestedTestClasses() { |
@@ -780,6 +798,34 @@ void createReadonlyFile(@TempDir Path tempDir) throws IOException { |
780 | 798 |
|
781 | 799 | } |
782 | 800 |
|
| 801 | + // https://github.com/junit-team/junit5/issues/2171 |
| 802 | + static class ReadOnlyFileInReadOnlyDirDoesNotCauseFailureTestCase { |
| 803 | + |
| 804 | + @Test |
| 805 | + void createReadOnlyFileInReadOnlyDir(@TempDir File tempDir) throws IOException { |
| 806 | + File file = tempDir.toPath().resolve("file").toFile(); |
| 807 | + assumeTrue(file.createNewFile()); |
| 808 | + assumeTrue(tempDir.setReadOnly()); |
| 809 | + assumeTrue(file.setReadOnly()); |
| 810 | + } |
| 811 | + |
| 812 | + } |
| 813 | + |
| 814 | + // https://github.com/junit-team/junit5/issues/2171 |
| 815 | + static class ReadOnlyFileInDirInReadOnlyDirDoesNotCauseFailureTestCase { |
| 816 | + |
| 817 | + @Test |
| 818 | + void createReadOnlyFileInReadOnlyDir(@TempDir File tempDir) throws IOException { |
| 819 | + File file = tempDir.toPath().resolve("dir").resolve("file").toFile(); |
| 820 | + assumeTrue(file.getParentFile().mkdirs()); |
| 821 | + assumeTrue(file.createNewFile()); |
| 822 | + assumeTrue(tempDir.setReadOnly()); |
| 823 | + assumeTrue(file.getParentFile().setReadOnly()); |
| 824 | + assumeTrue(file.setReadOnly()); |
| 825 | + } |
| 826 | + |
| 827 | + } |
| 828 | + |
783 | 829 | // https://github.com/junit-team/junit5/issues/2079 |
784 | 830 | static class TempDirUsageInsideNestedClassesTestCase { |
785 | 831 |
|
|
0 commit comments