Skip to content

Commit

Permalink
Fix FilePermissionsTests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
scottfrederick committed Jun 8, 2021
1 parent 8df6392 commit fba5ffc
Showing 1 changed file with 14 additions and 0 deletions.
Expand Up @@ -27,11 +27,15 @@
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}.
Expand All @@ -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-----"));
Expand All @@ -52,11 +57,20 @@ void umaskForPath() throws IOException {
}

@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));
Expand Down

0 comments on commit fba5ffc

Please sign in to comment.