From e83d137179fa3c532c191f89f9e6cdd53b0778c7 Mon Sep 17 00:00:00 2001 From: xuegao Date: Thu, 25 Mar 2021 16:00:32 +0100 Subject: Improve test coverage Add unit tests to improve test coverage. Issue-ID: SDC-3428 Change-Id: Ifd9e6eb25fa3ec9f4f93d283277574120edff835 Signed-off-by: xuegao --- .../sdc/be/dao/utils/CollectionUtilsTest.java | 78 ++++++++++++---------- 1 file changed, 43 insertions(+), 35 deletions(-) (limited to 'catalog-dao/src/test/java') diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/CollectionUtilsTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/CollectionUtilsTest.java index eaa2538d11..c5a27bc425 100644 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/CollectionUtilsTest.java +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/CollectionUtilsTest.java @@ -21,59 +21,67 @@ package org.openecomp.sdc.be.dao.utils; import org.apache.tinkerpop.gremlin.structure.T; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.util.*; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; public class CollectionUtilsTest { @Test public void testMerge() throws Exception { - Set source = null; - Set target = null; - Set result; - - // test 1 - target = null; - result = CollectionUtils.merge(source, target); - Assert.assertEquals(null, result); + Set source = new HashSet<>(); + Set target = new HashSet<>(); + assertNull(CollectionUtils.merge(source, target)); - // test 2 - source = null; - result = CollectionUtils.merge(source, target); - Assert.assertEquals(null, result); + T t = null; + source.add(t); + assertNotNull(CollectionUtils.merge(source, target)); } @Test public void testMerge_1() throws Exception { Map source = new HashMap(); Map target = new HashMap(); - boolean override = false; - Map result; - result = CollectionUtils.merge(source, target, override); - Assert.assertEquals(null, result); - - // test 1 - target = null; - result = CollectionUtils.merge(source, target, override); - Assert.assertEquals(null, result); - - // test 2 - source = null; - result = CollectionUtils.merge(source, target, override); - Assert.assertEquals(null, result); + source.put("key", "value"); + target.put("key", "value2"); + assertEquals("value2", CollectionUtils.merge(source, target, false).get("key")); + assertEquals("value", CollectionUtils.merge(source, target, true).get("key")); } @Test public void testMerge_2() throws Exception { - List source = new LinkedList<>(); - List target = new LinkedList<>(); - List result; + List source = null; + List target = null; + assertEquals(0, CollectionUtils.merge(source, target).size()); + + source = new LinkedList<>(); + target = new LinkedList<>(); + assertEquals(0, CollectionUtils.merge(source, target).size()); + + source.add("test1"); + target.add("test2"); + assertEquals("test2", CollectionUtils.merge(source, target).get(0)); + assertEquals("test1", CollectionUtils.merge(source, target).get(1)); + } + + @Test + public void testUnion() throws Exception { + List source = new LinkedList<>(); + List target = new LinkedList<>(); - // test 1 - result = CollectionUtils.merge(source, target); - Assert.assertEquals(target, result); + source.add("test1"); + target.add("test2"); + assertEquals("test1", CollectionUtils.union(source, target).get(0)); + assertEquals("test2", CollectionUtils.union(source, target).get(1)); } } -- cgit 1.2.3-korg