You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2021/01/23 00:31:21 UTC
[maven-clean-plugin] 02/03: (doc) quick fixes - tests
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch fix
in repository https://gitbox.apache.org/repos/asf/maven-clean-plugin.git
commit 297631d5581d11c79f9b31db8bbd0dc73909b014
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Sat Jan 23 01:16:21 2021 +0100
(doc) quick fixes - tests
---
.../apache/maven/plugins/clean/CleanMojoTest.java | 84 +++++-----------------
1 file changed, 18 insertions(+), 66 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 3083cce..9bf3b63 100644
--- a/src/test/java/org/apache/maven/plugins/clean/CleanMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/clean/CleanMojoTest.java
@@ -19,16 +19,15 @@ package org.apache.maven.plugins.clean;
* under the License.
*/
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.apache.maven.shared.utils.io.FileUtils;
+
import java.io.File;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-import org.apache.maven.plugins.clean.CleanMojo;
-import org.codehaus.plexus.util.FileUtils;
-
/**
* Test the clean mojo.
*
@@ -37,20 +36,6 @@ import org.codehaus.plexus.util.FileUtils;
public class CleanMojoTest
extends AbstractMojoTestCase
{
- /** {@inheritDoc} */
- protected void setUp()
- throws Exception
- {
- super.setUp();
- }
-
- /** {@inheritDoc} */
- protected void tearDown()
- throws Exception
- {
- super.tearDown();
- }
-
/**
* Tests the simple removal of directories
*
@@ -63,7 +48,7 @@ public class CleanMojoTest
// safety
FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/basic-clean-test" ),
- new File( getBasedir(), "target/test-classes/unit/basic-clean-test" ), null, "**/.svn,**/.svn/**" );
+ new File( getBasedir(), "target/test-classes/unit/basic-clean-test" ) );
CleanMojo mojo = (CleanMojo) lookupMojo( "clean", pluginPom );
assertNotNull( mojo );
@@ -90,7 +75,7 @@ public class CleanMojoTest
// safety
FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/nested-clean-test" ),
- new File( getBasedir(), "target/test-classes/unit/nested-clean-test" ), null, "**/.svn,**/.svn/**" );
+ new File( getBasedir(), "target/test-classes/unit/nested-clean-test" ) );
CleanMojo mojo = (CleanMojo) lookupMojo( "clean", pluginPom );
assertNotNull( mojo );
@@ -115,7 +100,7 @@ public class CleanMojoTest
// safety
FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/empty-clean-test" ),
- new File( getBasedir(), "target/test-classes/unit/empty-clean-test" ), null, "**/.svn,**/.svn/**" );
+ new File( getBasedir(), "target/test-classes/unit/empty-clean-test" ) );
CleanMojo mojo = (CleanMojo) lookupEmptyMojo( "clean", pluginPom );
assertNotNull( mojo );
@@ -143,7 +128,7 @@ public class CleanMojoTest
// safety
FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/fileset-clean-test" ),
- new File( getBasedir(), "target/test-classes/unit/fileset-clean-test" ), null, "**/.svn,**/.svn/**" );
+ new File( getBasedir(), "target/test-classes/unit/fileset-clean-test" ) );
CleanMojo mojo = (CleanMojo) lookupMojo( "clean", pluginPom );
assertNotNull( mojo );
@@ -179,7 +164,7 @@ public class CleanMojoTest
// safety
FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/invalid-directory-test" ),
- new File( getBasedir(), "target/test-classes/unit/invalid-directory-test" ), null, "**/.svn,**/.svn/**" );
+ new File( getBasedir(), "target/test-classes/unit/invalid-directory-test" ) );
CleanMojo mojo = (CleanMojo) lookupMojo( "clean", pluginPom );
assertNotNull( mojo );
@@ -208,7 +193,7 @@ public class CleanMojoTest
// safety
FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/missing-directory-test" ),
- new File( getBasedir(), "target/test-classes/unit/missing-directory-test" ), null, "**/.svn,**/.svn/**" );
+ new File( getBasedir(), "target/test-classes/unit/missing-directory-test" ) );
CleanMojo mojo = (CleanMojo) lookupMojo( "clean", pluginPom );
assertNotNull( mojo );
@@ -239,39 +224,22 @@ public class CleanMojoTest
// safety
FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/locked-file-test" ),
- new File( getBasedir(), "target/test-classes/unit/locked-file-test" ), null, "**/.svn,**/.svn/**" );
+ new File( getBasedir(), "target/test-classes/unit/locked-file-test" ) );
CleanMojo mojo = (CleanMojo) lookupMojo( "clean", pluginPom );
assertNotNull( mojo );
File f = new File( getBasedir(), "target/test-classes/unit/locked-file-test/buildDirectory/file.txt" );
- FileChannel channel = null;
- FileLock lock = null;
- try
+ try ( FileChannel channel = new RandomAccessFile( f, "rw" ).getChannel();
+ FileLock ignored = channel.lock() )
{
- channel = new RandomAccessFile( f, "rw" ).getChannel();
- lock = channel.lock();
-
mojo.execute();
-
fail( "Should fail to delete a file that is locked" );
}
catch ( MojoExecutionException expected )
{
assertTrue( true );
}
- finally
- {
- if ( lock != null )
- {
- lock.release();
- }
-
- if ( channel != null )
- {
- channel.close();
- }
- }
}
/**
@@ -295,40 +263,23 @@ public class CleanMojoTest
// safety
FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/locked-file-test" ),
- new File( getBasedir(), "target/test-classes/unit/locked-file-test" ), null, "**/.svn,**/.svn/**" );
+ new File( getBasedir(), "target/test-classes/unit/locked-file-test" ) );
CleanMojo mojo = (CleanMojo) lookupMojo( "clean", pluginPom );
setVariableValueToObject( mojo, "failOnError", Boolean.FALSE );
assertNotNull( mojo );
File f = new File( getBasedir(), "target/test-classes/unit/locked-file-test/buildDirectory/file.txt" );
- FileChannel channel = null;
- FileLock lock = null;
- try
+ try ( FileChannel channel = new RandomAccessFile( f, "rw" ).getChannel();
+ FileLock ignored = channel.lock())
{
- channel = new RandomAccessFile( f, "rw" ).getChannel();
- lock = channel.lock();
-
mojo.execute();
-
assertTrue( true );
}
catch ( MojoExecutionException expected )
{
fail( "Should display a warning when deleting a file that is locked" );
}
- finally
- {
- if ( lock != null )
- {
- lock.release();
- }
-
- if ( channel != null )
- {
- channel.close();
- }
- }
}
/**
@@ -346,6 +297,7 @@ public class CleanMojoTest
*/
private boolean checkEmpty( String dir )
{
- return new File( dir ).listFiles().length == 0;
+ File[] files = new File( dir ).listFiles();
+ return files == null || files.length == 0;
}
}