Polish "Assert that sources does not contain null elements"

See gh-30878
pull/31224/head
Andy Wilkinson 3 years ago
parent ebf276c005
commit 56c3a5f0ab

@ -182,7 +182,9 @@ public class Binder {
List<ConversionService> conversionServices, Consumer<PropertyEditorRegistry> propertyEditorInitializer, List<ConversionService> conversionServices, Consumer<PropertyEditorRegistry> propertyEditorInitializer,
BindHandler defaultBindHandler, BindConstructorProvider constructorProvider) { BindHandler defaultBindHandler, BindConstructorProvider constructorProvider) {
Assert.notNull(sources, "Sources must not be null"); 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.sources = sources;
this.placeholdersResolver = (placeholdersResolver != null) ? placeholdersResolver : PlaceholdersResolver.NONE; this.placeholdersResolver = (placeholdersResolver != null) ? placeholdersResolver : PlaceholdersResolver.NONE;
this.bindConverter = BindConverter.get(conversionServices, propertyEditorInitializer); this.bindConverter = BindConverter.get(conversionServices, propertyEditorInitializer);

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

Loading…
Cancel
Save