@ -19,6 +19,8 @@ package org.springframework.boot.context.properties.source;
import org.junit.Test ;
import org.mockito.Answers ;
import org.springframework.boot.origin.Origin ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.mockito.BDDMockito.given ;
import static org.mockito.Mockito.mock ;
@ -105,8 +107,30 @@ public class AliasedConfigurationPropertySourceTests {
. willReturn ( ConfigurationPropertyState . ABSENT ) ;
given ( source . containsDescendantOf ( ConfigurationPropertyName . of ( "bar" ) ) )
. willReturn ( ConfigurationPropertyState . PRESENT ) ;
ConfigurationPropertyName barBar = ConfigurationPropertyName . of ( "bar.bar" ) ;
given ( source . getConfigurationProperty ( barBar ) ) . willReturn (
new ConfigurationProperty ( barBar , "barBarValue" , mock ( Origin . class ) ) ) ;
ConfigurationPropertySource aliased = source
. withAliases ( new ConfigurationPropertyNameAliases ( "foo" , "bar" ) ) ;
. withAliases ( new ConfigurationPropertyNameAliases ( "bar.bar" , "foo.foo" ) ) ;
assertThat ( aliased . containsDescendantOf ( name ) )
. isEqualTo ( ConfigurationPropertyState . PRESENT ) ;
}
@Test
public void containsDescendantOfWhenPresentInAliasShouldReturnPresent ( ) {
ConfigurationPropertyName name = ConfigurationPropertyName . of ( "baz" ) ;
ConfigurationPropertySource source = mock ( ConfigurationPropertySource . class ,
withSettings ( ) . defaultAnswer ( Answers . CALLS_REAL_METHODS ) ) ;
given ( source . containsDescendantOf ( name ) )
. willReturn ( ConfigurationPropertyState . ABSENT ) ;
ConfigurationPropertyName barFoo = ConfigurationPropertyName . of ( "bar.foo" ) ;
given ( source . getConfigurationProperty ( barFoo ) ) . willReturn (
new ConfigurationProperty ( barFoo , "barFooValue" , mock ( Origin . class ) ) ) ;
ConfigurationPropertySource aliased = source
. withAliases ( new ConfigurationPropertyNameAliases ( "bar.foo" , "baz.foo" ) ) ;
assertThat ( aliased . containsDescendantOf ( name ) )
. isEqualTo ( ConfigurationPropertyState . PRESENT ) ;
}