1717 */
1818package org .owasp .dependencycheck .taskdefs ;
1919
20- import java .io .File ;
21-
2220import org .apache .tools .ant .BuildException ;
2321import org .apache .tools .ant .BuildFileRule ;
2422import org .apache .tools .ant .types .LogLevel ;
25- import org .junit .Assert ;
26- import org .junit .Before ;
27- import org .junit .Rule ;
28- import org .junit .Test ;
23+ import org .junit .jupiter .api .AfterEach ;
24+ import org .junit .jupiter .api .BeforeEach ;
25+ import org .junit .jupiter .api .Test ;
2926import org .owasp .dependencycheck .BaseDBTestCase ;
3027
31- import static org .junit .Assert .assertTrue ;
28+ import java .io .File ;
29+
30+ import static org .junit .jupiter .api .Assertions .assertThrows ;
31+ import static org .junit .jupiter .api .Assertions .assertTrue ;
3232
3333/**
3434 *
3535 * @author Jeremy Long
3636 */
37- public class DependencyCheckTaskIT extends BaseDBTestCase {
37+ class DependencyCheckTaskIT extends BaseDBTestCase {
3838
39- @ Rule
40- public final BuildFileRule buildFileRule = new BuildFileRule ();
39+ private final BuildFileRule buildFileRule = new BuildFileRule ();
4140
42- @ Before
41+ @ BeforeEach
4342 @ Override
4443 public void setUp () throws Exception {
4544 super .setUp ();
4645 final String buildFile = this .getClass ().getClassLoader ().getResource ("build.xml" ).getPath ();
4746 buildFileRule .configureProject (buildFile , LogLevel .VERBOSE .getLevel ());
4847 }
4948
49+ @ AfterEach
50+ @ Override
51+ public void tearDown () throws Exception {
52+ if (buildFileRule .getProject () != null ) {
53+ if (this .buildFileRule .getProject ().getTargets ().containsKey ("tearDown" )) {
54+ this .buildFileRule .getProject ().executeTarget ("tearDown" );
55+ }
56+ }
57+ super .tearDown ();
58+ }
59+
5060 /**
5161 * Test of addFileSet method, of class DependencyCheckTask.
5262 */
5363 @ Test
54- public void testAddFileSet () throws Exception {
64+ void testAddFileSet () throws Exception {
5565 File report = new File ("target/dependency-check-report.html" );
5666 if (report .exists () && !report .delete ()) {
5767 throw new Exception ("Unable to delete 'target/dependency-check-report.html' prior to test." );
5868 }
5969 buildFileRule .executeTarget ("test.fileset" );
60- assertTrue ("DependencyCheck report was not generated" , report . exists () );
70+ assertTrue (report . exists (), "DependencyCheck report was not generated" );
6171 }
6272
6373 /**
@@ -66,7 +76,7 @@ public void testAddFileSet() throws Exception {
6676 * @throws Exception
6777 */
6878 @ Test
69- public void testAddFileList () throws Exception {
79+ void testAddFileList () throws Exception {
7080 File report = new File ("target/dependency-check-report.xml" );
7181 if (report .exists ()) {
7282 if (!report .delete ()) {
@@ -75,7 +85,7 @@ public void testAddFileList() throws Exception {
7585 }
7686 buildFileRule .executeTarget ("test.filelist" );
7787
78- assertTrue ("DependencyCheck report was not generated" , report . exists () );
88+ assertTrue (report . exists (), "DependencyCheck report was not generated" );
7989 }
8090
8191 /**
@@ -84,19 +94,19 @@ public void testAddFileList() throws Exception {
8494 * @throws Exception
8595 */
8696 @ Test
87- public void testAddDirSet () throws Exception {
97+ void testAddDirSet () throws Exception {
8898 File report = new File ("target/dependency-check-report.csv" );
8999 if (report .exists ()) {
90100 if (!report .delete ()) {
91101 throw new Exception ("Unable to delete 'target/DependencyCheck-Vulnerability.html' prior to test." );
92102 }
93103 }
94104 buildFileRule .executeTarget ("test.dirset" );
95- assertTrue ("DependencyCheck report was not generated" , report . exists () );
105+ assertTrue (report . exists (), "DependencyCheck report was not generated" );
96106 }
97107
98108 @ Test
99- public void testNestedReportFormat () throws Exception {
109+ void testNestedReportFormat () throws Exception {
100110 File reportHTML = new File ("target/dependency-check-report.html" );
101111 File reportCSV = new File ("target/dependency-check-report.csv" );
102112 if (reportCSV .exists ()) {
@@ -110,38 +120,37 @@ public void testNestedReportFormat() throws Exception {
110120 }
111121 }
112122 buildFileRule .executeTarget ("test.formatNested" );
113- assertTrue ("DependencyCheck CSV report was not generated" , reportCSV . exists () );
114- assertTrue ("DependencyCheck HTML report was not generated" , reportHTML . exists () );
123+ assertTrue (reportCSV . exists (), "DependencyCheck CSV report was not generated" );
124+ assertTrue (reportHTML . exists (), "DependencyCheck HTML report was not generated" );
115125 }
116126
117127 @ Test
118- public void testNestedBADReportFormat () throws Exception {
119- try {
120- buildFileRule .executeTarget ("test.formatBADNested" );
121- Assert .fail ("Should have had a buildExceotion for a bad format attribute" );
122- } catch (BuildException e ) {
123- assertTrue ("Message did not have BAD, unexpected exception: " + e .getMessage (), e .getMessage ().contains ("BAD is not a legal value for this attribute" ));
124- }
128+ void testNestedBADReportFormat () {
129+ BuildException e = assertThrows (BuildException .class ,
130+ () -> buildFileRule .executeTarget ("test.formatBADNested" ),
131+ "Should have had a buildException for a bad format attribute" );
132+ assertTrue (e .getMessage ().contains ("BAD is not a legal value for this attribute" ),
133+ "Message did not have BAD, unexpected exception: " + e .getMessage ());
125134 }
126135
127136 /**
128137 * Test of getFailBuildOnCVSS method, of class DependencyCheckTask.
129138 */
130139 @ Test
131- public void testGetFailBuildOnCVSS () {
132- Exception exception = Assert . assertThrows (BuildException .class , () -> buildFileRule .executeTarget ("failCVSS" ));
140+ void testGetFailBuildOnCVSS () {
141+ Exception exception = assertThrows (BuildException .class , () -> buildFileRule .executeTarget ("failCVSS" ));
133142
134143 String expectedMessage = String .format ("One or more dependencies were identified with vulnerabilities that "
135144 + "have a CVSS score greater than or equal to '%.1f':" , 3.0f );
136145
137- Assert . assertTrue (exception .getMessage ().contains (expectedMessage ));
146+ assertTrue (exception .getMessage ().contains (expectedMessage ));
138147 }
139148
140149 /**
141150 * Test the DependencyCheckTask where a CVE is suppressed.
142151 */
143152 @ Test
144- public void testSuppressingCVE () {
153+ void testSuppressingCVE () {
145154 // GIVEN an ant task with a vulnerability
146155 final String antTaskName = "suppression" ;
147156
@@ -157,46 +166,46 @@ public void testSuppressingCVE() {
157166
158167 // THEN the ant task executed without error
159168 final File report = new File ("target/suppression-report.html" );
160- assertTrue ("Expected the DependencyCheck report to be generated" , report . exists () );
169+ assertTrue (report . exists (), "Expected the DependencyCheck report to be generated" );
161170 }
162171
163172 /**
164173 * Test the DependencyCheckTask deprecated suppression property throws an
165174 * exception with a warning.
166175 */
167176 @ Test
168- public void testSuppressingSingle () {
177+ void testSuppressingSingle () {
169178 // GIVEN an ant task with a vulnerability using the legacy property
170179 final String antTaskName = "suppression-single" ;
171180 // WHEN executing the ant task
172181 buildFileRule .executeTarget (antTaskName );
173182
174183 // THEN the ant task executed without error
175184 final File report = new File ("target/suppression-single-report.html" );
176- assertTrue ("Expected the DependencyCheck report to be generated" , report . exists () );
185+ assertTrue (report . exists (), "Expected the DependencyCheck report to be generated" );
177186 }
178187
179188 /**
180189 * Test the DependencyCheckTask deprecated suppression property throws an
181190 * exception with a warning.
182191 */
183192 @ Test
184- public void testSuppressingMultiple () {
193+ void testSuppressingMultiple () {
185194 // GIVEN an ant task with a vulnerability using multiple was to configure the suppression file
186195 final String antTaskName = "suppression-multiple" ;
187196 // WHEN executing the ant task
188197 buildFileRule .executeTarget (antTaskName );
189198
190199 // THEN the ant task executed without error
191200 final File report = new File ("target/suppression-multiple-report.html" );
192- assertTrue ("Expected the DependencyCheck report to be generated" , report . exists () );
201+ assertTrue (report . exists (), "Expected the DependencyCheck report to be generated" );
193202 }
194203
195204 /**
196205 * Test the DependencyCheckTask retireJS configuration.
197206 */
198207 @ Test
199- public void testRetireJsConfiguration () {
208+ void testRetireJsConfiguration () {
200209 // GIVEN an ant task with a vulnerability using multiple was to configure the suppression file
201210 final String antTaskName = "retireJS" ;
202211
@@ -205,6 +214,6 @@ public void testRetireJsConfiguration() {
205214
206215 // THEN the ant task executed without error
207216 final File report = new File ("target/retirejs-report.html" );
208- assertTrue ("Expected the DependencyCheck report to be generated" , report . exists () );
217+ assertTrue (report . exists (), "Expected the DependencyCheck report to be generated" );
209218 }
210219}
0 commit comments