diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/util/SpringUtils.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/util/SpringUtils.java index 91e89872d..275b54dcc 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/util/SpringUtils.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/util/SpringUtils.java @@ -68,6 +68,26 @@ @SuppressWarnings("unused") public abstract class SpringUtils { + /** + * Determines whether all the {@link Object} values in the array are {@literal non-null} + * + * @param values array of {@link Object Objects} to evaluate. + * @return a boolean value indicating whether all of the {@link Object} values + * in the array are {@literal non-null}. + */ + public static boolean areNotNull(Object... values) { + + if (values != null) { + for (Object value : values) { + if (value == null) { + return false; + } + } + } + + return true; + } + /** * Determines whether a given bean registered in the {@link BeanFactory Spring container} matches by * both {@link String name} and {@link Class type}. diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/util/SpringUtilsUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/util/SpringUtilsUnitTests.java index cf1d6393e..a97bcec75 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/util/SpringUtilsUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/util/SpringUtilsUnitTests.java @@ -77,6 +77,29 @@ public class SpringUtilsUnitTests { @Mock private BeanDefinition mockBeanDefinition; + @Test + public void areNotNullIsNullSafe() { + assertThat(SpringUtils.areNotNull((Object[]) null)).isTrue(); + } + + @Test + public void areNotNullWithAllNullValuesReturnsFalse() { + assertThat(SpringUtils.areNotNull(null, null, null)).isFalse(); + } + + @Test + public void areNotNullWithNoNullValuesReturnsTrue() { + assertThat(SpringUtils.areNotNull(1, 2, 3)).isTrue(); + } + + @Test + public void areNotNullWithOneNullValueIsFalse() { + + assertThat(SpringUtils.areNotNull(null, 2, 3)).isFalse(); + assertThat(SpringUtils.areNotNull(1, null, 3)).isFalse(); + assertThat(SpringUtils.areNotNull(1, 2, null)).isFalse(); + } + @Test public void isMatchingBeanReturnsTrue() {