2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.model.utilities;
23 import static org.junit.Assert.assertEquals;
25 import java.util.List;
26 import java.util.Map.Entry;
27 import java.util.TreeMap;
29 import org.junit.Test;
30 import org.onap.policy.apex.model.utilities.TreeMapUtils;
33 * Test the tree map utilities.
34 * @author Liam Fallon (liam.fallon@ericsson.com)
36 public class TreeMapUtilsTest {
40 TreeMap<String, String> testTreeMap = new TreeMap<String, String>();
41 testTreeMap.put("G", "G");
42 testTreeMap.put("H", "H");
43 testTreeMap.put("JA", "JA");
44 testTreeMap.put("JAM", "JAM");
45 testTreeMap.put("JOE", "JOE");
46 testTreeMap.put("JOSH", "JOSH");
47 testTreeMap.put("K", "K");
49 List<Entry<String, String>> foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "F");
50 assertEquals(0, foundKeyList.size());
52 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "G");
53 assertEquals("G", foundKeyList.get(0).getKey());
55 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "H");
56 assertEquals("H", foundKeyList.get(0).getKey());
58 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "I");
59 assertEquals(0, foundKeyList.size());
61 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "J");
62 assertEquals("JA", foundKeyList.get(0).getKey());
64 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JA");
65 assertEquals("JA", foundKeyList.get(0).getKey());
67 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JB");
68 assertEquals(0, foundKeyList.size());
70 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JO");
71 assertEquals("JOE", foundKeyList.get(0).getKey());
73 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JOE");
74 assertEquals("JOE", foundKeyList.get(0).getKey());
76 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JOS");
77 assertEquals("JOSH", foundKeyList.get(0).getKey());
79 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JOSH");
80 assertEquals("JOSH", foundKeyList.get(0).getKey());
82 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "K");
83 assertEquals("K", foundKeyList.get(0).getKey());
85 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "L");
86 assertEquals(0, foundKeyList.size());