AliasedConfigurationPropertySourceTests.java (spring-boot-2.7.3) | : | AliasedConfigurationPropertySourceTests.java (spring-boot-2.7.4) | ||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | |||
* limitations under the License. | * limitations under the License. | |||
*/ | */ | |||
package org.springframework.boot.context.properties.source; | package org.springframework.boot.context.properties.source; | |||
import java.util.Collections; | import java.util.Collections; | |||
import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | |||
import org.mockito.Answers; | ||||
import static org.assertj.core.api.Assertions.assertThat; | import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.BDDMockito.given; | ||||
import static org.mockito.Mockito.mock; | ||||
/** | /** | |||
* Tests for {@link AliasedConfigurationPropertySource}. | * Tests for {@link AliasedConfigurationPropertySource}. | |||
* | * | |||
* @author Phillip Webb | * @author Phillip Webb | |||
* @author Madhura Bhave | * @author Madhura Bhave | |||
*/ | */ | |||
class AliasedConfigurationPropertySourceTests { | class AliasedConfigurationPropertySourceTests { | |||
@Test | @Test | |||
skipping to change at line 60 | skipping to change at line 57 | |||
source.put("foo.bar", "bing"); | source.put("foo.bar", "bing"); | |||
source.put("foo.baz", "biff"); | source.put("foo.baz", "biff"); | |||
ConfigurationPropertySource aliased = source.nonIterable() | ConfigurationPropertySource aliased = source.nonIterable() | |||
.withAliases(new ConfigurationPropertyNameAliases ("foo.bar", "foo.bar1")); | .withAliases(new ConfigurationPropertyNameAliases ("foo.bar", "foo.bar1")); | |||
assertThat(getValue(aliased, "foo.baz")).isEqualTo("biff"); | assertThat(getValue(aliased, "foo.baz")).isEqualTo("biff"); | |||
} | } | |||
@Test | @Test | |||
void containsDescendantOfWhenSourceReturnsUnknownShouldReturnUnknown() { | void containsDescendantOfWhenSourceReturnsUnknownShouldReturnUnknown() { | |||
ConfigurationPropertyName name = ConfigurationPropertyName.of("fo o"); | ConfigurationPropertyName name = ConfigurationPropertyName.of("fo o"); | |||
ConfigurationPropertySource source = mock(ConfigurationPropertySo | ConfigurationPropertySource source = new KnownAncestorsConfigurat | |||
urce.class, Answers.CALLS_REAL_METHODS); | ionPropertySource().unknown(name); | |||
given(source.containsDescendantOf(name)).willReturn(Configuration | ||||
PropertyState.UNKNOWN); | ||||
ConfigurationPropertySource aliased = source | ConfigurationPropertySource aliased = source | |||
.withAliases(new ConfigurationPropertyNameAliases ("foo.bar", "foo.bar1")); | .withAliases(new ConfigurationPropertyNameAliases ("foo.bar", "foo.bar1")); | |||
assertThat(aliased.containsDescendantOf(name)).isEqualTo(Configur ationPropertyState.UNKNOWN); | assertThat(aliased.containsDescendantOf(name)).isEqualTo(Configur ationPropertyState.UNKNOWN); | |||
} | } | |||
@Test | @Test | |||
void containsDescendantOfWhenSourceReturnsPresentShouldReturnPresent() { | void containsDescendantOfWhenSourceReturnsPresentShouldReturnPresent() { | |||
ConfigurationPropertyName name = ConfigurationPropertyName.of("fo o"); | ConfigurationPropertyName name = ConfigurationPropertyName.of("fo o"); | |||
ConfigurationPropertySource source = mock(ConfigurationPropertySo | ConfigurationPropertySource source = new KnownAncestorsConfigurat | |||
urce.class, Answers.CALLS_REAL_METHODS); | ionPropertySource().present(name) | |||
given(source.containsDescendantOf(name)).willReturn(Configuration | .unknown(ConfigurationPropertyName.of("bar")); | |||
PropertyState.PRESENT); | ||||
given(source.containsDescendantOf(ConfigurationPropertyName.of("b | ||||
ar"))) | ||||
.willReturn(ConfigurationPropertyState.UNKNOWN); | ||||
ConfigurationPropertySource aliased = source | ConfigurationPropertySource aliased = source | |||
.withAliases(new ConfigurationPropertyNameAliases ("foo.bar", "foo.bar1")); | .withAliases(new ConfigurationPropertyNameAliases ("foo.bar", "foo.bar1")); | |||
assertThat(aliased.containsDescendantOf(name)).isEqualTo(Configur ationPropertyState.PRESENT); | assertThat(aliased.containsDescendantOf(name)).isEqualTo(Configur ationPropertyState.PRESENT); | |||
} | } | |||
@Test | @Test | |||
void containsDescendantOfWhenAllAreAbsentShouldReturnAbsent() { | void containsDescendantOfWhenAllAreAbsentShouldReturnAbsent() { | |||
ConfigurationPropertyName name = ConfigurationPropertyName.of("fo o"); | ConfigurationPropertyName name = ConfigurationPropertyName.of("fo o"); | |||
ConfigurationPropertySource source = mock(ConfigurationPropertySo | ConfigurationPropertySource source = new KnownAncestorsConfigurat | |||
urce.class, Answers.CALLS_REAL_METHODS); | ionPropertySource().absent(name) | |||
given(source.containsDescendantOf(name)).willReturn(Configuration | .absent(ConfigurationPropertyName.of("bar")); | |||
PropertyState.ABSENT); | ||||
given(source.containsDescendantOf(ConfigurationPropertyName.of("b | ||||
ar"))) | ||||
.willReturn(ConfigurationPropertyState.ABSENT); | ||||
ConfigurationPropertySource aliased = source.withAliases(new Conf igurationPropertyNameAliases("foo", "bar")); | ConfigurationPropertySource aliased = source.withAliases(new Conf igurationPropertyNameAliases("foo", "bar")); | |||
assertThat(aliased.containsDescendantOf(name)).isEqualTo(Configur ationPropertyState.ABSENT); | assertThat(aliased.containsDescendantOf(name)).isEqualTo(Configur ationPropertyState.ABSENT); | |||
} | } | |||
@Test | @Test | |||
void containsDescendantOfWhenAnyIsPresentShouldReturnPresent() { | void containsDescendantOfWhenAnyIsPresentShouldReturnPresent() { | |||
ConfigurationPropertyName name = ConfigurationPropertyName.of("fo o"); | ConfigurationPropertyName name = ConfigurationPropertyName.of("fo o"); | |||
ConfigurationPropertySource source = mock(ConfigurationPropertySo | ConfigurationPropertySource source = new KnownAncestorsConfigurat | |||
urce.class, Answers.CALLS_REAL_METHODS); | ionPropertySource().absent(name) | |||
given(source.containsDescendantOf(name)).willReturn(Configuration | .present(ConfigurationPropertyName.of("bar")); | |||
PropertyState.ABSENT); | ||||
given(source.containsDescendantOf(ConfigurationPropertyName.of("b | ||||
ar"))) | ||||
.willReturn(ConfigurationPropertyState.PRESENT); | ||||
ConfigurationPropertySource aliased = source.withAliases(new Conf igurationPropertyNameAliases("foo", "bar")); | ConfigurationPropertySource aliased = source.withAliases(new Conf igurationPropertyNameAliases("foo", "bar")); | |||
assertThat(aliased.containsDescendantOf(name)).isEqualTo(Configur ationPropertyState.PRESENT); | assertThat(aliased.containsDescendantOf(name)).isEqualTo(Configur ationPropertyState.PRESENT); | |||
} | } | |||
@Test | @Test | |||
void containsDescendantOfWhenPresentInAliasShouldReturnPresent() { | void containsDescendantOfWhenPresentInAliasShouldReturnPresent() { | |||
ConfigurationPropertySource source = new MapConfigurationProperty Source( | ConfigurationPropertySource source = new MapConfigurationProperty Source( | |||
Collections.singletonMap("foo.bar", "foobar")); | Collections.singletonMap("foo.bar", "foobar")); | |||
ConfigurationPropertySource aliased = source | ConfigurationPropertySource aliased = source | |||
.withAliases(new ConfigurationPropertyNameAliases ("foo.bar", "baz.foo")); | .withAliases(new ConfigurationPropertyNameAliases ("foo.bar", "baz.foo")); | |||
End of changes. 6 change blocks. | ||||
28 lines changed or deleted | 11 lines changed or added |