Sonar Fixes, Formatting
[aaf/authz.git] / cadi / core / src / test / java / org / onap / aaf / cadi / util / test / JU_Split.java
1 /*******************************************************************************
2  * * org.onap.aaf
3  * * ===========================================================================
4  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
5  * * ===========================================================================
6  * * Licensed under the Apache License, Version 2.0 (the "License");
7  * * you may not use this file except in compliance with the License.
8  * * You may obtain a copy of the License at
9  * *
10  *  *      http://www.apache.org/licenses/LICENSE-2.0
11  * *
12  *  * Unless required by applicable law or agreed to in writing, software
13  * * distributed under the License is distributed on an "AS IS" BASIS,
14  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * * See the License for the specific language governing permissions and
16  * * limitations under the License.
17  * * ============LICENSE_END====================================================
18  * *
19  * *
20  ******************************************************************************/
21
22 package org.onap.aaf.cadi.util.test;
23
24 import static org.junit.Assert.*;
25 import static org.hamcrest.CoreMatchers.*;
26 import org.junit.*;
27
28 import org.onap.aaf.cadi.util.Split;
29
30 public class JU_Split {
31
32     @Test
33     public void splitTest() {
34         String[] output = Split.split('c', "ctestctc", 0, "ctestctc".length());
35         assertThat(output.length, is(4));
36         assertThat(output[0], is(""));
37         assertThat(output[1], is("test"));
38         assertThat(output[2], is("t"));
39         assertThat(output[3], is(""));
40
41         output = Split.split('c', "ctestctc", 0, 4);
42         assertThat(output.length, is(2));
43         assertThat(output[0], is(""));
44         assertThat(output[1], is("tes"));
45
46         output = Split.split('c', "test", 0, "test".length());
47         assertThat(output.length, is(1));
48         assertThat(output[0], is("test"));
49
50         assertThat(Split.split('c', null, 0, 0).length, is(0));
51
52         // Test with fewer arguments
53         output = Split.split('c', "ctestctc");
54         assertThat(output.length, is(4));
55         assertThat(output[0], is(""));
56         assertThat(output[1], is("test"));
57         assertThat(output[2], is("t"));
58         assertThat(output[3], is(""));
59     }
60
61     @Test
62     public void splitTrimTest() {
63         String[] output = Split.splitTrim('c', " cte stc ctc ", 0, " cte stc ctc ".length());
64         assertThat(output.length, is(5));
65         assertThat(output[0], is(""));
66         assertThat(output[1], is("te st"));
67         assertThat(output[2], is(""));
68         assertThat(output[3], is("t"));
69         assertThat(output[4], is(""));
70
71         output = Split.splitTrim('c', " cte stc ctc ", 0, 5);
72         assertThat(output.length, is(2));
73         assertThat(output[0], is(""));
74         assertThat(output[1], is("te"));
75
76         assertThat(Split.splitTrim('c', " te st ", 0, " te st ".length())[0], is("te st"));
77
78         assertThat(Split.splitTrim('c', null, 0, 0).length, is(0));
79
80         // Test with 2 arguments
81         output = Split.splitTrim('c', " cte stc ctc ");
82         assertThat(output.length, is(5));
83         assertThat(output[0], is(""));
84         assertThat(output[1], is("te st"));
85         assertThat(output[2], is(""));
86         assertThat(output[3], is("t"));
87         assertThat(output[4], is(""));
88
89         // Tests with 1 argument
90         output = Split.splitTrim('c', " cte stc ctc ", 1);
91         assertThat(output.length, is(1));
92         assertThat(output[0], is("cte stc ctc"));
93
94         output = Split.splitTrim('c', "testctest2", 2);
95         assertThat(output.length, is(2));
96         assertThat(output[0], is("test"));
97         assertThat(output[1], is("test2"));
98
99         output = Split.splitTrim('c', " cte stc ctc ", 4);
100         assertThat(output.length, is(4));
101         assertThat(output[0], is(""));
102         assertThat(output[1], is("te st"));
103         assertThat(output[2], is(""));
104
105         assertThat(Split.splitTrim('c', null, 0).length, is(0));
106     }
107
108     @Test
109     public void coverageTest() {
110         @SuppressWarnings("unused")
111         Split split = new Split();
112     }
113
114 }