12be4e15f5d870df573b8178842e3b272d56957e
[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 package org.onap.aaf.cadi.util.test;
22
23 import static org.junit.Assert.*;
24 import static org.hamcrest.CoreMatchers.*;
25 import org.junit.*;
26
27 import org.onap.aaf.cadi.util.Split;
28
29 public class JU_Split {
30
31         @Test
32         public void splitTest() {
33                 String[] output = Split.split('c', "ctestctc", 0, "ctestctc".length());
34                 assertThat(output.length, is(4));
35                 assertThat(output[0], is(""));
36                 assertThat(output[1], is("test"));
37                 assertThat(output[2], is("t"));
38                 assertThat(output[3], is(""));
39
40                 output = Split.split('c', "ctestctc", 0, 4);
41                 assertThat(output.length, is(2));
42                 assertThat(output[0], is(""));
43                 assertThat(output[1], is("tes"));
44
45         output = Split.split('c', "test", 0, "test".length());
46                 assertThat(output.length, is(1));
47                 assertThat(output[0], is("test"));
48
49                 assertThat(Split.split('c', null, 0, 0).length, is(0));
50
51         // Test with fewer arguments
52                 output = Split.split('c', "ctestctc");
53                 assertThat(output.length, is(4));
54                 assertThat(output[0], is(""));
55                 assertThat(output[1], is("test"));
56                 assertThat(output[2], is("t"));
57                 assertThat(output[3], is(""));
58         }
59
60         @Test
61         public void splitTrimTest() {
62                 String[] output = Split.splitTrim('c', " cte stc ctc ", 0, " cte stc ctc ".length());
63                 assertThat(output.length, is(5));
64                 assertThat(output[0], is(""));
65                 assertThat(output[1], is("te st"));
66                 assertThat(output[2], is(""));
67                 assertThat(output[3], is("t"));
68                 assertThat(output[4], is(""));
69
70                 output = Split.splitTrim('c', " cte stc ctc ", 0, 5);
71                 assertThat(output.length, is(2));
72                 assertThat(output[0], is(""));
73                 assertThat(output[1], is("te"));
74
75                 assertThat(Split.splitTrim('c', " te st ", 0, " te st ".length())[0], is("te st"));
76
77         assertThat(Split.splitTrim('c', null, 0, 0).length, is(0));
78
79                 // Test with 2 arguments
80                 output = Split.splitTrim('c', " cte stc ctc ");
81                 assertThat(output.length, is(5));
82                 assertThat(output[0], is(""));
83                 assertThat(output[1], is("te st"));
84                 assertThat(output[2], is(""));
85                 assertThat(output[3], is("t"));
86                 assertThat(output[4], is(""));
87
88                 // Tests with 1 argument
89                 output = Split.splitTrim('c', " cte stc ctc ", 1);
90                 assertThat(output.length, is(1));
91                 assertThat(output[0], is("cte stc ctc"));
92
93                 output = Split.splitTrim('c', "testctest2", 2);
94                 assertThat(output.length, is(2));
95                 assertThat(output[0], is("test"));
96                 assertThat(output[1], is("test2"));
97
98                 output = Split.splitTrim('c', " cte stc ctc ", 4);
99                 assertThat(output.length, is(4));
100                 assertThat(output[0], is(""));
101                 assertThat(output[1], is("te st"));
102                 assertThat(output[2], is(""));
103
104                 assertThat(Split.splitTrim('c', null, 0).length, is(0));
105         }
106         
107         @Test
108         public void coverageTest() {
109                 @SuppressWarnings("unused")
110                 Split split = new Split();
111         }
112
113 }