Skip to content

Commit 2408e96

Browse files
Migrate tests to JUnit5 (cli)
* Migrate annotations and imports * Migrate assertions * Remove public visibility for test classes and methods * Minor code cleanup
1 parent b4a8eaf commit 2408e96

File tree

3 files changed

+114
-111
lines changed

3 files changed

+114
-111
lines changed

cli/src/test/java/org/owasp/dependencycheck/AppTest.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,34 @@
1717
*/
1818
package org.owasp.dependencycheck;
1919

20-
import static org.hamcrest.core.Is.is;
21-
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertTrue;
20+
import org.apache.commons.cli.ParseException;
21+
import org.apache.commons.cli.UnrecognizedOptionException;
22+
import org.junit.jupiter.api.Test;
23+
import org.owasp.dependencycheck.utils.InvalidSettingException;
24+
import org.owasp.dependencycheck.utils.Settings;
25+
import org.owasp.dependencycheck.utils.Settings.KEYS;
2326

2427
import java.io.File;
2528
import java.io.FileNotFoundException;
26-
import java.net.URISyntaxException;
2729
import java.util.HashMap;
2830
import java.util.Map;
2931

30-
import org.apache.commons.cli.ParseException;
31-
import org.apache.commons.cli.UnrecognizedOptionException;
3232
import static org.hamcrest.MatcherAssert.assertThat;
33-
import org.junit.Assert;
34-
import org.junit.Test;
35-
import org.owasp.dependencycheck.utils.InvalidSettingException;
36-
import org.owasp.dependencycheck.utils.Settings;
37-
import org.owasp.dependencycheck.utils.Settings.KEYS;
33+
import static org.hamcrest.core.Is.is;
34+
import static org.junit.jupiter.api.Assertions.assertFalse;
35+
import static org.junit.jupiter.api.Assertions.assertThrows;
36+
import static org.junit.jupiter.api.Assertions.assertTrue;
3837

3938
/**
4039
* Tests for the {@link AppTest} class.
4140
*/
42-
public class AppTest extends BaseTest {
41+
class AppTest extends BaseTest {
4342

4443
/**
4544
* Test of ensureCanonicalPath method, of class App.
4645
*/
4746
@Test
48-
public void testEnsureCanonicalPath() {
47+
void testEnsureCanonicalPath() {
4948
String file = "../*.jar";
5049
App instance = new App(getSettings());
5150
String result = instance.ensureCanonicalPath(file);
@@ -55,7 +54,7 @@ public void testEnsureCanonicalPath() {
5554
file = "../some/skip/../path/file.txt";
5655
String expResult = "/some/path/file.txt";
5756
result = instance.ensureCanonicalPath(file);
58-
assertTrue("result=" + result, result.endsWith(expResult));
57+
assertTrue(result.endsWith(expResult), "result=" + result);
5958
}
6059

6160
/**
@@ -65,7 +64,7 @@ public void testEnsureCanonicalPath() {
6564
* @throws Exception the unexpected {@link Exception}.
6665
*/
6766
@Test
68-
public void testPopulateSettings() throws Exception {
67+
void testPopulateSettings() throws Exception {
6968
File prop = new File(this.getClass().getClassLoader().getResource("sample.properties").toURI().getPath());
7069
String[] args = {"-P", prop.getAbsolutePath()};
7170
Map<String, Boolean> expected = new HashMap<>();
@@ -115,13 +114,12 @@ public void testPopulateSettings() throws Exception {
115114
* Assert that an {@link UnrecognizedOptionException} is thrown when a
116115
* property that is not supported is specified on the CLI.
117116
*
118-
* @throws Exception the unexpected {@link Exception}.
119117
*/
120118
@Test
121-
public void testPopulateSettingsException() throws Exception {
119+
void testPopulateSettingsException() {
122120
String[] args = {"-invalidPROPERTY"};
123-
Exception exception = Assert.assertThrows(UnrecognizedOptionException.class, () -> testBooleanProperties(args, null));
124-
Assert.assertTrue(exception.getMessage().contains("Unrecognized option: -invalidPROPERTY"));
121+
Exception exception = assertThrows(UnrecognizedOptionException.class, () -> testBooleanProperties(args, null));
122+
assertTrue(exception.getMessage().contains("Unrecognized option: -invalidPROPERTY"));
125123
}
126124

127125
/**
@@ -130,7 +128,7 @@ public void testPopulateSettingsException() throws Exception {
130128
* @throws Exception the unexpected {@link Exception}.
131129
*/
132130
@Test
133-
public void testPopulatingSuppressionSettingsWithASingleFile() throws Exception {
131+
void testPopulatingSuppressionSettingsWithASingleFile() throws Exception {
134132
// GIVEN CLI properties with the mandatory arguments
135133
File prop = new File(this.getClass().getClassLoader().getResource("sample.properties").toURI().getPath());
136134

@@ -154,7 +152,7 @@ public void testPopulatingSuppressionSettingsWithASingleFile() throws Exception
154152
* @throws Exception the unexpected {@link Exception}.
155153
*/
156154
@Test
157-
public void testPopulatingSuppressionSettingsWithMultipleFiles() throws Exception {
155+
void testPopulatingSuppressionSettingsWithMultipleFiles() throws Exception {
158156
// GIVEN CLI properties with the mandatory arguments
159157
File prop = new File(this.getClass().getClassLoader().getResource("sample.properties").toURI().getPath());
160158

@@ -172,7 +170,7 @@ public void testPopulatingSuppressionSettingsWithMultipleFiles() throws Exceptio
172170
}
173171

174172

175-
private boolean testBooleanProperties(String[] args, Map<String, Boolean> expected) throws URISyntaxException, FileNotFoundException, ParseException, InvalidSettingException {
173+
private boolean testBooleanProperties(String[] args, Map<String, Boolean> expected) throws FileNotFoundException, ParseException, InvalidSettingException {
176174
this.reloadSettings();
177175
final CliParser cli = new CliParser(getSettings());
178176
cli.parse(args);

cli/src/test/java/org/owasp/dependencycheck/BaseTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package org.owasp.dependencycheck;
1717

18-
import org.junit.After;
19-
import org.junit.Before;
18+
import org.junit.jupiter.api.AfterEach;
19+
import org.junit.jupiter.api.BeforeEach;
2020
import org.owasp.dependencycheck.utils.Settings;
2121

2222
/**
@@ -33,15 +33,15 @@ public abstract class BaseTest {
3333
/**
3434
* Initialize the {@link Settings}.
3535
*/
36-
@Before
36+
@BeforeEach
3737
public void setUp() {
3838
settings = new Settings();
3939
}
4040

4141
/**
4242
* Clean the {@link Settings}.
4343
*/
44-
@After
44+
@AfterEach
4545
public void tearDown() {
4646
settings.cleanup(true);
4747
}

0 commit comments

Comments
 (0)