Merge pull request #1087 from PHJ2000/fix-properties-defaults-only
Fix Property enumeration without local entries
This commit is contained in:
@@ -30,7 +30,7 @@ public class Property {
|
|||||||
// can't use the new constructor for Android support
|
// can't use the new constructor for Android support
|
||||||
// JSONObject jo = new JSONObject(properties == null ? 0 : properties.size());
|
// JSONObject jo = new JSONObject(properties == null ? 0 : properties.size());
|
||||||
JSONObject jo = new JSONObject();
|
JSONObject jo = new JSONObject();
|
||||||
if (properties != null && !properties.isEmpty()) {
|
if (properties != null) {
|
||||||
Enumeration<?> enumProperties = properties.propertyNames();
|
Enumeration<?> enumProperties = properties.propertyNames();
|
||||||
while(enumProperties.hasMoreElements()) {
|
while(enumProperties.hasMoreElements()) {
|
||||||
String name = (String)enumProperties.nextElement();
|
String name = (String)enumProperties.nextElement();
|
||||||
|
|||||||
@@ -17,6 +17,33 @@ import org.junit.Test;
|
|||||||
*/
|
*/
|
||||||
public class PropertyTest {
|
public class PropertyTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldIncludeInheritedPropertiesWithoutLocalEntries() {
|
||||||
|
Properties defaults = new Properties();
|
||||||
|
defaults.setProperty("timeout", "30");
|
||||||
|
Properties properties = new Properties(new Properties(defaults));
|
||||||
|
|
||||||
|
JSONObject jsonObject = Property.toJSONObject(properties);
|
||||||
|
|
||||||
|
assertEquals(1, jsonObject.length());
|
||||||
|
assertEquals("30", jsonObject.getString("timeout"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldPreferLocalPropertiesOverDefaults() {
|
||||||
|
Properties defaults = new Properties();
|
||||||
|
defaults.setProperty("timeout", "30");
|
||||||
|
defaults.setProperty("host", "localhost");
|
||||||
|
Properties properties = new Properties(defaults);
|
||||||
|
properties.setProperty("timeout", "60");
|
||||||
|
|
||||||
|
JSONObject jsonObject = Property.toJSONObject(properties);
|
||||||
|
|
||||||
|
assertEquals(2, jsonObject.length());
|
||||||
|
assertEquals("60", jsonObject.getString("timeout"));
|
||||||
|
assertEquals("localhost", jsonObject.getString("host"));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSONObject from null properties object should
|
* JSONObject from null properties object should
|
||||||
* result in an empty JSONObject.
|
* result in an empty JSONObject.
|
||||||
@@ -99,4 +126,4 @@ public class PropertyTest {
|
|||||||
assertTrue("property objects should match",
|
assertTrue("property objects should match",
|
||||||
properties.equals(jsonProperties));
|
properties.equals(jsonProperties));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user