Fix FilePermissionsTests on Windows

See gh-26658
This commit is contained in:
Scott Frederick 2021-06-08 15:10:14 -05:00
parent 8df6392ca5
commit fba5ffc626

View File

@ -27,11 +27,15 @@ import java.util.Collections;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIOException;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/**
* Tests for {@link FilePermissions}.
@ -44,6 +48,7 @@ class FilePermissionsTests {
Path tempDir;
@Test
@DisabledOnOs(OS.WINDOWS)
void umaskForPath() throws IOException {
FileAttribute<Set<PosixFilePermission>> fileAttribute = PosixFilePermissions
.asFileAttribute(PosixFilePermissions.fromString("rw-r-----"));
@ -52,11 +57,20 @@ class FilePermissionsTests {
}
@Test
@DisabledOnOs(OS.WINDOWS)
void umaskForPathWithNonExistentFile() throws IOException {
assertThatIOException()
.isThrownBy(() -> FilePermissions.umaskForPath(Paths.get(this.tempDir.toString(), "does-not-exist")));
}
@Test
@EnabledOnOs(OS.WINDOWS)
void umaskForPathOnWindowsFails() throws IOException {
Path tempFile = Files.createTempFile("umask", null);
assertThatIllegalStateException().isThrownBy(() -> FilePermissions.umaskForPath(tempFile))
.withMessageContaining("Unsupported file type for retrieving Posix attributes");
}
@Test
void umaskForPathWithNullPath() throws IOException {
assertThatIllegalArgumentException().isThrownBy(() -> FilePermissions.umaskForPath(null));