re base code
[sdc.git] / openecomp-be / lib / openecomp-core-lib / openecomp-utilities-lib / src / test / java / org / openecomp / core / utilities / CommonMethodsTest.java
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.*;
25
26 public class CommonMethodsTest {
27
28   private static final String[] ARRAY = { "A", "B", "C" };
29
30   @Test
31   public void testPrintStackTrace() {
32
33     String trace = CommonMethods.printStackTrace();
34     assertTrue(trace.contains("org.openecomp.core.utilities" +
35         ".CommonMethods.printStackTrace(CommonMethods.java:"));
36     assertTrue(trace.contains("org.openecomp.core.utilities" +
37         ".CommonMethodsTest.testPrintStackTrace(CommonMethodsTest.java"));
38   }
39
40   @Test
41   public void testArrayToCommaSeparatedString() {
42     assertEquals(CommonMethods.arrayToCommaSeparatedString(ARRAY), "A,B,C");
43   }
44
45   @Test
46   public void testArrayToCommaSeparatedStringEmpty() {
47     assertEquals(CommonMethods.arrayToCommaSeparatedString(new String[0]), "");
48   }
49
50   @Test
51   public void testArrayToCommaSeparatedStringNulls() {
52     assertEquals(CommonMethods.arrayToCommaSeparatedString(new String[] { null, null }), "null,null");
53   }
54
55   @Test
56   public void testArrayToCommaSeparatedStringEmptyStrings() {
57     assertEquals(CommonMethods.arrayToCommaSeparatedString(new String[] { "", "" }), ",");
58   }
59
60   @Test(expectedExceptions = NullPointerException.class)
61   public void testArrayToCommaSeparatedStringNull() {
62     CommonMethods.arrayToCommaSeparatedString(null);
63   }
64
65   @Test
66   public void testArrayToSeparatedString() {
67     assertEquals(CommonMethods.arrayToSeparatedString(ARRAY, '/'),"A/B/C");
68   }
69
70   @Test
71   public void testArrayToSeparatedStringEmpty() {
72     assertEquals(CommonMethods.arrayToSeparatedString(new String[0], '/'),"");
73   }
74
75   @Test
76   public void testArrayToSeparatedStringNulls() {
77     assertEquals(CommonMethods.arrayToSeparatedString(new String[] {null, null}, '/'),"null/null");
78   }
79
80   @Test
81   public void testArrayToSeparatedStringEmptyStrings() {
82     assertEquals(CommonMethods.arrayToSeparatedString(new String[] {"", ""}, '/'),"/");
83   }
84
85   @Test(expectedExceptions = NullPointerException.class)
86   public void testArrayToSeparatedStringNull() {
87     CommonMethods.arrayToSeparatedString(null, '/');
88   }
89
90   @Test
91   public void testCollectionToCommaSeparatedString() {
92     assertEquals(CommonMethods.collectionToCommaSeparatedString(Arrays.asList(ARRAY)), "A,B,C");
93   }
94
95   @Test
96   public void testCollectionToCommaSeparatedStringNulls() {
97     assertEquals(CommonMethods.collectionToCommaSeparatedString(Arrays.asList(null, null)), "null,null");
98   }
99
100   @Test
101   public void testCollectionToCommaSeparatedStringEmptyStrings() {
102     assertEquals(CommonMethods.collectionToCommaSeparatedString(Arrays.asList("", "")), ",");
103   }
104
105   @Test
106   public void testCollectionToCommaSeparatedStringEmtpy() {
107     assertEquals(CommonMethods.collectionToCommaSeparatedString(Collections.emptySet()), "");
108   }
109
110   @Test(expectedExceptions = NullPointerException.class)
111   public void testCollectionToCommaSeparatedStringNull() {
112     assertNull(CommonMethods.collectionToCommaSeparatedString(null));
113   }
114
115 }