1 /*******************************************************************************
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
10 * * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
20 ******************************************************************************/
22 package org.onap.aaf.cadi.util.test;
24 import static org.junit.Assert.*;
25 import static org.hamcrest.CoreMatchers.*;
28 import org.onap.aaf.cadi.util.Split;
30 public class JU_Split {
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(""));
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"));
46 output = Split.split('c', "test", 0, "test".length());
47 assertThat(output.length, is(1));
48 assertThat(output[0], is("test"));
50 assertThat(Split.split('c', null, 0, 0).length, is(0));
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(""));
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(""));
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"));
76 assertThat(Split.splitTrim('c', " te st ", 0, " te st ".length())[0], is("te st"));
78 assertThat(Split.splitTrim('c', null, 0, 0).length, is(0));
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(""));
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"));
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"));
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(""));
105 assertThat(Split.splitTrim('c', null, 0).length, is(0));
109 public void coverageTest() {
110 @SuppressWarnings("unused")
111 Split split = new Split();