diff --git a/src/test/java/xyz/zhouxy/plusone/commons/collection/CollectionToolsTests.java b/src/test/java/xyz/zhouxy/plusone/commons/collection/CollectionToolsTests.java index bcb53a6..97fdef5 100644 --- a/src/test/java/xyz/zhouxy/plusone/commons/collection/CollectionToolsTests.java +++ b/src/test/java/xyz/zhouxy/plusone/commons/collection/CollectionToolsTests.java @@ -16,16 +16,24 @@ package xyz.zhouxy.plusone.commons.collection; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import org.junit.jupiter.api.Test; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + public class CollectionToolsTests { @Test void testIsEmpty() { @@ -46,4 +54,19 @@ public class CollectionToolsTests { assertFalse(CollectionTools.isEmpty(map)); assertTrue(CollectionTools.isNotEmpty(map)); } + + @Test + void testNullToEmpty() { + List list = Lists.newArrayList("Java", "C", "C++", "C#"); + assertSame(list, CollectionTools.nullToEmptyList(list)); + assertEquals(Collections.emptyList(), CollectionTools.nullToEmptyList(null)); + + Set set = Sets.newHashSet("Java", "C", "C++", "C#"); + assertSame(set, CollectionTools.nullToEmptySet(set)); + assertEquals(Collections.emptySet(), CollectionTools.nullToEmptySet(null)); + + Map map = ImmutableMap.of("K1", 1, "K2", 2, "K3", 3); + assertSame(map, CollectionTools.nullToEmptyMap(map)); + assertEquals(Collections.emptyMap(), CollectionTools.nullToEmptyMap(null)); + } }