mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-18 07:14:09 +01:00
minor formating updates
This commit is contained in:
@@ -44,7 +44,9 @@ import org.owasp.dependencycheck.utils.Settings.KEYS;
|
|||||||
*/
|
*/
|
||||||
public class AppTest {
|
public class AppTest {
|
||||||
|
|
||||||
/** Test rule for asserting exceptions and their contents. */
|
/**
|
||||||
|
* Test rule for asserting exceptions and their contents.
|
||||||
|
*/
|
||||||
@Rule
|
@Rule
|
||||||
public ExpectedException expectedException = ExpectedException.none();
|
public ExpectedException expectedException = ExpectedException.none();
|
||||||
|
|
||||||
@@ -82,65 +84,67 @@ public class AppTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert that boolean properties can be set on the CLI and parsed into the {@link Settings} singleton.
|
* Assert that boolean properties can be set on the CLI and parsed into the
|
||||||
|
* {@link Settings} singleton.
|
||||||
*
|
*
|
||||||
* @throws Exception the unexpected {@link Exception}.
|
* @throws Exception the unexpected {@link Exception}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testPopulateSettings() throws Exception {
|
public void testPopulateSettings() throws Exception {
|
||||||
File prop = new File(this.getClass().getClassLoader().getResource("sample.properties").toURI().getPath());
|
File prop = new File(this.getClass().getClassLoader().getResource("sample.properties").toURI().getPath());
|
||||||
String[] args = { "-P", prop.getAbsolutePath() };
|
String[] args = {"-P", prop.getAbsolutePath()};
|
||||||
Map<String, Boolean> expected = new HashMap<>();
|
Map<String, Boolean> expected = new HashMap<>();
|
||||||
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE);
|
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE);
|
||||||
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.TRUE);
|
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.TRUE);
|
||||||
|
|
||||||
assertTrue(testBooleanProperties(args, expected));
|
assertTrue(testBooleanProperties(args, expected));
|
||||||
|
|
||||||
String[] args2 = { "-n" };
|
String[] args2 = {"-n"};
|
||||||
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE);
|
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE);
|
||||||
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.TRUE);
|
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.TRUE);
|
||||||
assertTrue(testBooleanProperties(args2, expected));
|
assertTrue(testBooleanProperties(args2, expected));
|
||||||
|
|
||||||
String[] args3 = { "-h" };
|
String[] args3 = {"-h"};
|
||||||
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.TRUE);
|
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.TRUE);
|
||||||
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.TRUE);
|
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.TRUE);
|
||||||
assertTrue(testBooleanProperties(args3, expected));
|
assertTrue(testBooleanProperties(args3, expected));
|
||||||
|
|
||||||
String[] args4 = { "--disableArchive" };
|
String[] args4 = {"--disableArchive"};
|
||||||
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.TRUE);
|
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.TRUE);
|
||||||
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.FALSE);
|
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.FALSE);
|
||||||
assertTrue(testBooleanProperties(args4, expected));
|
assertTrue(testBooleanProperties(args4, expected));
|
||||||
|
|
||||||
String[] args5 = { "-P", prop.getAbsolutePath(), "--disableArchive" };
|
String[] args5 = {"-P", prop.getAbsolutePath(), "--disableArchive"};
|
||||||
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE);
|
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE);
|
||||||
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.FALSE);
|
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.FALSE);
|
||||||
assertTrue(testBooleanProperties(args5, expected));
|
assertTrue(testBooleanProperties(args5, expected));
|
||||||
|
|
||||||
prop = new File(this.getClass().getClassLoader().getResource("sample2.properties").toURI().getPath());
|
prop = new File(this.getClass().getClassLoader().getResource("sample2.properties").toURI().getPath());
|
||||||
String[] args6 = { "-P", prop.getAbsolutePath(), "--disableArchive" };
|
String[] args6 = {"-P", prop.getAbsolutePath(), "--disableArchive"};
|
||||||
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.TRUE);
|
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.TRUE);
|
||||||
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.FALSE);
|
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.FALSE);
|
||||||
assertTrue(testBooleanProperties(args6, expected));
|
assertTrue(testBooleanProperties(args6, expected));
|
||||||
|
|
||||||
String[] args7 = { "-P", prop.getAbsolutePath(), "--noupdate" };
|
String[] args7 = {"-P", prop.getAbsolutePath(), "--noupdate"};
|
||||||
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE);
|
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE);
|
||||||
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.FALSE);
|
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.FALSE);
|
||||||
assertTrue(testBooleanProperties(args7, expected));
|
assertTrue(testBooleanProperties(args7, expected));
|
||||||
|
|
||||||
String[] args8 = { "-P", prop.getAbsolutePath(), "--noupdate", "--disableArchive" };
|
String[] args8 = {"-P", prop.getAbsolutePath(), "--noupdate", "--disableArchive"};
|
||||||
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE);
|
expected.put(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE);
|
||||||
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.FALSE);
|
expected.put(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, Boolean.FALSE);
|
||||||
assertTrue(testBooleanProperties(args8, expected));
|
assertTrue(testBooleanProperties(args8, expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert that an {@link UnrecognizedOptionException} is thrown when a property that is not supported is specified on the CLI.
|
* Assert that an {@link UnrecognizedOptionException} is thrown when a
|
||||||
|
* property that is not supported is specified on the CLI.
|
||||||
*
|
*
|
||||||
* @throws Exception the unexpected {@link Exception}.
|
* @throws Exception the unexpected {@link Exception}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testPopulateSettingsException() throws Exception {
|
public void testPopulateSettingsException() throws Exception {
|
||||||
String[] args = { "-invalidPROPERTY" };
|
String[] args = {"-invalidPROPERTY"};
|
||||||
|
|
||||||
expectedException.expect(UnrecognizedOptionException.class);
|
expectedException.expect(UnrecognizedOptionException.class);
|
||||||
expectedException.expectMessage("Unrecognized option: -invalidPROPERTY");
|
expectedException.expectMessage("Unrecognized option: -invalidPROPERTY");
|
||||||
@@ -158,7 +162,7 @@ public class AppTest {
|
|||||||
File prop = new File(this.getClass().getClassLoader().getResource("sample.properties").toURI().getPath());
|
File prop = new File(this.getClass().getClassLoader().getResource("sample.properties").toURI().getPath());
|
||||||
|
|
||||||
// AND a single suppression file
|
// AND a single suppression file
|
||||||
String[] args = { "-P", prop.getAbsolutePath(), "--suppression", "another-file.xml" };
|
String[] args = {"-P", prop.getAbsolutePath(), "--suppression", "another-file.xml"};
|
||||||
|
|
||||||
// WHEN parsing the CLI arguments
|
// WHEN parsing the CLI arguments
|
||||||
final CliParser cli = new CliParser();
|
final CliParser cli = new CliParser();
|
||||||
@@ -181,7 +185,7 @@ public class AppTest {
|
|||||||
File prop = new File(this.getClass().getClassLoader().getResource("sample.properties").toURI().getPath());
|
File prop = new File(this.getClass().getClassLoader().getResource("sample.properties").toURI().getPath());
|
||||||
|
|
||||||
// AND a single suppression file
|
// AND a single suppression file
|
||||||
String[] args = { "-P", prop.getAbsolutePath(), "--suppression", "first-file.xml", "another-file.xml" };
|
String[] args = {"-P", prop.getAbsolutePath(), "--suppression", "first-file.xml", "another-file.xml"};
|
||||||
|
|
||||||
// WHEN parsing the CLI arguments
|
// WHEN parsing the CLI arguments
|
||||||
final CliParser cli = new CliParser();
|
final CliParser cli = new CliParser();
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
Copyright (c) 2013 Jeremy Long. All Rights Reserved.
|
Copyright (c) 2017 Jeremy Long. All Rights Reserved.
|
||||||
-->
|
-->
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -246,7 +246,8 @@ public class SettingsTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert {@link Settings#getArray(String)} from a delimited string returns multiple values in an array.
|
* Assert {@link Settings#getArray(String)} from a delimited string returns
|
||||||
|
* multiple values in an array.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetArrayFromADelimitedString() {
|
public void testGetArrayFromADelimitedString() {
|
||||||
@@ -265,7 +266,8 @@ public class SettingsTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert {@link Settings#getArray(String)} returns {@code null} if the property is not set.
|
* Assert {@link Settings#getArray(String)} returns {@code null} if the
|
||||||
|
* property is not set.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetArrayWhereThePropertyIsNotSet() {
|
public void testGetArrayWhereThePropertyIsNotSet() {
|
||||||
@@ -277,7 +279,8 @@ public class SettingsTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert {@link Settings#setArrayIfNotEmpty(String, String[])} with an empty array is ignored.
|
* Assert {@link Settings#setArrayIfNotEmpty(String, String[])} with an
|
||||||
|
* empty array is ignored.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetArrayNotEmptyIgnoresAnEmptyArray() {
|
public void testSetArrayNotEmptyIgnoresAnEmptyArray() {
|
||||||
@@ -292,7 +295,8 @@ public class SettingsTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert {@link Settings#setArrayIfNotEmpty(String, String[])} with a null array is ignored.
|
* Assert {@link Settings#setArrayIfNotEmpty(String, String[])} with a null
|
||||||
|
* array is ignored.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetArrayNotEmptyIgnoresAnNullArray() {
|
public void testSetArrayNotEmptyIgnoresAnNullArray() {
|
||||||
@@ -307,12 +311,13 @@ public class SettingsTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert {@link Settings#setArrayIfNotEmpty(String, String[])} with multiple values sets a delimited string.
|
* Assert {@link Settings#setArrayIfNotEmpty(String, String[])} with
|
||||||
|
* multiple values sets a delimited string.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetArrayNotEmptySetsADelimitedString() {
|
public void testSetArrayNotEmptySetsADelimitedString() {
|
||||||
// GIVEN an array with values
|
// GIVEN an array with values
|
||||||
final String[] array = { "value1", "value2" };
|
final String[] array = {"value1", "value2"};
|
||||||
|
|
||||||
// WHEN setting the array
|
// WHEN setting the array
|
||||||
Settings.setArrayIfNotEmpty("key", array);
|
Settings.setArrayIfNotEmpty("key", array);
|
||||||
@@ -322,12 +327,13 @@ public class SettingsTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert {@link Settings#setArrayIfNotEmpty(String, String[])} with a single values sets a string.
|
* Assert {@link Settings#setArrayIfNotEmpty(String, String[])} with a
|
||||||
|
* single values sets a string.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetArrayNotEmptyWithSingleValueSetsAString() {
|
public void testSetArrayNotEmptyWithSingleValueSetsAString() {
|
||||||
// GIVEN an array with a value
|
// GIVEN an array with a value
|
||||||
final String[] array = { "value1" };
|
final String[] array = {"value1"};
|
||||||
|
|
||||||
// WHEN setting the array
|
// WHEN setting the array
|
||||||
Settings.setArrayIfNotEmpty("key", array);
|
Settings.setArrayIfNotEmpty("key", array);
|
||||||
@@ -335,5 +341,4 @@ public class SettingsTest extends BaseTest {
|
|||||||
// THEN the property is set
|
// THEN the property is set
|
||||||
assertThat("Expected the property to be set", Settings.getString("key"), is("value1"));
|
assertThat("Expected the property to be set", Settings.getString("key"), is("value1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user