You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2025/04/18 11:32:02 UTC

(maven-dependency-plugin) branch testing created (now ebf1f39a)

This is an automated email from the ASF dual-hosted git repository.

elharo pushed a change to branch testing
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git


      at ebf1f39a Clean up test teardown adn temp directories

This branch includes the following new commits:

     new ebf1f39a Clean up test teardown adn temp directories

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven-dependency-plugin) 01/01: Clean up test teardown adn temp directories

Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch testing
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit ebf1f39a81b6f76485853ffc067803cb2b2e23d4
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Fri Apr 18 07:31:54 2025 -0400

    Clean up test teardown adn temp directories
---
 .../dependency/AbstractDependencyMojoTestCase.java     | 18 +++++++-----------
 .../TestIncludeExcludeUnpackMojo.java                  |  7 +++----
 .../TestIncludeExcludeUnpackDependenciesMojo.java      |  9 +--------
 .../fromDependencies/TestUnpackDependenciesMojo.java   |  5 ++---
 .../fromDependencies/TestUnpackDependenciesMojo2.java  | 13 +++----------
 5 files changed, 16 insertions(+), 36 deletions(-)

diff --git a/src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTestCase.java b/src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTestCase.java
index 6ac6ff22..9681f242 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTestCase.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTestCase.java
@@ -43,31 +43,27 @@ public abstract class AbstractDependencyMojoTestCase extends AbstractMojoTestCas
 
     protected DependencyArtifactStubFactory stubFactory;
 
-    protected void setUp(String testDirStr, boolean createFiles) throws Exception {
-        setUp(testDirStr, createFiles, true);
+    protected void setUp(String testDirectoryName, boolean createFiles) throws Exception {
+        setUp(testDirectoryName, createFiles, true);
     }
 
-    protected void setUp(String testDirStr, boolean createFiles, boolean flattenedPath) throws Exception {
+    protected void setUp(String testDirectoryName, boolean createFiles, boolean flattenedPath) throws Exception {
         // required for mojo lookups to work
         super.setUp();
 
-        testDir = Files.createTempDirectory("testDirStr").toFile();
+        testDir = Files.createTempDirectory(testDirectoryName).toFile();
         testDir.deleteOnExit();
 
         stubFactory = new DependencyArtifactStubFactory(this.testDir, createFiles, flattenedPath);
     }
 
     @Override
-    protected void tearDown() {
+    protected void tearDown() throws Exception {
         if (testDir != null) {
-            try {
-                FileUtils.deleteDirectory(testDir);
-            } catch (IOException e) {
-                e.printStackTrace();
-                fail("Trying to remove directory: " + testDir + System.lineSeparator() + e);
-            }
+            FileUtils.deleteDirectory(testDir);
             assertFalse(testDir.exists());
         }
+        super.tearDown();
     }
 
     protected void copyArtifactFile(Artifact sourceArtifact, File destFile) throws MojoExecutionException, IOException {
diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java
index 02c3644c..f913e0d4 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java
@@ -57,7 +57,7 @@ public class TestIncludeExcludeUnpackMojo extends AbstractDependencyMojoTestCase
         mojo = (UnpackMojo) lookupMojo("unpack", testPom);
         mojo.setOutputDirectory(new File(this.testDir, "outputDirectory"));
 
-        // i'm using one file repeatedly to archive so I can test the name
+        // I'm using one file repeatedly to archive so I can test the name
         // programmatically.
         stubFactory.setSrcFile(new File(getBasedir() + File.separatorChar + PACKED_FILE_PATH));
         Artifact artifact = stubFactory.createArtifact("test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null);
@@ -75,11 +75,10 @@ public class TestIncludeExcludeUnpackMojo extends AbstractDependencyMojoTestCase
         installLocalRepository(legacySupport);
     }
 
-    protected void tearDown() {
-        super.tearDown();
-
+    protected void tearDown() throws Exception {
         mojo = null;
         System.gc();
+        super.tearDown();
     }
 
     public void assertMarkerFiles(Collection<ArtifactItem> items, boolean exist) {
diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestIncludeExcludeUnpackDependenciesMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestIncludeExcludeUnpackDependenciesMojo.java
index 0617b875..8c290a14 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestIncludeExcludeUnpackDependenciesMojo.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestIncludeExcludeUnpackDependenciesMojo.java
@@ -54,7 +54,7 @@ public class TestIncludeExcludeUnpackDependenciesMojo extends AbstractDependency
 
         // it needs to get the archivermanager
         // stubFactory.setUnpackableFile( mojo.getArchiverManager() );
-        // i'm using one file repeatedly to archive so I can test the name
+        // I'm using one file repeatedly to archive so I can test the name
         // programmatically.
         stubFactory.setSrcFile(new File(getBasedir() + File.separatorChar + PACKED_FILE_PATH));
 
@@ -70,13 +70,6 @@ public class TestIncludeExcludeUnpackDependenciesMojo extends AbstractDependency
         mojo.markersDirectory = new File(this.testDir, "markers");
     }
 
-    protected void tearDown() {
-        super.tearDown();
-
-        mojo = null;
-        System.gc();
-    }
-
     private void assertUnpacked(boolean unpacked, String fileName) {
         File destFile = new File(mojo.getOutputDirectory().getAbsolutePath(), fileName);
         assertEquals(unpacked, destFile.exists());
diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java
index 9c913e2a..1cf8e0e8 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java
@@ -91,11 +91,10 @@ public class TestUnpackDependenciesMojo extends AbstractDependencyMojoTestCase {
         setVariableValueToObject(mojo, "artifactHandlerManager", manager);
     }
 
-    protected void tearDown() {
-        super.tearDown();
-
+    protected void tearDown() throws Exception {
         mojo = null;
         System.gc();
+        super.tearDown();
     }
 
     public void assertUnpacked(Artifact artifact) {
diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo2.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo2.java
index 27e43c9f..8711a458 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo2.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo2.java
@@ -34,6 +34,8 @@ import org.apache.maven.plugins.dependency.utils.DependencyUtil;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.archiver.manager.ArchiverManager;
 
+import static org.junit.Assert.assertNotEquals;
+
 public class TestUnpackDependenciesMojo2 extends AbstractDependencyMojoTestCase {
 
     private final String UNPACKABLE_FILE = "test.txt";
@@ -73,13 +75,6 @@ public class TestUnpackDependenciesMojo2 extends AbstractDependencyMojoTestCase
         mojo.markersDirectory = new File(this.testDir, "markers");
     }
 
-    protected void tearDown() {
-        super.tearDown();
-
-        mojo = null;
-        System.gc();
-    }
-
     public File getUnpackedFile(Artifact artifact) {
         File destDir = DependencyUtil.getFormattedOutputDirectory(
                 mojo.isUseSubDirectoryPerScope(),
@@ -211,9 +206,7 @@ public class TestUnpackDependenciesMojo2 extends AbstractDependencyMojoTestCase
 
         mojo.execute();
 
-        assertTrue(time != unpackedFile.lastModified());
-
-        System.gc();
+        assertNotEquals(time, unpackedFile.lastModified());
     }
 
     public void assertUnpacked(Artifact artifact, boolean overWrite)