PrefixedConfigurationPropertySourceTests.java (spring-boot-2.7.3) | : | PrefixedConfigurationPropertySourceTests.java (spring-boot-2.7.4) | ||
---|---|---|---|---|
skipping to change at line 20 | skipping to change at line 20 | |||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | |||
* 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 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 PrefixedConfigurationPropertySource}. | * Tests for {@link PrefixedConfigurationPropertySource}. | |||
* | * | |||
* @author Madhura Bhave | * @author Madhura Bhave | |||
*/ | */ | |||
class PrefixedConfigurationPropertySourceTests { | class PrefixedConfigurationPropertySourceTests { | |||
@Test | @Test | |||
void getConfigurationPropertyShouldConsiderPrefix() { | void getConfigurationPropertyShouldConsiderPrefix() { | |||
skipping to change at line 48 | skipping to change at line 45 | |||
ConfigurationPropertySource prefixed = source.nonIterable().withP refix("my"); | ConfigurationPropertySource prefixed = source.nonIterable().withP refix("my"); | |||
assertThat(getName(prefixed, "foo.bar").toString()).isEqualTo("fo o.bar"); | assertThat(getName(prefixed, "foo.bar").toString()).isEqualTo("fo o.bar"); | |||
assertThat(getValue(prefixed, "foo.bar")).isEqualTo("bing"); | assertThat(getValue(prefixed, "foo.bar")).isEqualTo("bing"); | |||
assertThat(getName(prefixed, "foo.baz").toString()).isEqualTo("fo o.baz"); | assertThat(getName(prefixed, "foo.baz").toString()).isEqualTo("fo o.baz"); | |||
assertThat(getValue(prefixed, "foo.baz")).isEqualTo("biff"); | assertThat(getValue(prefixed, "foo.baz")).isEqualTo("biff"); | |||
} | } | |||
@Test | @Test | |||
void containsDescendantOfWhenSourceReturnsUnknownShouldReturnUnknown() { | void containsDescendantOfWhenSourceReturnsUnknownShouldReturnUnknown() { | |||
ConfigurationPropertyName name = ConfigurationPropertyName.of("my .foo"); | ConfigurationPropertyName name = ConfigurationPropertyName.of("my .foo"); | |||
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 prefixed = source.withPrefix("my"); | ConfigurationPropertySource prefixed = source.withPrefix("my"); | |||
assertThat(prefixed.containsDescendantOf(ConfigurationPropertyNam e.of("foo"))) | assertThat(prefixed.containsDescendantOf(ConfigurationPropertyNam e.of("foo"))) | |||
.isEqualTo(ConfigurationPropertyState.UNKNOWN); | .isEqualTo(ConfigurationPropertyState.UNKNOWN); | |||
} | } | |||
@Test | @Test | |||
void containsDescendantOfWhenSourceReturnsPresentShouldReturnPresent() { | void containsDescendantOfWhenSourceReturnsPresentShouldReturnPresent() { | |||
ConfigurationPropertyName name = ConfigurationPropertyName.of("my .foo"); | ConfigurationPropertyName name = ConfigurationPropertyName.of("my .foo"); | |||
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 prefixed = source.withPrefix("my"); | ConfigurationPropertySource prefixed = source.withPrefix("my"); | |||
assertThat(prefixed.containsDescendantOf(ConfigurationPropertyNam e.of("foo"))) | assertThat(prefixed.containsDescendantOf(ConfigurationPropertyNam e.of("foo"))) | |||
.isEqualTo(ConfigurationPropertyState.PRESENT); | .isEqualTo(ConfigurationPropertyState.PRESENT); | |||
} | } | |||
@Test | @Test | |||
void containsDescendantOfWhenSourceReturnsAbsentShouldReturnAbsent() { | void containsDescendantOfWhenSourceReturnsAbsentShouldReturnAbsent() { | |||
ConfigurationPropertyName name = ConfigurationPropertyName.of("my .foo"); | ConfigurationPropertyName name = ConfigurationPropertyName.of("my .foo"); | |||
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 prefixed = source.withPrefix("my"); | ConfigurationPropertySource prefixed = source.withPrefix("my"); | |||
assertThat(prefixed.containsDescendantOf(ConfigurationPropertyNam e.of("foo"))) | assertThat(prefixed.containsDescendantOf(ConfigurationPropertyNam e.of("foo"))) | |||
.isEqualTo(ConfigurationPropertyState.ABSENT); | .isEqualTo(ConfigurationPropertyState.ABSENT); | |||
} | } | |||
@Test | @Test | |||
void withPrefixWhenPrefixIsNullReturnsOriginalSource() { | void withPrefixWhenPrefixIsNullReturnsOriginalSource() { | |||
ConfigurationPropertySource source = new MockConfigurationPropert ySource().nonIterable(); | ConfigurationPropertySource source = new MockConfigurationPropert ySource().nonIterable(); | |||
ConfigurationPropertySource prefixed = source.withPrefix(null); | ConfigurationPropertySource prefixed = source.withPrefix(null); | |||
assertThat(prefixed).isSameAs(source); | assertThat(prefixed).isSameAs(source); | |||
End of changes. 5 change blocks. | ||||
21 lines changed or deleted | 8 lines changed or added |