aboutsummaryrefslogtreecommitdiffstats
path: root/utils-test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-05-06 11:28:53 -0400
committerJim Hahn <jrh3@att.com>2021-05-06 15:26:24 -0400
commit1d0aaaa5b31719c1718700bb0d1a99c413fd513c (patch)
treebd2687f1d38f3e3c4e53a68695c8c91c6866468e /utils-test
parent3b00f1c32b89282dcbb74d3d3645e263f005319e (diff)
Fix sonars in policy-common
Fixed sonars: - use "var" instead of actual type name - re-interrupt threads - use rej2 split() instead of String split() Issue-ID: POLICY-3285 Change-Id: I82261e0b8a53ee5c5264556fbf5cec37454f014e Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'utils-test')
-rw-r--r--utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java14
-rw-r--r--utils-test/src/main/java/org/onap/policy/common/utils/io/Serializer.java10
-rw-r--r--utils-test/src/main/java/org/onap/policy/common/utils/security/SelfSignedKeyStore.java6
-rw-r--r--utils-test/src/main/java/org/onap/policy/common/utils/test/ExceptionsTester.java12
-rw-r--r--utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java20
-rw-r--r--utils-test/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java6
-rw-r--r--utils-test/src/main/java/org/onap/policy/common/utils/time/PseudoExecutor.java4
-rw-r--r--utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java2
8 files changed, 36 insertions, 38 deletions
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java b/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java
index e267179e..1357a51f 100644
--- a/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java
+++ b/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java
@@ -27,12 +27,10 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
-import com.google.re2j.Matcher;
import com.google.re2j.Pattern;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
@@ -127,7 +125,7 @@ public class GsonTestUtils {
*/
public void compareGson(Object object, File expected) {
// file is not required to have a full path - find it via getResource()
- URL url = object.getClass().getResource(expected.getName());
+ var url = object.getClass().getResource(expected.getName());
if (url == null) {
throw new JsonParseException(new FileNotFoundException(expected.getName()));
}
@@ -197,7 +195,7 @@ public class GsonTestUtils {
* @return the text, after interpolating the script elements
*/
public String applyScripts(String text, Object object) {
- Matcher mat = SCRIPT_PAT.matcher(text);
+ var mat = SCRIPT_PAT.matcher(text);
if (!mat.find()) {
// contains no script elements - just return it as is
return text;
@@ -209,8 +207,8 @@ public class GsonTestUtils {
context.set("obj", object);
// work our way through the text, interpolating script elements as we go
- StringBuilder bldr = new StringBuilder();
- int ilast = 0;
+ var bldr = new StringBuilder();
+ var ilast = 0;
mat.reset();
while (mat.find(ilast)) {
// append segment that appears between last match and this
@@ -275,7 +273,7 @@ public class GsonTestUtils {
* @return a new object, without the null items
*/
public JsonObject reorder(JsonObject jsonObj) {
- JsonObject newjo = new JsonObject();
+ var newjo = new JsonObject();
// sort the keys before copying to the new object
List<Entry<String, JsonElement>> sortedSet = new ArrayList<>(jsonObj.entrySet());
@@ -301,7 +299,7 @@ public class GsonTestUtils {
* @return a new array, with null items removed from all elements
*/
public JsonArray reorder(JsonArray jsonArray) {
- JsonArray newarr = new JsonArray();
+ var newarr = new JsonArray();
for (JsonElement ent : jsonArray) {
newarr.add(reorder(ent));
}
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/io/Serializer.java b/utils-test/src/main/java/org/onap/policy/common/utils/io/Serializer.java
index 7e09cd96..39266a66 100644
--- a/utils-test/src/main/java/org/onap/policy/common/utils/io/Serializer.java
+++ b/utils-test/src/main/java/org/onap/policy/common/utils/io/Serializer.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine - Common Modules
* ================================================================================
- * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,8 +51,8 @@ public class Serializer {
* @throws IOException if an error occurs
*/
public static <T> byte[] serialize(T object) throws IOException {
- try (ByteArrayOutputStream out = factory.makeByteArrayOutputStream()) {
- try (ObjectOutputStream oos = factory.makeObjectOutputStream(out)) {
+ try (var out = factory.makeByteArrayOutputStream()) {
+ try (var oos = factory.makeObjectOutputStream(out)) {
/*
* writeObject() is final and mockito can't mock final methods. In
* addition, powermock seemed to be having difficulty with the junit test
@@ -75,8 +75,8 @@ public class Serializer {
*/
private static <T> T deserialize(Class<T> clazz, byte[] data) throws IOException {
- try (ByteArrayInputStream in = factory.makeByteArrayInputStream(data);
- ObjectInputStream ois = factory.makeObjectInputStream(in)) {
+ try (var in = factory.makeByteArrayInputStream(data);
+ var ois = factory.makeObjectInputStream(in)) {
/*
* readObject() is final and mockito can't mock final methods. In addition,
* powermock seemed to be having difficulty with the junit test class as well,
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/security/SelfSignedKeyStore.java b/utils-test/src/main/java/org/onap/policy/common/utils/security/SelfSignedKeyStore.java
index cc0fed07..11dff4b4 100644
--- a/utils-test/src/main/java/org/onap/policy/common/utils/security/SelfSignedKeyStore.java
+++ b/utils-test/src/main/java/org/onap/policy/common/utils/security/SelfSignedKeyStore.java
@@ -70,7 +70,7 @@ public class SelfSignedKeyStore {
keystoreName = System.getProperty("user.dir") + "/" + relativePath;
// use existing file if it isn't too old
- File keystore = new File(keystoreName);
+ var keystore = new File(keystoreName);
if (keystore.exists()) {
if (System.currentTimeMillis() < keystore.lastModified()
+ TimeUnit.MILLISECONDS.convert(5, TimeUnit.HOURS)) {
@@ -85,7 +85,7 @@ public class SelfSignedKeyStore {
* dropping the trailing comma.
*/
String sanName = getKeystoreSanName();
- String subAltNames = ResourceUtils.getResourceAsString(sanName);
+ var subAltNames = ResourceUtils.getResourceAsString(sanName);
if (subAltNames == null) {
throw new FileNotFoundException(sanName);
}
@@ -96,7 +96,7 @@ public class SelfSignedKeyStore {
// build up the "keytool" command
// @formatter:off
- ProcessBuilder builder = new ProcessBuilder("keytool", "-genkeypair",
+ var builder = new ProcessBuilder("keytool", "-genkeypair",
"-alias", "policy@policy.onap.org",
"-validity", "1",
"-keyalg", "RSA",
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/test/ExceptionsTester.java b/utils-test/src/main/java/org/onap/policy/common/utils/test/ExceptionsTester.java
index f457dd21..1ab1f285 100644
--- a/utils-test/src/main/java/org/onap/policy/common/utils/test/ExceptionsTester.java
+++ b/utils-test/src/main/java/org/onap/policy/common/utils/test/ExceptionsTester.java
@@ -2,7 +2,7 @@
* ============LICENSE_START====================================================
* Common Utils-Test
* =============================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2021 AT&T Intellectual Property. All rights reserved.
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,7 +70,7 @@ public class ExceptionsTester extends ThrowablesTester {
* if the constructed objects fail to pass various tests
*/
public <T extends Exception> int testAllException(final Class<T> claz) {
- int ncons = 0;
+ var ncons = 0;
ncons += testAllThrowable(claz);
ncons += testException(claz);
@@ -111,8 +111,8 @@ public class ExceptionsTester extends ThrowablesTester {
return 0;
}
- Exception cause = new Exception(EXPECTED_EXCEPTION_MSG);
- T ex = newInstance(cons, cause);
+ var cause = new Exception(EXPECTED_EXCEPTION_MSG);
+ var ex = newInstance(cons, cause);
assertNotNull(ex.toString());
assertEquals(ex.getMessage(), ex.getMessage());
@@ -151,8 +151,8 @@ public class ExceptionsTester extends ThrowablesTester {
return 0;
}
- Exception cause = new Exception(EXPECTED_EXCEPTION_MSG);
- T ex = newInstance(cons, "world", cause);
+ var cause = new Exception(EXPECTED_EXCEPTION_MSG);
+ var ex = newInstance(cons, "world", cause);
assertNotNull(ex.toString());
assertEquals("world", ex.getMessage());
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java b/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java
index fd819b25..06ca8046 100644
--- a/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java
+++ b/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java
@@ -2,7 +2,7 @@
* ============LICENSE_START====================================================
* Common Utils-Test
* =============================================================================
- * Copyright (C) 2018, 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2020-2021 AT&T Intellectual Property. All rights reserved.
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -73,7 +73,7 @@ public class ThrowablesTester {
*/
public final <T extends Throwable> int testAllThrowable(
final Class<T> claz) {
- int ncons = 0;
+ var ncons = 0;
ncons += testDefault(claz);
ncons += testString(claz);
@@ -112,7 +112,7 @@ public class ThrowablesTester {
return 0;
}
- T ex = newInstance(cons);
+ var ex = newInstance(cons);
assertNotNull(ex.toString());
assertNull(ex.getMessage());
@@ -151,7 +151,7 @@ public class ThrowablesTester {
return 0;
}
- T ex = newInstance(cons, "hello");
+ var ex = newInstance(cons, "hello");
assertNotNull(ex.toString());
assertEquals("hello", ex.getMessage());
@@ -191,7 +191,7 @@ public class ThrowablesTester {
return 0;
}
- T ex = newInstance(cons, CAUSE);
+ var ex = newInstance(cons, CAUSE);
assertEquals(ex.getMessage(), ex.getMessage());
assertNotNull(ex.toString());
@@ -231,7 +231,7 @@ public class ThrowablesTester {
return 0;
}
- T ex = newInstance(cons, "world", CAUSE);
+ var ex = newInstance(cons, "world", CAUSE);
assertNotNull(ex.toString());
assertEquals("world", ex.getMessage());
@@ -382,7 +382,7 @@ public class ThrowablesTester {
*/
public final <T extends Throwable> void testSuppressStack(
final Constructor<T> cons) {
- T ex = newInstance(cons, "yes,yes", CAUSE, true, true);
+ var ex = newInstance(cons, "yes,yes", CAUSE, true, true);
ex.addSuppressed(SUPPRESSED);
@@ -420,7 +420,7 @@ public class ThrowablesTester {
*/
public final <T extends Throwable> void testSuppressNoStack(
final Constructor<T> cons) {
- T ex = newInstance(cons, "yes,no", CAUSE, true, false);
+ var ex = newInstance(cons, "yes,no", CAUSE, true, false);
ex.addSuppressed(SUPPRESSED);
@@ -458,7 +458,7 @@ public class ThrowablesTester {
*/
public final <T extends Throwable> void testNoSuppressStack(
final Constructor<T> cons) {
- T ex = newInstance(cons, "no,yes", CAUSE, false, true);
+ var ex = newInstance(cons, "no,yes", CAUSE, false, true);
ex.addSuppressed(SUPPRESSED);
@@ -494,7 +494,7 @@ public class ThrowablesTester {
*/
public final <T extends Throwable> void testNoSuppressNoStack(
final Constructor<T> cons) {
- T ex = newInstance(cons, "no,no", CAUSE, false, false);
+ var ex = newInstance(cons, "no,no", CAUSE, false, false);
ex.addSuppressed(SUPPRESSED);
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java b/utils-test/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java
index 19c50968..887cec9b 100644
--- a/utils-test/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java
+++ b/utils-test/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java
@@ -2,7 +2,7 @@
* ============LICENSE_START====================================================
* Common Utils-Test
* =============================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019, 2021 AT&T Intellectual Property. All rights reserved.
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -110,7 +110,7 @@ public class ExtractAppender extends AppenderBase<ILoggingEvent> {
}
for (Pattern p : patterns.values()) {
- Matcher matcher = p.matcher(msg);
+ var matcher = p.matcher(msg);
if (matcher.find()) {
addGroupMatch(matcher);
@@ -129,7 +129,7 @@ public class ExtractAppender extends AppenderBase<ILoggingEvent> {
private void addGroupMatch(final Matcher mat) {
int ngroups = mat.groupCount();
- for (int x = 1; x <= ngroups; ++x) {
+ for (var x = 1; x <= ngroups; ++x) {
String txt = mat.group(x);
if (txt != null) {
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/time/PseudoExecutor.java b/utils-test/src/main/java/org/onap/policy/common/utils/time/PseudoExecutor.java
index d8b792a8..b29f7421 100644
--- a/utils-test/src/main/java/org/onap/policy/common/utils/time/PseudoExecutor.java
+++ b/utils-test/src/main/java/org/onap/policy/common/utils/time/PseudoExecutor.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,7 +61,7 @@ public class PseudoExecutor implements Executor {
* tasks have been reached before the queue was emptied
*/
public boolean runAll(int maxTasks) {
- for (int count = 0; count < maxTasks && !tasks.isEmpty(); ++count) {
+ for (var count = 0; count < maxTasks && !tasks.isEmpty(); ++count) {
tasks.remove().run();
}
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java b/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java
index 54ec601a..9e61eaa3 100644
--- a/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java
+++ b/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java
@@ -282,7 +282,7 @@ public class TestTimeMulti extends TestTime {
return;
}
- SleepItem item = new SleepItem(this, sleepMs, Thread.currentThread());
+ var item = new SleepItem(this, sleepMs, Thread.currentThread());
enqueue(item);
// wait for the item to fire