791a4dcf95b3fc046fe51cf361c7a1e05c794b93
[policy/apex-pdp.git] / model / utilities / src / test / java / org / onap / policy / apex / model / utilities / TreeMapUtilsTest.java
1 /*
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.model.utilities;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.util.List;
26 import java.util.Map.Entry;
27 import java.util.TreeMap;
28
29 import org.junit.Test;
30 import org.onap.policy.apex.model.utilities.TreeMapUtils;
31
32 /**
33  * Test the tree map utilities.
34  * @author Liam Fallon (liam.fallon@ericsson.com)
35  */
36 public class TreeMapUtilsTest {
37
38     @Test
39     public void test() {
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");
48         
49         List<Entry<String, String>> foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "F");
50         assertEquals(0, foundKeyList.size());
51
52         foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "G");
53         assertEquals("G", foundKeyList.get(0).getKey());
54
55         foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "H");
56         assertEquals("H", foundKeyList.get(0).getKey());
57  
58         foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "I");
59         assertEquals(0, foundKeyList.size());
60         
61         foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "J");
62         assertEquals("JA", foundKeyList.get(0).getKey());
63         
64         foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JA");
65         assertEquals("JA", foundKeyList.get(0).getKey());
66         
67         foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JB");
68         assertEquals(0, foundKeyList.size());
69
70         foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JO");
71         assertEquals("JOE", foundKeyList.get(0).getKey());
72         
73         foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JOE");
74         assertEquals("JOE", foundKeyList.get(0).getKey());
75         
76         foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JOS");
77         assertEquals("JOSH", foundKeyList.get(0).getKey());
78         
79         foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JOSH");
80         assertEquals("JOSH", foundKeyList.get(0).getKey());
81         
82         foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "K");
83         assertEquals("K", foundKeyList.get(0).getKey());
84         
85         foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "L");
86         assertEquals(0, foundKeyList.size());
87     }
88 }