17
17
*/
18
18
package org .owasp .dependencycheck .taskdefs ;
19
19
20
- import java .io .File ;
21
-
22
20
import org .apache .tools .ant .BuildException ;
23
21
import org .apache .tools .ant .BuildFileRule ;
24
22
import 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 ;
29
26
import org .owasp .dependencycheck .BaseDBTestCase ;
30
27
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 ;
32
32
33
33
/**
34
34
*
35
35
* @author Jeremy Long
36
36
*/
37
- public class DependencyCheckTaskIT extends BaseDBTestCase {
37
+ class DependencyCheckTaskIT extends BaseDBTestCase {
38
38
39
- @ Rule
40
- public final BuildFileRule buildFileRule = new BuildFileRule ();
39
+ private final BuildFileRule buildFileRule = new BuildFileRule ();
41
40
42
- @ Before
41
+ @ BeforeEach
43
42
@ Override
44
43
public void setUp () throws Exception {
45
44
super .setUp ();
46
45
final String buildFile = this .getClass ().getClassLoader ().getResource ("build.xml" ).getPath ();
47
46
buildFileRule .configureProject (buildFile , LogLevel .VERBOSE .getLevel ());
48
47
}
49
48
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
+
50
60
/**
51
61
* Test of addFileSet method, of class DependencyCheckTask.
52
62
*/
53
63
@ Test
54
- public void testAddFileSet () throws Exception {
64
+ void testAddFileSet () throws Exception {
55
65
File report = new File ("target/dependency-check-report.html" );
56
66
if (report .exists () && !report .delete ()) {
57
67
throw new Exception ("Unable to delete 'target/dependency-check-report.html' prior to test." );
58
68
}
59
69
buildFileRule .executeTarget ("test.fileset" );
60
- assertTrue ("DependencyCheck report was not generated" , report . exists () );
70
+ assertTrue (report . exists (), "DependencyCheck report was not generated" );
61
71
}
62
72
63
73
/**
@@ -66,7 +76,7 @@ public void testAddFileSet() throws Exception {
66
76
* @throws Exception
67
77
*/
68
78
@ Test
69
- public void testAddFileList () throws Exception {
79
+ void testAddFileList () throws Exception {
70
80
File report = new File ("target/dependency-check-report.xml" );
71
81
if (report .exists ()) {
72
82
if (!report .delete ()) {
@@ -75,7 +85,7 @@ public void testAddFileList() throws Exception {
75
85
}
76
86
buildFileRule .executeTarget ("test.filelist" );
77
87
78
- assertTrue ("DependencyCheck report was not generated" , report . exists () );
88
+ assertTrue (report . exists (), "DependencyCheck report was not generated" );
79
89
}
80
90
81
91
/**
@@ -84,19 +94,19 @@ public void testAddFileList() throws Exception {
84
94
* @throws Exception
85
95
*/
86
96
@ Test
87
- public void testAddDirSet () throws Exception {
97
+ void testAddDirSet () throws Exception {
88
98
File report = new File ("target/dependency-check-report.csv" );
89
99
if (report .exists ()) {
90
100
if (!report .delete ()) {
91
101
throw new Exception ("Unable to delete 'target/DependencyCheck-Vulnerability.html' prior to test." );
92
102
}
93
103
}
94
104
buildFileRule .executeTarget ("test.dirset" );
95
- assertTrue ("DependencyCheck report was not generated" , report . exists () );
105
+ assertTrue (report . exists (), "DependencyCheck report was not generated" );
96
106
}
97
107
98
108
@ Test
99
- public void testNestedReportFormat () throws Exception {
109
+ void testNestedReportFormat () throws Exception {
100
110
File reportHTML = new File ("target/dependency-check-report.html" );
101
111
File reportCSV = new File ("target/dependency-check-report.csv" );
102
112
if (reportCSV .exists ()) {
@@ -110,38 +120,37 @@ public void testNestedReportFormat() throws Exception {
110
120
}
111
121
}
112
122
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" );
115
125
}
116
126
117
127
@ 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 ());
125
134
}
126
135
127
136
/**
128
137
* Test of getFailBuildOnCVSS method, of class DependencyCheckTask.
129
138
*/
130
139
@ 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" ));
133
142
134
143
String expectedMessage = String .format ("One or more dependencies were identified with vulnerabilities that "
135
144
+ "have a CVSS score greater than or equal to '%.1f':" , 3.0f );
136
145
137
- Assert . assertTrue (exception .getMessage ().contains (expectedMessage ));
146
+ assertTrue (exception .getMessage ().contains (expectedMessage ));
138
147
}
139
148
140
149
/**
141
150
* Test the DependencyCheckTask where a CVE is suppressed.
142
151
*/
143
152
@ Test
144
- public void testSuppressingCVE () {
153
+ void testSuppressingCVE () {
145
154
// GIVEN an ant task with a vulnerability
146
155
final String antTaskName = "suppression" ;
147
156
@@ -157,46 +166,46 @@ public void testSuppressingCVE() {
157
166
158
167
// THEN the ant task executed without error
159
168
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" );
161
170
}
162
171
163
172
/**
164
173
* Test the DependencyCheckTask deprecated suppression property throws an
165
174
* exception with a warning.
166
175
*/
167
176
@ Test
168
- public void testSuppressingSingle () {
177
+ void testSuppressingSingle () {
169
178
// GIVEN an ant task with a vulnerability using the legacy property
170
179
final String antTaskName = "suppression-single" ;
171
180
// WHEN executing the ant task
172
181
buildFileRule .executeTarget (antTaskName );
173
182
174
183
// THEN the ant task executed without error
175
184
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" );
177
186
}
178
187
179
188
/**
180
189
* Test the DependencyCheckTask deprecated suppression property throws an
181
190
* exception with a warning.
182
191
*/
183
192
@ Test
184
- public void testSuppressingMultiple () {
193
+ void testSuppressingMultiple () {
185
194
// GIVEN an ant task with a vulnerability using multiple was to configure the suppression file
186
195
final String antTaskName = "suppression-multiple" ;
187
196
// WHEN executing the ant task
188
197
buildFileRule .executeTarget (antTaskName );
189
198
190
199
// THEN the ant task executed without error
191
200
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" );
193
202
}
194
203
195
204
/**
196
205
* Test the DependencyCheckTask retireJS configuration.
197
206
*/
198
207
@ Test
199
- public void testRetireJsConfiguration () {
208
+ void testRetireJsConfiguration () {
200
209
// GIVEN an ant task with a vulnerability using multiple was to configure the suppression file
201
210
final String antTaskName = "retireJS" ;
202
211
@@ -205,6 +214,6 @@ public void testRetireJsConfiguration() {
205
214
206
215
// THEN the ant task executed without error
207
216
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" );
209
218
}
210
219
}
0 commit comments