Commit 1abd0879 authored by Dave Syer's avatar Dave Syer

Add and fix tests for overridden bindings

The order of property values is only preserved if we check carefully
that each property is actually present in the source being inspected.

Fixes gh-3385
parent 43dc0c64
...@@ -153,6 +153,9 @@ public class PropertySourcesPropertyValues implements PropertyValues { ...@@ -153,6 +153,9 @@ public class PropertySourcesPropertyValues implements PropertyValues {
PropertySourcesPropertyResolver resolver, PropertySourcesPropertyResolver resolver,
PropertyNamePatternsMatcher includes, Collection<String> exacts) { PropertyNamePatternsMatcher includes, Collection<String> exacts) {
for (String propertyName : exacts) { for (String propertyName : exacts) {
if (!source.containsProperty(propertyName)) {
continue;
}
Object value = null; Object value = null;
try { try {
value = resolver.getProperty(propertyName, Object.class); value = resolver.getProperty(propertyName, Object.class);
......
...@@ -57,6 +57,16 @@ public class PropertySourcesBindingTests { ...@@ -57,6 +57,16 @@ public class PropertySourcesBindingTests {
assertThat(this.properties.getBar(), is("override")); assertThat(this.properties.getBar(), is("override"));
} }
@Test
public void overridingOfPropertiesOrderOfAtPropertySourcesWherePropertyIsCapitalized() {
assertThat(this.properties.getSpam(), is("BUCKET"));
}
@Test
public void overridingOfPropertiesOrderOfAtPropertySourcesWherePropertyNamesDiffer() {
assertThat(this.properties.getTheName(), is("NAME"));
}
@Test @Test
public void overridingOfPropertiesAndBindToAtValue() { public void overridingOfPropertiesAndBindToAtValue() {
assertThat(this.foo, is(this.properties.getFoo())); assertThat(this.foo, is(this.properties.getFoo()));
...@@ -93,6 +103,10 @@ public class PropertySourcesBindingTests { ...@@ -93,6 +103,10 @@ public class PropertySourcesBindingTests {
private String bar; private String bar;
private String spam;
private String theName;
public String getBar() { public String getBar() {
return this.bar; return this.bar;
} }
...@@ -108,6 +122,22 @@ public class PropertySourcesBindingTests { ...@@ -108,6 +122,22 @@ public class PropertySourcesBindingTests {
public void setFoo(String foo) { public void setFoo(String foo) {
this.foo = foo; this.foo = foo;
} }
public String getSpam() {
return this.spam;
}
public void setSpam(String spam) {
this.spam = spam;
}
public String getTheName() {
return this.theName;
}
public void setTheName(String theName) {
this.theName = theName;
}
} }
} }
foo=bar foo=bar
bar=override bar=override
SPAM=BUCKET
THE_NAME=NAME
\ No newline at end of file
foo=spam foo=spam
bar=some bar=some
\ No newline at end of file spam=bucket
the-name=name
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment