Skip to content

Commit

Permalink
[MCLEAN-124] Replace JUnit Assumptions with @DisabledOnOs, to better …
Browse files Browse the repository at this point in the history
…align with surrounding tests
  • Loading branch information
peterdemaeyer authored and slawekjaranowski committed Nov 12, 2024
1 parent cb2127f commit 091570b
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/test/java/org/apache/maven/plugins/clean/CleanerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
import java.io.IOException;
import java.nio.file.AccessDeniedException;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set;

import org.apache.maven.plugin.logging.Log;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
Expand All @@ -42,7 +43,6 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.inOrder;
Expand All @@ -54,14 +54,11 @@

class CleanerTest {

private static final boolean POSIX_COMPLIANT =
FileSystems.getDefault().supportedFileAttributeViews().contains("posix");

private final Log log = mock();

@Test
@DisabledOnOs(OS.WINDOWS)
void deleteSucceedsDeeply(@TempDir Path tempDir) throws Exception {
assumeTrue(POSIX_COMPLIANT);
final Path basedir = createDirectory(tempDir.resolve("target")).toRealPath();
final Path file = createFile(basedir.resolve("file"));
final Cleaner cleaner = new Cleaner(null, log, false, null, null);
Expand All @@ -71,8 +68,8 @@ void deleteSucceedsDeeply(@TempDir Path tempDir) throws Exception {
}

@Test
@DisabledOnOs(OS.WINDOWS)
void deleteFailsWithoutRetryWhenNoPermission(@TempDir Path tempDir) throws Exception {
assumeTrue(POSIX_COMPLIANT);
when(log.isWarnEnabled()).thenReturn(true);
final Path basedir = createDirectory(tempDir.resolve("target")).toRealPath();
createFile(basedir.resolve("file"));
Expand All @@ -90,8 +87,8 @@ void deleteFailsWithoutRetryWhenNoPermission(@TempDir Path tempDir) throws Excep
}

@Test
@DisabledOnOs(OS.WINDOWS)
void deleteFailsAfterRetryWhenNoPermission(@TempDir Path tempDir) throws Exception {
assumeTrue(POSIX_COMPLIANT);
final Path basedir = createDirectory(tempDir.resolve("target")).toRealPath();
createFile(basedir.resolve("file"));
// Remove the executable flag to prevent directory listing, which will result in a DirectoryNotEmptyException.
Expand All @@ -107,8 +104,8 @@ void deleteFailsAfterRetryWhenNoPermission(@TempDir Path tempDir) throws Excepti
}

@Test
@DisabledOnOs(OS.WINDOWS)
void deleteLogsWarningWithoutRetryWhenNoPermission(@TempDir Path tempDir) throws Exception {
assumeTrue(POSIX_COMPLIANT);
when(log.isWarnEnabled()).thenReturn(true);
final Path basedir = createDirectory(tempDir.resolve("target")).toRealPath();
final Path file = createFile(basedir.resolve("file"));
Expand All @@ -128,8 +125,8 @@ void deleteLogsWarningWithoutRetryWhenNoPermission(@TempDir Path tempDir) throws
}

@Test
@DisabledOnOs(OS.WINDOWS)
void deleteDoesNotLogAnythingWhenNoPermissionAndWarnDisabled(@TempDir Path tempDir) throws Exception {
assumeTrue(POSIX_COMPLIANT);
when(log.isWarnEnabled()).thenReturn(false);
final Path basedir = createDirectory(tempDir.resolve("target")).toRealPath();
createFile(basedir.resolve("file"));
Expand Down

0 comments on commit 091570b

Please sign in to comment.