2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
27 package org.openecomp.appc.util;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNotNull;
31 import static org.junit.Assert.assertTrue;
33 import java.util.Properties;
35 import org.junit.Test;
36 import org.openecomp.appc.util.StringHelper;
39 public class TestStringHelper {
42 public void testAsListWithNullList() {
43 String value = StringHelper.asList((String[]) null);
45 assertEquals("[]", value);
49 public void testAsListWithEmptyList() {
50 String value = StringHelper.asList(new String[] {});
52 assertEquals("[]", value);
56 public void testAsListWithSingleValue() {
57 String value = StringHelper.asList("one");
59 assertEquals("[one]", value);
63 public void testAsListWithTwoValues() {
64 String value = StringHelper.asList("one", "two");
66 assertEquals("[one,two]", value);
70 public void testAsListWithFiveValues() {
71 String value = StringHelper.asList("one", "two", "three", "four", "five");
73 assertEquals("[one,two,three,four,five]", value);
77 public void testPropertiesToString() {
83 assertEquals(null, StringHelper.propertiesToString(null));
85 Properties props = new Properties();
87 String result = StringHelper.propertiesToString(props);
88 assertNotNull(result);
89 assertEquals("[ ]", result);
91 props.setProperty(key1, val1);
92 result = StringHelper.propertiesToString(props);
93 assertNotNull(result);
94 assertTrue(result.contains(key1));
95 assertTrue(result.contains(val1));
96 assertTrue(result.lastIndexOf(",") < result.length() - 3); // No trailing comma
98 props.setProperty(key2, val2);
99 result = StringHelper.propertiesToString(props);
100 assertNotNull(result);
101 assertTrue(result.contains(key1));
102 assertTrue(result.contains(val1));
103 assertTrue(result.contains(key2));
104 assertTrue(result.contains(val2));
105 assertTrue(result.lastIndexOf(",") < result.length() - 3); // No trailing comma