2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
24 package org.openecomp.appc.util;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
30 import java.util.Properties;
32 import org.junit.Test;
33 import org.openecomp.appc.util.StringHelper;
36 public class TestStringHelper {
39 public void testAsListWithNullList() {
40 String value = StringHelper.asList((String[]) null);
42 assertEquals("[]", value);
46 public void testAsListWithEmptyList() {
47 String value = StringHelper.asList(new String[] {});
49 assertEquals("[]", value);
53 public void testAsListWithSingleValue() {
54 String value = StringHelper.asList("one");
56 assertEquals("[one]", value);
60 public void testAsListWithTwoValues() {
61 String value = StringHelper.asList("one", "two");
63 assertEquals("[one,two]", value);
67 public void testAsListWithFiveValues() {
68 String value = StringHelper.asList("one", "two", "three", "four", "five");
70 assertEquals("[one,two,three,four,five]", value);
74 public void testPropertiesToString() {
80 assertEquals(null, StringHelper.propertiesToString(null));
82 Properties props = new Properties();
84 String result = StringHelper.propertiesToString(props);
85 assertNotNull(result);
86 assertEquals("[ ]", result);
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
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