Skip to content

Commit

Permalink
Fixed apache#1772
Browse files Browse the repository at this point in the history
  • Loading branch information
mercyblitz committed May 10, 2018
1 parent 37293eb commit 31acca8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ public static Map<String, String> getSubProperties(Iterable<PropertySource<?>> p
for (String name : ((EnumerablePropertySource<?>) source).getPropertyNames()) {
if (name.startsWith(normalizedPrefix)) {
String subName = name.substring(normalizedPrefix.length());
Object value = source.getProperty(name);
subProperties.put(subName, String.valueOf(value));
if (!subProperties.containsKey(subName)) {
Object value = source.getProperty(name);
subProperties.put(subName, String.valueOf(value));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,19 @@ public void testGetSubProperties() {
source.put(KEY_PREFIX + "." + KEY_AGE, 31);

Map<String, Object> expected = new HashMap<String, Object>();
expected.put(KEY_NAME, "Mercy");
expected.put(KEY_NAME, "mercyblitz");
expected.put(KEY_AGE, "31");


Map<String, Object> source2 = new HashMap<String, Object>();

source2.put("user.name", "mercyblitz");

MapPropertySource propertySource2 = new MapPropertySource("test2", source2);

propertySources.addFirst(propertySource2);


result = PropertySourcesUtils.getSubProperties(propertySources, KEY_PREFIX);
Assert.assertEquals(expected, result);

Expand Down

0 comments on commit 31acca8

Please sign in to comment.