diff --git a/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java b/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java index dbc7b8f5a2..6c8e877a1a 100644 --- a/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java +++ b/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java @@ -12,15 +12,10 @@ import hudson.tasks.Maven.MavenInstallation; import java.io.File; import java.io.IOException; -import java.net.URI; import java.util.Collection; import org.apache.commons.io.FileUtils; -import org.apache.commons.io.filefilter.IOFileFilter; -import org.apache.commons.io.filefilter.PrefixFileFilter; import org.junit.Assert; -import org.junit.BeforeClass; -import org.jvnet.hudson.test.Bug; import org.jvnet.hudson.test.ExtractResourceWithChangesSCM; import org.jvnet.hudson.test.HudsonTestCase; @@ -31,7 +26,6 @@ import org.jvnet.hudson.test.HudsonTestCase; * for jars in archive for build one and build two, expecting no jars in build 1 * and expecting jars in build 2 * - * @author redlab * */ public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase { @@ -55,7 +49,7 @@ public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase { super.setUp(); configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21); m = createMavenProject(); - m.setBuildDiscarder(new LogRotator("-1", "-1", "-1", "1")); + m.setBuildDiscarder(new LogRotator("-1", "2", "-1", "1")); m.getReporters().add(new TestReporter()); m.getReporters().add(new MavenFingerprinter()); m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource( @@ -66,15 +60,14 @@ public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase { m.setIncrementalBuild(false); buildAndAssertSuccess(m); FilePath workspace = m.getWorkspace(); - URI uri = workspace.toURI(); FilePath parent = workspace.getParent().getParent(); jobs = new FilePath(parent, "jobs"); } + @SuppressWarnings("unchecked") public void testArtifactsAreDeletedInBuildOneWhenBuildDiscarderRun() throws Exception { File directory = new File(new FilePath(jobs, "test0/builds/1").toURI()); - System.out.println(directory); Collection files = FileUtils.listFiles(directory, new String[] { "jar" }, true); Assert.assertTrue( @@ -85,4 +78,16 @@ public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase { Assert.assertFalse("No jars in last build ALERT!", files2.isEmpty()); } + /** + * Performs a third build and expecting build one to be deleted + * @throws Exception + */ + @SuppressWarnings("unchecked") + public void testArtifactsOldBuildsDeletedWhenBuildDiscarderRun() + throws Exception { + buildAndAssertSuccess(m); + File directory = new File(new FilePath(jobs, "test0/builds/1").toURI()); + Assert.assertFalse("oops the build should have been deleted", directory.exists()); + } + }