From e5786831ae5b51ac83fdb9cefd8787ff25d55bcc Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sun, 10 Nov 2024 06:20:25 -0500 Subject: [PATCH 1/2] Clean up assertions --- .../java/org/apache/maven/plugins/clean/CleanMojoTest.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/clean/CleanMojoTest.java b/src/test/java/org/apache/maven/plugins/clean/CleanMojoTest.java index 5a5d0d4..78d2c28 100644 --- a/src/test/java/org/apache/maven/plugins/clean/CleanMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/clean/CleanMojoTest.java @@ -52,7 +52,6 @@ */ @MojoTest public class CleanMojoTest { - private static final String LOCAL_REPO = "target/local-repo/"; /** * Tests the simple removal of directories @@ -175,7 +174,7 @@ public void testCleanLockedFile(CleanMojo mojo) throws Exception { mojo.execute(); fail("Should fail to delete a file that is locked"); } catch (MojoException expected) { - assertTrue(true); + assertNotNull(expected.getMessage()); } } @@ -199,9 +198,6 @@ public void testCleanLockedFileWithNoError(CleanMojo mojo) throws Exception { try (FileChannel channel = new RandomAccessFile(f, "rw").getChannel(); FileLock ignored = channel.lock()) { mojo.execute(); - assertTrue(true); - } catch (MojoException expected) { - fail("Should display a warning when deleting a file that is locked"); } } From 0fda3b7288ee1370de06285dcbdb17075b1bfad8 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 14 Nov 2024 07:51:38 -0500 Subject: [PATCH 2/2] assertThrows --- .../java/org/apache/maven/plugins/clean/CleanMojoTest.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/clean/CleanMojoTest.java b/src/test/java/org/apache/maven/plugins/clean/CleanMojoTest.java index 78d2c28..882a672 100644 --- a/src/test/java/org/apache/maven/plugins/clean/CleanMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/clean/CleanMojoTest.java @@ -45,7 +45,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; /** * Test the clean mojo. @@ -171,10 +170,7 @@ public void testCleanLockedFile(CleanMojo mojo) throws Exception { File f = new File(getBasedir(), "buildDirectory/file.txt"); try (FileChannel channel = new RandomAccessFile(f, "rw").getChannel(); FileLock ignored = channel.lock()) { - mojo.execute(); - fail("Should fail to delete a file that is locked"); - } catch (MojoException expected) { - assertNotNull(expected.getMessage()); + assertThrows(MojoException.class, () -> mojo.execute()); } }