Sonar violation fixes for Parameterized tests and Lambda Expressions
[cli.git] / framework / src / test / java / org / onap / cli / fw / output / print / OnapCommandPrintTest.java
1 /*
2  * Copyright 2017 Huawei Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.cli.fw.output.print;
18
19 import static org.junit.Assert.assertEquals;
20
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collection;
24
25 import org.junit.Ignore;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.Parameterized;
29 import org.onap.cli.fw.error.OnapCommandOutputPrintingFailed;
30 import org.onap.cli.fw.output.OnapCommandPrintDirection;
31
32 @RunWith(Parameterized.class)
33 public class OnapCommandPrintTest {
34     private String expected;
35     private String colValue1;
36     private String colValue2;
37
38
39     public OnapCommandPrintTest(String expected, String colValue1, String colValue2) {
40         this.expected = expected;
41         this.colValue1 = colValue1;
42         this.colValue2 = colValue2;
43     }
44
45     @Parameterized.Parameters
46     public static Collection testUtilParams() {
47         return Arrays.asList(new Object[][]{ {"+--------+\n|name2   |\n+--------+\n|value2  |\n+--------+\n", "name2", "value2"},
48                 {"+--------+\n|name2   |\n+--------+\n|value2  |\n+--------+\n", "name2", "value2"},
49                 {"+--------+\n|name2   |\n+--------+\n|        |\n+--------+\n", "name2", ""} });
50     }
51
52
53     /**
54      * Tests involved:
55      * 1. printTableTest
56      * 2. printTableNullColumnHeaderTest
57      * 3. printTableEmptyColumnValuesTest
58      * @throws OnapCommandOutputPrintingFailed
59      */
60     @Test
61     public void printableTests() throws OnapCommandOutputPrintingFailed {
62         OnapCommandPrint pr = new OnapCommandPrint();
63         pr.setDirection(OnapCommandPrintDirection.LANDSCAPE);
64         pr.setPrintTitle(true);
65         pr.addColumn(this.colValue1, new ArrayList<String>(Arrays.asList(new String[] { this.colValue2 })));
66         String exp = this.expected;
67         String result = pr.printTable(true);
68         assertEquals(exp, result);
69     }
70
71     @Test
72     @Ignore
73     public void printCsvTest() throws OnapCommandOutputPrintingFailed { //NOSONAR
74         OnapCommandPrint pr = new OnapCommandPrint();
75         pr.setDirection(OnapCommandPrintDirection.LANDSCAPE);
76         pr.setPrintTitle(true);
77         pr.addColumn("name1", new ArrayList<String>(Arrays.asList(new String[] { "value1" })));
78         String exp = "name1\r\n";
79         String result = pr.printCsv();
80         assertEquals(exp, result);
81     }
82 }