Fix ConfigurationPropertyName ancestor bug

Fix an issue with `ConfigurationPropertyName` where the `isAncesorOf`
method would not work with `ConfigurationPropertyName.EMPTY`

See gh-9000
This commit is contained in:
Phillip Webb 2017-05-01 22:03:05 -07:00
parent 10b8eb3109
commit 3153117429
2 changed files with 12 additions and 0 deletions

View File

@ -145,6 +145,9 @@ public final class ConfigurationPropertyName
* @return {@code true} if this name is an ancestor
*/
public boolean isAncestorOf(ConfigurationPropertyName name) {
if (this.equals(EMPTY)) {
return true;
}
ConfigurationPropertyName candidate = (name == null ? null : name.getParent());
while (candidate != null) {
if (candidate.equals(this)) {

View File

@ -274,6 +274,15 @@ public class ConfigurationPropertyNameTests {
assertThat(grandchild.isAncestorOf(parent)).isFalse();
}
@Test
public void isAncestorOfWhenRootReturnTrue() throws Exception {
ConfigurationPropertyName parent = ConfigurationPropertyName.of("");
ConfigurationPropertyName grandchild = ConfigurationPropertyName
.of("foo.bar.baz");
assertThat(parent.isAncestorOf(grandchild)).isTrue();
assertThat(grandchild.isAncestorOf(parent)).isFalse();
}
@Test
public void appendWhenNotIndexedShouldAppendWithDot() throws Exception {
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");