mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-14 07:43:40 +01:00
Added extra setters with null and empty checks.
This commit is contained in:
@@ -444,6 +444,30 @@ public final class Settings {
|
||||
LOGGER.debug("Setting: {}='{}'", key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a property value only if the value is not null.
|
||||
*
|
||||
* @param key the key for the property
|
||||
* @param value the value for the property
|
||||
*/
|
||||
public static void setStringIfNotNull(String key, String value) {
|
||||
if (null != value) {
|
||||
setString(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a property value only if the value is not null and not empty.
|
||||
*
|
||||
* @param key the key for the property
|
||||
* @param value the value for the property
|
||||
*/
|
||||
public static void setStringIfNotEmpty(String key, String value) {
|
||||
if (null != value && !value.isEmpty()) {
|
||||
setString(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a property value.
|
||||
*
|
||||
@@ -454,6 +478,18 @@ public final class Settings {
|
||||
setString(key, Boolean.toString(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a property value only if the value is not null.
|
||||
*
|
||||
* @param key the key for the property
|
||||
* @param value the value for the property
|
||||
*/
|
||||
public static void setBooleanIfNotNull(String key, Boolean value) {
|
||||
if (null != value) {
|
||||
setBoolean(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a property value.
|
||||
*
|
||||
@@ -465,6 +501,18 @@ public final class Settings {
|
||||
LOGGER.debug("Setting: {}='{}'", key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a property value only if the value is not null.
|
||||
*
|
||||
* @param key the key for the property
|
||||
* @param value the value for the property
|
||||
*/
|
||||
public static void setIntIfNotNull(String key, Integer value) {
|
||||
if (null != value) {
|
||||
setInt(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges a new properties file into the current properties. This method allows for the loading of a user provided properties
|
||||
* file.<br/><br/>
|
||||
|
||||
@@ -77,6 +77,32 @@ public class SettingsTest extends BaseTest {
|
||||
Assert.assertEquals(expResults, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of setStringIfNotNull method, of class Settings.
|
||||
*/
|
||||
@Test
|
||||
public void testSetStringIfNotNull() {
|
||||
String key = "nullableProperty";
|
||||
String value = "someValue";
|
||||
Settings.setString(key, value);
|
||||
Settings.setStringIfNotNull(key, null); // NO-OP
|
||||
String expResults = Settings.getString(key);
|
||||
Assert.assertEquals(expResults, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of setStringIfNotNull method, of class Settings.
|
||||
*/
|
||||
@Test
|
||||
public void testSetStringIfNotEmpty() {
|
||||
String key = "optionalProperty";
|
||||
String value = "someValue";
|
||||
Settings.setString(key, value);
|
||||
Settings.setStringIfNotEmpty(key, ""); // NO-OP
|
||||
String expResults = Settings.getString(key);
|
||||
Assert.assertEquals(expResults, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getString method, of class Settings.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user