Moving all files to root directory
[appc.git] / appc-common / src / test / java / org / openecomp / appc / util / TestStringHelper.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22
23
24 package org.openecomp.appc.util;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29
30 import java.util.Properties;
31
32 import org.junit.Test;
33 import org.openecomp.appc.util.StringHelper;
34
35
36 public class TestStringHelper {
37
38     @Test
39     public void testAsListWithNullList() {
40         String value = StringHelper.asList((String[]) null);
41         assertNotNull(value);
42         assertEquals("[]", value);
43     }
44
45     @Test
46     public void testAsListWithEmptyList() {
47         String value = StringHelper.asList(new String[] {});
48         assertNotNull(value);
49         assertEquals("[]", value);
50     }
51
52     @Test
53     public void testAsListWithSingleValue() {
54         String value = StringHelper.asList("one");
55         assertNotNull(value);
56         assertEquals("[one]", value);
57     }
58
59     @Test
60     public void testAsListWithTwoValues() {
61         String value = StringHelper.asList("one", "two");
62         assertNotNull(value);
63         assertEquals("[one,two]", value);
64     }
65
66     @Test
67     public void testAsListWithFiveValues() {
68         String value = StringHelper.asList("one", "two", "three", "four", "five");
69         assertNotNull(value);
70         assertEquals("[one,two,three,four,five]", value);
71     }
72
73     @Test
74     public void testPropertiesToString() {
75         String key1 = "key1";
76         String val1 = "val1";
77         String key2 = "key2";
78         String val2 = "val2";
79
80         assertEquals(null, StringHelper.propertiesToString(null));
81
82         Properties props = new Properties();
83
84         String result = StringHelper.propertiesToString(props);
85         assertNotNull(result);
86         assertEquals("[ ]", result);
87
88         props.setProperty(key1, val1);
89         result = StringHelper.propertiesToString(props);
90         assertNotNull(result);
91         assertTrue(result.contains(key1));
92         assertTrue(result.contains(val1));
93         assertTrue(result.lastIndexOf(",") < result.length() - 3); // No trailing comma
94
95         props.setProperty(key2, val2);
96         result = StringHelper.propertiesToString(props);
97         assertNotNull(result);
98         assertTrue(result.contains(key1));
99         assertTrue(result.contains(val1));
100         assertTrue(result.contains(key2));
101         assertTrue(result.contains(val2));
102         assertTrue(result.lastIndexOf(",") < result.length() - 3); // No trailing comma
103     }
104 }