@Override public <T> T getProperty(String key, Class<T> targetType, T defaultValue) { return this.propertyResolver.getProperty(key, targetType, defaultValue); }
@Override public String getProperty(String key, String defaultValue) { return this.propertyResolver.getProperty(key, defaultValue); }
@Override @Nullable public String getProperty(String key) { return this.propertyResolver.getProperty(key); }
@Override @Nullable public <T> T getProperty(String key, Class<T> targetType) { return this.propertyResolver.getProperty(key, targetType); }
@Override public String getProperty(String key, String defaultValue) { return this.propertyResolver.getProperty(key, defaultValue); }
@Override public <T> T getProperty(String key, Class<T> targetType, T defaultValue) { return this.propertyResolver.getProperty(key, targetType, defaultValue); }
@Override @Nullable public String getProperty(String key) { return this.propertyResolver.getProperty(key); }
@Override @Nullable public <T> T getProperty(String key, Class<T> targetType) { return this.propertyResolver.getProperty(key, targetType); }
@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_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() { assertThat(propertyResolver.getProperty("foo"), nullValue()); testProperties.put("foo", "bar"); assertThat(propertyResolver.getProperty("foo"), is("bar")); }
@Test public void getProperty_withStringArrayConversion() { testProperties.put("foo", "bar,baz"); assertThat(propertyResolver.getProperty("foo", String[].class), equalTo(new String[] { "bar", "baz" })); }
@Test public void getProperty_withNonConvertibleTargetType() { testProperties.put("foo", "bar"); class TestType { } try { propertyResolver.getProperty("foo", TestType.class); fail("Expected ConverterNotFoundException due to non-convertible types"); } catch (ConverterNotFoundException ex) { // expected } }
@Test public void getProperty_withExplicitNullValue() { // java.util.Properties does not allow null values (because Hashtable does not) Map<String, Object> nullableProperties = new HashMap<>(); propertySources.addLast(new MapPropertySource("nullableProperties", nullableProperties)); nullableProperties.put("foo", null); assertThat(propertyResolver.getProperty("foo"), nullValue()); }
); ConfigurablePropertyResolver pr = new PropertySourcesPropertyResolver(ps); assertThat(pr.getProperty("p1"), equalTo("v1")); assertThat(pr.getProperty("p2"), equalTo("v2")); assertThat(pr.getProperty("p3"), equalTo("v1:v2")); assertThat(pr.getProperty("p4"), equalTo("v1:v2")); try { pr.getProperty("p5"); "Could not resolve placeholder 'bogus' in value \"${p1}:${p2}:${bogus}\"")); assertThat(pr.getProperty("p6"), equalTo("v1:v2:def")); try { pr.getProperty("pL");
); ConfigurablePropertyResolver pr = new PropertySourcesPropertyResolver(ps); assertThat(pr.getProperty("p1"), equalTo("v1")); assertThat(pr.getProperty("p2"), equalTo("v2")); assertThat(pr.getProperty("p3"), equalTo("v1:v2:def")); pr.getProperty("p4"); assertThat(pr.getProperty("p4"), equalTo("v1:v2:${bogus}"));
@Test public void getPropertySources_replacePropertySource() { propertySources = new MutablePropertySources(); propertyResolver = new PropertySourcesPropertyResolver(propertySources); propertySources.addLast(new MockPropertySource("local").withProperty("foo", "localValue")); propertySources.addLast(new MockPropertySource("system").withProperty("foo", "systemValue")); // 'local' was added first so has precedence assertThat(propertyResolver.getProperty("foo"), equalTo("localValue")); // replace 'local' with new property source propertySources.replace("local", new MockPropertySource("new").withProperty("foo", "newValue")); // 'system' now has precedence assertThat(propertyResolver.getProperty("foo"), equalTo("newValue")); assertThat(propertySources.size(), is(2)); }
public <T> T getProperty(String key, Class<T> targetType, T defaultValue) { return this.propertyResolver.getProperty(key, targetType, defaultValue); };
public String getProperty(String key) { return this.propertyResolver.getProperty(key); }
public <T> T getProperty(String key, Class<T> targetType) { return this.propertyResolver.getProperty(key, targetType); }