summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib
diff options
context:
space:
mode:
authorsiddharth0905 <siddharth.singh4@amdocs.com>2017-12-27 15:28:38 +0530
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2017-12-27 14:42:38 +0000
commit5acfbc6eb741836a63cd75ebc2dfc60c2ff1bc5a (patch)
tree41fe5b6ed8bf529b35b14a3c8203ba2c9c0d197c /openecomp-be/lib
parentb220096e336b0e2bff63f596db3b65878dcd5fe1 (diff)
Fix sonar issues - Common Methods
Junit and Logger removed Change-Id: Ic1a987600a8a5ab8c236be242f0f0cd12faf9624 Issue-ID: SDC-343 Signed-off-by: siddharth0905 <siddharth.singh4@amdocs.com>
Diffstat (limited to 'openecomp-be/lib')
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/CommonMethods.java55
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/CommonMethodsTest.java31
2 files changed, 50 insertions, 36 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/CommonMethods.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/CommonMethods.java
index 81a82c6298..5a17f887d9 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/CommonMethods.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/CommonMethods.java
@@ -1,21 +1,17 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.core.utilities;
@@ -140,7 +136,7 @@ public class CommonMethods {
* @return <tt>true</tt> - if the Object is null, <tt>false</tt> otherwise.
*/
public static boolean isEmpty(byte[] byteArray) {
- return (byteArray == null || byteArray.length == 0);
+ return byteArray == null || byteArray.length == 0;
}
/**
@@ -232,9 +228,10 @@ public class CommonMethods {
}
private static void long2string(long lng, StringBuilder buff) {
+ long value = lng;
for (int i = 0; i < 16; i++) {
- long nextByte = lng & 0xF000000000000000L;
- lng <<= 4;
+ long nextByte = value & 0xF000000000000000L;
+ value <<= 4;
boolean isNegative = nextByte < 0;
nextByte = rightShift(nextByte, 60);
@@ -265,7 +262,7 @@ public class CommonMethods {
*/
@SuppressWarnings("unchecked")
public static <T> T[] concat(T[] left, T[] right) {
- T[] res = null;
+ T[] res;
if (isEmpty(left)) {
res = right;
@@ -365,9 +362,7 @@ public class CommonMethods {
public static <T> T newInstance(Class<T> cls) {
try {
return cls.newInstance();
- } catch (InstantiationException exception) {
- throw new RuntimeException(exception);
- } catch (IllegalAccessException exception) {
+ } catch (InstantiationException | IllegalAccessException exception) {
throw new RuntimeException(exception);
}
}
@@ -380,10 +375,8 @@ public class CommonMethods {
*/
public static String getResourcesPath(String resourceName) {
URL resourceUrl = CommonMethods.class.getClassLoader().getResource(resourceName);
- String resourcePath = resourceUrl.getPath();
- String dirPath = resourcePath.substring(0, resourcePath.lastIndexOf("/") + 1);
-
- return dirPath;
+ return resourceUrl != null ? resourceUrl.getPath()
+ .substring(0, resourceUrl.getPath().lastIndexOf("/") + 1) : null;
}
/**
@@ -407,21 +400,13 @@ public class CommonMethods {
* @return the string
*/
public static String printStackTrace() {
-
- StringWriter sw = new StringWriter();
+ StringBuilder sb = new StringBuilder();
StackTraceElement[] trace = Thread.currentThread().getStackTrace();
for (StackTraceElement traceElement : trace) {
- sw.write("\t " + traceElement);
- sw.write(System.lineSeparator());
+ sb.append("\t ").append(traceElement);
+ sb.append(System.lineSeparator());
}
- String str = sw.toString();
- try {
- sw.close();
- } catch (IOException exception) {
- System.err.println(exception);
- }
- return str;
-
+ return sb.toString();
}
/**
@@ -461,7 +446,7 @@ public class CommonMethods {
*/
public static String collectionToCommaSeparatedString(Collection<String> elementCollection) {
List<String> list = new ArrayList<>();
- elementCollection.stream().forEach(element -> list.add(element));
+ list.addAll(elementCollection);
return listToSeparatedString(list, ',');
}
@@ -509,7 +494,6 @@ public class CommonMethods {
*/
public static String duplicateStringWithDelimiter(String arg, char separator,
int numberOfDuplications) {
- String res = null;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < numberOfDuplications; i++) {
@@ -518,8 +502,7 @@ public class CommonMethods {
}
sb.append(arg);
}
- res = sb.toString();
- return res;
+ return sb.toString();
}
/**
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/CommonMethodsTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/CommonMethodsTest.java
new file mode 100644
index 0000000000..c675f8927f
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/CommonMethodsTest.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.core.utilities;
+
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertTrue;
+
+public class CommonMethodsTest {
+ @Test
+ public void testPrintStackTrace() throws Exception {
+ assertTrue(CommonMethods.printStackTrace().contains("org.openecomp.core.utilities" +
+ ".CommonMethods.printStackTrace(CommonMethods.java:"));
+ assertTrue(CommonMethods.printStackTrace().contains("org.openecomp.core.utilities" +
+ ".CommonMethodsTest.testPrintStackTrace(CommonMethodsTest.java"));
+ }
+}