c5a27bc42519b66fa92b8367e04bb76eff632c7f
[sdc.git] / catalog-dao / src / test / java / org / openecomp / sdc / be / dao / utils / CollectionUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.dao.utils;
22
23 import org.apache.tinkerpop.gremlin.structure.T;
24 import org.junit.jupiter.api.Test;
25
26 import java.util.List;
27 import java.util.LinkedList;
28 import java.util.Map;
29 import java.util.HashMap;
30 import java.util.HashSet;
31 import java.util.Set;
32
33 import static org.junit.jupiter.api.Assertions.assertEquals;
34 import static org.junit.jupiter.api.Assertions.assertNotNull;
35 import static org.junit.jupiter.api.Assertions.assertNull;
36
37 public class CollectionUtilsTest {
38
39         @Test
40         public void testMerge() throws Exception {
41                 Set<T> source = new HashSet<>();
42                 Set<T> target = new HashSet<>();
43                 assertNull(CollectionUtils.merge(source, target));
44
45                 T t = null;
46                 source.add(t);
47                 assertNotNull(CollectionUtils.merge(source, target));
48         }
49
50         @Test
51         public void testMerge_1() throws Exception {
52                 Map<String, String> source = new HashMap();
53                 Map<String, String> target = new HashMap();
54
55                 source.put("key", "value");
56                 target.put("key", "value2");
57                 assertEquals("value2", CollectionUtils.merge(source, target, false).get("key"));
58                 assertEquals("value", CollectionUtils.merge(source, target, true).get("key"));
59         }
60
61         @Test
62         public void testMerge_2() throws Exception {
63                 List<String> source = null;
64                 List<String> target = null;
65                 assertEquals(0, CollectionUtils.merge(source, target).size());
66
67                 source = new LinkedList<>();
68                 target = new LinkedList<>();
69                 assertEquals(0, CollectionUtils.merge(source, target).size());
70
71                 source.add("test1");
72                 target.add("test2");
73                 assertEquals("test2", CollectionUtils.merge(source, target).get(0));
74                 assertEquals("test1", CollectionUtils.merge(source, target).get(1));
75         }
76
77         @Test
78         public void testUnion() throws Exception {
79                 List<String> source = new LinkedList<>();
80                 List<String> target = new LinkedList<>();
81
82                 source.add("test1");
83                 target.add("test2");
84                 assertEquals("test1", CollectionUtils.union(source, target).get(0));
85                 assertEquals("test2", CollectionUtils.union(source, target).get(1));
86         }
87 }