Add default-value getProperty convenience variants

Issue: SPR-8322
This commit is contained in:
Chris Beams
2011-05-11 06:09:06 +00:00
parent 693204aef8
commit dc2d5c107f
4 changed files with 62 additions and 3 deletions

View File

@@ -65,6 +65,13 @@ public class PropertySourcesPropertyResolverTests {
assertThat(propertyResolver.getProperty("foo"), is("bar"));
}
@Test
public void getProperty_withDefaultValue() {
assertThat(propertyResolver.getProperty("foo", "myDefault"), is("myDefault"));
testProperties.put("foo", "bar");
assertThat(propertyResolver.getProperty("foo"), is("bar"));
}
@Test
public void getProperty_propertySourceSearchOrderIsFIFO() {
MutablePropertySources sources = new MutablePropertySources();
@@ -86,6 +93,13 @@ public class PropertySourcesPropertyResolverTests {
assertThat(propertyResolver.getProperty("foo"), nullValue());
}
@Test
public void getProperty_withTargetType_andDefaultValue() {
assertThat(propertyResolver.getProperty("foo", Integer.class, 42), equalTo(42));
testProperties.put("foo", 13);
assertThat(propertyResolver.getProperty("foo", Integer.class, 42), equalTo(13));
}
@Test
public void getProperty_withStringArrayConversion() {
testProperties.put("foo", "bar,baz");
@@ -197,7 +211,7 @@ public class PropertySourcesPropertyResolverTests {
}
@Test
public void resolvePlaceholders_withDefault() {
public void resolvePlaceholders_withDefaultValue() {
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new MockPropertySource().withProperty("key", "value"));
PropertyResolver resolver = new PropertySourcesPropertyResolver(propertySources);
@@ -227,7 +241,7 @@ public class PropertySourcesPropertyResolverTests {
}
@Test
public void resolveRequiredPlaceholders_withDefault() {
public void resolveRequiredPlaceholders_withDefaultValue() {
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new MockPropertySource().withProperty("key", "value"));
PropertyResolver resolver = new PropertySourcesPropertyResolver(propertySources);