diff --git a/dependency-check-ant/pom.xml b/dependency-check-ant/pom.xml index ca0a4a782..dc10e0231 100644 --- a/dependency-check-ant/pom.xml +++ b/dependency-check-ant/pom.xml @@ -423,12 +423,10 @@ Copyright (c) 2013 - Jeremy Long. All Rights Reserved. org.apache.ant ant - 1.9.4 org.apache.ant ant-testutil - 1.9.4 test diff --git a/dependency-check-ant/src/test/java/org/owasp/dependencycheck/taskdefs/DependencyCheckTaskTest.java b/dependency-check-ant/src/test/java/org/owasp/dependencycheck/taskdefs/DependencyCheckTaskTest.java index d7d9deb47..f381e04d2 100644 --- a/dependency-check-ant/src/test/java/org/owasp/dependencycheck/taskdefs/DependencyCheckTaskTest.java +++ b/dependency-check-ant/src/test/java/org/owasp/dependencycheck/taskdefs/DependencyCheckTaskTest.java @@ -18,34 +18,41 @@ package org.owasp.dependencycheck.taskdefs; import java.io.File; -import org.apache.tools.ant.BuildFileTest; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.owasp.dependencycheck.data.nvdcve.BaseDBTestCase; import org.owasp.dependencycheck.utils.Settings; +import static org.junit.Assert.assertTrue; + + /** * * @author Jeremy Long */ -public class DependencyCheckTaskTest extends BuildFileTest { - //TODO: The use of deprecated class BuildFileTestcan possibly - //be replaced with BuildFileRule. However, it currently isn't included in the ant-testutil jar. - //This should be fixed in ant-testutil 1.9.5, so we can check back once that has been released. - //Reference: http://mail-archives.apache.org/mod_mbox/ant-user/201406.mbox/%3C000001cf87ba$8949b690$9bdd23b0$@de%3E +public class DependencyCheckTaskTest { + + @Rule + public BuildFileRule buildFileRule = new BuildFileRule(); + + @Rule + public ExpectedException expectedException = ExpectedException.none(); @Before - @Override public void setUp() throws Exception { Settings.initialize(); BaseDBTestCase.ensureDBExists(); final String buildFile = this.getClass().getClassLoader().getResource("build.xml").getPath(); - configureProject(buildFile); + buildFileRule.configureProject(buildFile); } @After - @Override public void tearDown() { //no cleanup... //executeTarget("cleanup"); @@ -63,7 +70,7 @@ public class DependencyCheckTaskTest extends BuildFileTest { throw new Exception("Unable to delete 'target/DependencyCheck-Report.html' prior to test."); } } - executeTarget("test.fileset"); + buildFileRule.executeTarget("test.fileset"); assertTrue("DependencyCheck report was not generated", report.exists()); @@ -82,7 +89,7 @@ public class DependencyCheckTaskTest extends BuildFileTest { throw new Exception("Unable to delete 'target/DependencyCheck-Report.xml' prior to test."); } } - executeTarget("test.filelist"); + buildFileRule.executeTarget("test.filelist"); assertTrue("DependencyCheck report was not generated", report.exists()); } @@ -100,7 +107,7 @@ public class DependencyCheckTaskTest extends BuildFileTest { throw new Exception("Unable to delete 'target/DependencyCheck-Vulnerability.html' prior to test."); } } - executeTarget("test.dirset"); + buildFileRule.executeTarget("test.dirset"); assertTrue("DependencyCheck report was not generated", report.exists()); } @@ -109,7 +116,7 @@ public class DependencyCheckTaskTest extends BuildFileTest { */ @Test public void testGetFailBuildOnCVSS() { - expectBuildException("failCVSS", "asdfasdfscore"); - System.out.println(this.getOutput()); + expectedException.expect(BuildException.class); + buildFileRule.executeTarget("failCVSS"); } } diff --git a/pom.xml b/pom.xml index 3e6f40bfe..4d3cf181e 100644 --- a/pom.xml +++ b/pom.xml @@ -359,6 +359,16 @@ Copyright (c) 2012 - Jeremy Long 4.12 test + + org.apache.ant + ant + 1.9.5 + + + org.apache.ant + ant-testutil + 1.9.5 + org.hamcrest hamcrest-core