2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.dao.utils;
23 import org.apache.tinkerpop.gremlin.structure.T;
24 import org.junit.jupiter.api.Test;
26 import java.util.List;
27 import java.util.LinkedList;
29 import java.util.HashMap;
30 import java.util.HashSet;
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;
37 public class CollectionUtilsTest {
40 public void testMerge() throws Exception {
41 Set<T> source = new HashSet<>();
42 Set<T> target = new HashSet<>();
43 assertNull(CollectionUtils.merge(source, target));
47 assertNotNull(CollectionUtils.merge(source, target));
51 public void testMerge_1() throws Exception {
52 Map<String, String> source = new HashMap();
53 Map<String, String> target = new HashMap();
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"));
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());
67 source = new LinkedList<>();
68 target = new LinkedList<>();
69 assertEquals(0, CollectionUtils.merge(source, target).size());
73 assertEquals("test2", CollectionUtils.merge(source, target).get(0));
74 assertEquals("test1", CollectionUtils.merge(source, target).get(1));
78 public void testUnion() throws Exception {
79 List<String> source = new LinkedList<>();
80 List<String> target = new LinkedList<>();
84 assertEquals("test1", CollectionUtils.union(source, target).get(0));
85 assertEquals("test2", CollectionUtils.union(source, target).get(1));