ff3584a8a1d7776381423d6666369817b47525df
[sdc.git] /
1 /*
2  * Copyright © 2016-2017 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.core.utilities;
18
19 import org.testng.annotations.Test;
20
21 import java.util.Arrays;
22 import java.util.Collections;
23
24 import static org.testng.Assert.assertEquals;
25 import static org.testng.Assert.assertNull;
26 import static org.testng.Assert.assertTrue;
27
28 public class CommonMethodsTest {
29
30   private static final String[] ARRAY = { "A", "B", "C" };
31
32   @Test
33   public void testPrintStackTrace() {
34
35     String trace = CommonMethods.printStackTrace();
36     assertTrue(trace.contains("org.openecomp.core.utilities" +
37         ".CommonMethods.printStackTrace(CommonMethods.java:"));
38     assertTrue(trace.contains("org.openecomp.core.utilities" +
39         ".CommonMethodsTest.testPrintStackTrace(CommonMethodsTest.java"));
40   }
41
42   @Test
43   public void testArrayToCommaSeparatedString() {
44     assertEquals(CommonMethods.arrayToCommaSeparatedString(ARRAY), "A,B,C");
45   }
46
47   @Test
48   public void testArrayToCommaSeparatedStringEmpty() {
49     assertEquals(CommonMethods.arrayToCommaSeparatedString(new String[0]), "");
50   }
51
52   @Test
53   public void testArrayToCommaSeparatedStringNulls() {
54     assertEquals(CommonMethods.arrayToCommaSeparatedString(new String[] { null, null }), "null,null");
55   }
56
57   @Test
58   public void testArrayToCommaSeparatedStringEmptyStrings() {
59     assertEquals(CommonMethods.arrayToCommaSeparatedString(new String[] { "", "" }), ",");
60   }
61
62   @Test(expectedExceptions = NullPointerException.class)
63   public void testArrayToCommaSeparatedStringNull() {
64     CommonMethods.arrayToCommaSeparatedString(null);
65   }
66
67   @Test
68   public void testArrayToSeparatedString() {
69     assertEquals(CommonMethods.arrayToSeparatedString(ARRAY, '/'),"A/B/C");
70   }
71
72   @Test
73   public void testArrayToSeparatedStringEmpty() {
74     assertEquals(CommonMethods.arrayToSeparatedString(new String[0], '/'),"");
75   }
76
77   @Test
78   public void testArrayToSeparatedStringNulls() {
79     assertEquals(CommonMethods.arrayToSeparatedString(new String[] {null, null}, '/'),"null/null");
80   }
81
82   @Test
83   public void testArrayToSeparatedStringEmptyStrings() {
84     assertEquals(CommonMethods.arrayToSeparatedString(new String[] {"", ""}, '/'),"/");
85   }
86
87   @Test(expectedExceptions = NullPointerException.class)
88   public void testArrayToSeparatedStringNull() {
89     CommonMethods.arrayToSeparatedString(null, '/');
90   }
91
92   @Test
93   public void testCollectionToCommaSeparatedString() {
94     assertEquals(CommonMethods.collectionToCommaSeparatedString(Arrays.asList(ARRAY)), "A,B,C");
95   }
96
97   @Test
98   public void testCollectionToCommaSeparatedStringNulls() {
99     assertEquals(CommonMethods.collectionToCommaSeparatedString(Arrays.asList(null, null)), "null,null");
100   }
101
102   @Test
103   public void testCollectionToCommaSeparatedStringEmptyStrings() {
104     assertEquals(CommonMethods.collectionToCommaSeparatedString(Arrays.asList("", "")), ",");
105   }
106
107   @Test
108   public void testCollectionToCommaSeparatedStringEmtpy() {
109     assertEquals(CommonMethods.collectionToCommaSeparatedString(Collections.emptySet()), "");
110   }
111
112   @Test(expectedExceptions = NullPointerException.class)
113   public void testCollectionToCommaSeparatedStringNull() {
114     assertNull(CommonMethods.collectionToCommaSeparatedString(null));
115   }
116
117 }