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 ******************************************************************************/
21 package org.onap.aaf.cadi.util.test;
23 import static org.junit.Assert.*;
24 import static org.hamcrest.CoreMatchers.*;
27 import org.onap.aaf.cadi.util.Split;
29 public class JU_Split {
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(""));
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"));
45 output = Split.split('c', "test", 0, "test".length());
46 assertThat(output.length, is(1));
47 assertThat(output[0], is("test"));
49 assertThat(Split.split('c', null, 0, 0).length, is(0));
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(""));
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(""));
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"));
75 assertThat(Split.splitTrim('c', " te st ", 0, " te st ".length())[0], is("te st"));
77 assertThat(Split.splitTrim('c', null, 0, 0).length, is(0));
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(""));
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"));
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"));
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(""));
104 assertThat(Split.splitTrim('c', null, 0).length, is(0));
108 public void coverageTest() {
109 @SuppressWarnings("unused")
110 Split split = new Split();