diff options
author | Alexander Tsvetkov <alexander.tsvetkov.93@gmail.com> | 2018-08-17 08:47:07 +0300 |
---|---|---|
committer | Alexander Tsvetkov <alexander.tsvetkov.93@gmail.com> | 2018-08-17 09:02:46 +0300 |
commit | 2a11642511a3c69bac5aa1abd83d3219871395e3 (patch) | |
tree | f5b428d0732b9f274626bcee09bcea18c7fa3e9a /src/test/java/org/apache/commons | |
parent | c3de2d69ce9ad778a0bc22971cb8ff36dd0ee062 (diff) | |
download | apache-commons-lang-2a11642511a3c69bac5aa1abd83d3219871395e3.tar.gz |
LANG-1411: Add empty checks to ObjectUtils
Diffstat (limited to 'src/test/java/org/apache/commons')
-rw-r--r-- | src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java b/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java index 661722dac..2ec631fcb 100644 --- a/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java @@ -31,9 +31,14 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; +import java.util.Collections; import java.util.Comparator; import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Set; import org.apache.commons.lang3.exception.CloneFailedException; import org.apache.commons.lang3.mutable.MutableObject; @@ -47,6 +52,13 @@ import org.junit.Test; public class ObjectUtilsTest { private static final String FOO = "foo"; private static final String BAR = "bar"; + private static final String[] NON_EMPTY_ARRAY = new String[] { FOO, BAR, }; + private static final List<String> NON_EMPTY_LIST = Arrays.asList(NON_EMPTY_ARRAY); + private static final Set<String> NON_EMPTY_SET = new HashSet<>(NON_EMPTY_LIST); + private static final Map<String, String> NON_EMPTY_MAP = new HashMap<>(); + static { + NON_EMPTY_MAP.put(FOO, BAR); + } //----------------------------------------------------------------------- @Test @@ -61,6 +73,41 @@ public class ObjectUtilsTest { //----------------------------------------------------------------------- @Test + public void testIsEmpty() { + assertTrue(ObjectUtils.isEmpty(null)); + assertTrue(ObjectUtils.isEmpty("")); + assertTrue(ObjectUtils.isEmpty(new int[] {})); + assertTrue(ObjectUtils.isEmpty(Collections.emptyList())); + assertTrue(ObjectUtils.isEmpty(Collections.emptySet())); + assertTrue(ObjectUtils.isEmpty(Collections.emptyMap())); + + assertFalse(ObjectUtils.isEmpty(" ")); + assertFalse(ObjectUtils.isEmpty("ab")); + assertFalse(ObjectUtils.isEmpty(NON_EMPTY_ARRAY)); + assertFalse(ObjectUtils.isEmpty(NON_EMPTY_LIST)); + assertFalse(ObjectUtils.isEmpty(NON_EMPTY_SET)); + assertFalse(ObjectUtils.isEmpty(NON_EMPTY_MAP)); + } + + @Test + public void testIsNotEmpty() { + assertFalse(ObjectUtils.isNotEmpty(null)); + assertFalse(ObjectUtils.isNotEmpty("")); + assertFalse(ObjectUtils.isNotEmpty(new int[] {})); + assertFalse(ObjectUtils.isNotEmpty(Collections.emptyList())); + assertFalse(ObjectUtils.isNotEmpty(Collections.emptySet())); + assertFalse(ObjectUtils.isNotEmpty(Collections.emptyMap())); + + assertTrue(ObjectUtils.isNotEmpty(" ")); + assertTrue(ObjectUtils.isNotEmpty("ab")); + assertTrue(ObjectUtils.isNotEmpty(NON_EMPTY_ARRAY)); + assertTrue(ObjectUtils.isNotEmpty(NON_EMPTY_LIST)); + assertTrue(ObjectUtils.isNotEmpty(NON_EMPTY_SET)); + assertTrue(ObjectUtils.isNotEmpty(NON_EMPTY_MAP)); + } + + //----------------------------------------------------------------------- + @Test public void testIsNull() { final Object o = FOO; final Object dflt = BAR; |