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;
28 import org.junit.Test;
31 * Test the tree map utilities.
32 * @author Liam Fallon (liam.fallon@ericsson.com)
34 public class TreeMapUtilsTest {
38 TreeMap<String, String> testTreeMap = new TreeMap<String, String>();
39 testTreeMap.put("G", "G");
40 testTreeMap.put("H", "H");
41 testTreeMap.put("JA", "JA");
42 testTreeMap.put("JAM", "JAM");
43 testTreeMap.put("JOE", "JOE");
44 testTreeMap.put("JOSH", "JOSH");
45 testTreeMap.put("K", "K");
47 List<Entry<String, String>> foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "F");
48 assertEquals(0, foundKeyList.size());
50 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "G");
51 assertEquals("G", foundKeyList.get(0).getKey());
53 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "H");
54 assertEquals("H", foundKeyList.get(0).getKey());
56 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "I");
57 assertEquals(0, foundKeyList.size());
59 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "J");
60 assertEquals("JA", foundKeyList.get(0).getKey());
62 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JA");
63 assertEquals("JA", foundKeyList.get(0).getKey());
65 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JB");
66 assertEquals(0, foundKeyList.size());
68 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JO");
69 assertEquals("JOE", foundKeyList.get(0).getKey());
71 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JOE");
72 assertEquals("JOE", foundKeyList.get(0).getKey());
74 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JOS");
75 assertEquals("JOSH", foundKeyList.get(0).getKey());
77 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JOSH");
78 assertEquals("JOSH", foundKeyList.get(0).getKey());
80 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "K");
81 assertEquals("K", foundKeyList.get(0).getKey());
83 foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "L");
84 assertEquals(0, foundKeyList.size());