Add Semicolon at the end
[vid.git] / vid-app-common / src / test / java / org / onap / vid / utils / TreeTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 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.onap.vid.utils;
22
23 import com.google.common.collect.ImmutableList;
24 import org.jetbrains.annotations.NotNull;
25 import org.testng.annotations.DataProvider;
26 import org.testng.annotations.Test;
27
28 import java.util.List;
29
30 import static org.junit.Assert.assertFalse;
31 import static org.testng.Assert.*;
32
33 public class TreeTest {
34
35     @NotNull
36     protected Tree<String> buildTreeForTest() {
37         Tree<String> tree = new Tree<>("a");
38         tree.addPath("b","c","d");
39         tree.addPath("b","cc","dd");
40         tree.addPath("1","2","dd");
41         return tree;
42     }
43
44     @DataProvider
45     public static Object[][] pathsToFind() {
46         return new Object[][]{
47                 {ImmutableList.of("b","c","d"), true},
48                 {ImmutableList.of("b","c"), true},
49                 {ImmutableList.of("b","cc","dd"), true},
50                 {ImmutableList.of("b","cc","d"), false},
51                 {ImmutableList.of("1","2","dd"), true},
52                 {ImmutableList.of("b"), true},
53                 {ImmutableList.of("c"), false},
54                 {ImmutableList.of("z", "z", "z", "z", "z"), false},
55         };
56     }
57
58     @Test(dataProvider="pathsToFind")
59     public void whenBuildTree_nodesFoundsInRoute(List<String> path, boolean isFound) {
60         Tree<String> tree = buildTreeForTest();
61         assertEquals(isFound, tree.isPathExist(path));
62     }
63
64     @Test(dataProvider="pathsToFind")
65     public void whenBuildTree_subTreeGetRight(List<String> path, boolean isFound) {
66         Tree<String> tree = buildTreeForTest();
67         if (isFound) {
68             assertNotNull(tree.getSubTree(path));
69         }
70         else {
71             assertNull(tree.getSubTree(path));
72         }
73     }
74
75     @Test
76     public void whenBuildTree_getSubTreeAsExpected() {
77         Tree<String> tree = buildTreeForTest();
78         Tree<String> subTree = tree.getSubTree("b","c");
79         assertEquals(subTree.getRootValue(), "c");
80         assertTrue(subTree.isPathExist("d"));
81         assertFalse(subTree.isPathExist("b","c","d"));
82     }
83 }