Polish "Assert that sources does not contain null elements"

See gh-30878
This commit is contained in:
Andy Wilkinson 2022-05-27 10:01:06 +01:00
parent ebf276c005
commit 56c3a5f0ab
2 changed files with 15 additions and 5 deletions

View File

@ -182,7 +182,9 @@ public class Binder {
List<ConversionService> conversionServices, Consumer<PropertyEditorRegistry> propertyEditorInitializer,
BindHandler defaultBindHandler, BindConstructorProvider constructorProvider) {
Assert.notNull(sources, "Sources must not be null");
sources.forEach((source) -> Assert.notNull(source, "Sources cannot contain null values"));
for (ConfigurationPropertySource source : sources) {
Assert.notNull(source, "Sources must not contain null elements");
}
this.sources = sources;
this.placeholdersResolver = (placeholdersResolver != null) ? placeholdersResolver : PlaceholdersResolver.NONE;
this.bindConverter = BindConverter.get(conversionServices, propertyEditorInitializer);

View File

@ -70,19 +70,27 @@ class BinderTests {
private Binder binder = new Binder(this.sources);
@Test
void createWhenSourcesIsNullShouldThrowException() {
void createWhenSourcesIsNullArrayShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new Binder((ConfigurationPropertySource[]) null))
.withMessageContaining("Sources must not be null");
}
@Test
void creatWhenSourcesIsNullIterableShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new Binder((Iterable<ConfigurationPropertySource>) null))
.withMessageContaining("Sources must not be null");
}
@Test
void createWhenSourcesContainNullValuesShouldThrowException() {
void createWhenArraySourcesContainsNullElementShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new Binder(new ConfigurationPropertySource[] { null }))
.withMessageContaining("Sources cannot contain null values");
.withMessageContaining("Sources must not contain null elements");
}
@Test
void createWhenIterableSourcesContainsNullElementShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new Binder(Collections.singletonList(null)))
.withMessageContaining("Sources cannot contain null values");
.withMessageContaining("Sources must not contain null elements");
}
@Test