3030import java .io .IOException ;
3131import java .nio .file .Files ;
3232import java .nio .file .Path ;
33+ import java .nio .file .attribute .DosFileAttributeView ;
3334import java .util .Deque ;
3435import java .util .LinkedList ;
3536import java .util .function .Supplier ;
4748import org .junit .jupiter .api .TestInfo ;
4849import org .junit .jupiter .api .TestInstance ;
4950import org .junit .jupiter .api .TestMethodOrder ;
50- import org .junit .jupiter .api .condition .DisabledOnOs ;
51- import org .junit .jupiter .api .condition .OS ;
5251import org .junit .jupiter .api .extension .ExtensionConfigurationException ;
5352import org .junit .jupiter .api .extension .ExtensionContext ;
5453import org .junit .jupiter .api .extension .ParameterResolutionException ;
@@ -126,15 +125,13 @@ void nonMintPermissionsDoNotCauseFailure() {
126125 }
127126
128127 @ Test
129- @ DisabledOnOs (OS .WINDOWS )
130128 @ DisplayName ("is capable of removing a read-only file in a read-only dir" )
131129 void readOnlyFileInReadOnlyDirDoesNotCauseFailure () {
132130 executeTestsForClass (ReadOnlyFileInReadOnlyDirDoesNotCauseFailureTestCase .class ).testEvents ()//
133131 .assertStatistics (stats -> stats .started (1 ).succeeded (1 ));
134132 }
135133
136134 @ Test
137- @ DisabledOnOs (OS .WINDOWS )
138135 @ DisplayName ("is capable of removing a read-only file in a dir in a read-only dir" )
139136 void readOnlyFileInNestedReadOnlyDirDoesNotCauseFailure () {
140137 executeTestsForClass (ReadOnlyFileInDirInReadOnlyDirDoesNotCauseFailureTestCase .class ).testEvents ()//
@@ -942,8 +939,8 @@ static class ReadOnlyFileInReadOnlyDirDoesNotCauseFailureTestCase {
942939 void createReadOnlyFileInReadOnlyDir (@ TempDir File tempDir ) throws IOException {
943940 File file = tempDir .toPath ().resolve ("file" ).toFile ();
944941 assumeTrue (file .createNewFile ());
945- assumeTrue (tempDir . setReadOnly ( ));
946- assumeTrue (file . setReadOnly ( ));
942+ assumeTrue (makeReadOnly ( tempDir ));
943+ assumeTrue (makeReadOnly ( file ));
947944 }
948945
949946 }
@@ -956,13 +953,22 @@ void createReadOnlyFileInReadOnlyDir(@TempDir File tempDir) throws IOException {
956953 File file = tempDir .toPath ().resolve ("dir" ).resolve ("file" ).toFile ();
957954 assumeTrue (file .getParentFile ().mkdirs ());
958955 assumeTrue (file .createNewFile ());
959- assumeTrue (tempDir . setReadOnly ( ));
960- assumeTrue (file .getParentFile (). setReadOnly ( ));
961- assumeTrue (file . setReadOnly ( ));
956+ assumeTrue (makeReadOnly ( tempDir ));
957+ assumeTrue (makeReadOnly ( file .getParentFile ()));
958+ assumeTrue (makeReadOnly ( file ));
962959 }
963960
964961 }
965962
963+ private static boolean makeReadOnly (File file ) throws IOException {
964+ var dos = Files .getFileAttributeView (file .toPath (), DosFileAttributeView .class );
965+ if (dos != null ) {
966+ dos .setReadOnly (true );
967+ return true ;
968+ }
969+ return file .setReadOnly ();
970+ }
971+
966972 // https://github.com/junit-team/junit5/issues/2609
967973 @ SuppressWarnings ("ResultOfMethodCallIgnored" )
968974 static class NonMintPermissionContentInTempDirectoryDoesNotCauseFailureTestCase {
0 commit comments