summaryrefslogtreecommitdiffstats
path: root/gson
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-06-12 14:32:25 -0400
committerJim Hahn <jrh3@att.com>2019-06-12 17:36:59 -0400
commitea262e6da52fd4da0733f02998f87aebaf502ddb (patch)
treea7cded567521f0141f31d9f8c185eccdaf2a8979 /gson
parente671e9fa5d09ec696cb24aeefaf10ddbc7c705d7 (diff)
Apply simple sonar fixes
Note: A number of these were identified, by SonarLint, in the Test classes, which are not typically scanned by Sonar. Removed unnecessary imports. Removed unneeded "throws Xxx". Replaced lambda with method references. Replaced duplicate strings with constants. Replaced try-fail-catch with assert-j methods to eliminate sonar complaints about duplicate failure messages. Added missing @Override annotations. Use map.computeIfAbsent() where appropriate. Also fixed some minor checkstyle issues. Removed unneeded "volatile" declarations. Replaced some if-else constructs with "?:" construct, per sonar. Replaced Object.wait() with CountDownLatch.await(); according to sonar (and javadocs), Object.wait() can return due to "spurious wakeups". Fixed issue whereby CryptoUtilsTest wouldn't run in my Eclipse. Change-Id: Ib6b71ed65662cfd6209400dac57ed69279bf29ec Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'gson')
-rw-r--r--gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java4
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/JacksonExclusionStrategyTest.java1
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/JacksonFieldAdapterFactoryTest.java2
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/JacksonMethodAdapterFactoryTest.java2
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/internal/AdapterTest.java17
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/internal/AnyGetterSerializerTest.java5
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/internal/AnySetterDeserializerTest.java1
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/internal/ClassWalkerTest.java20
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/internal/FieldDeserializerTest.java1
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/internal/FieldSerializerTest.java1
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/internal/JacksonTypeAdapterTest.java2
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/internal/LifterTest.java1
12 files changed, 25 insertions, 32 deletions
diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java b/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java
index 65baaee4..c7b3bc98 100644
--- a/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java
+++ b/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java
@@ -59,7 +59,7 @@ public class Adapter {
/**
* Converter used when writing, allocated lazily, once an actual type is determined.
*/
- private volatile ConvInfo writer = null;
+ private ConvInfo writer = null;
/**
* Name of the item being lifted - used when throwing exceptions.
@@ -318,7 +318,7 @@ public class Adapter {
* Converter to use, initialized lazily.
*/
@SuppressWarnings("rawtypes")
- private volatile TypeAdapter conv = null;
+ private TypeAdapter conv = null;
/**
* Constructs the object.
diff --git a/gson/src/test/java/org/onap/policy/common/gson/JacksonExclusionStrategyTest.java b/gson/src/test/java/org/onap/policy/common/gson/JacksonExclusionStrategyTest.java
index 4b5473c5..3ce16964 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/JacksonExclusionStrategyTest.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/JacksonExclusionStrategyTest.java
@@ -33,7 +33,6 @@ import java.util.LinkedList;
import java.util.TreeMap;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.onap.policy.common.gson.JacksonExclusionStrategy;
public class JacksonExclusionStrategyTest {
diff --git a/gson/src/test/java/org/onap/policy/common/gson/JacksonFieldAdapterFactoryTest.java b/gson/src/test/java/org/onap/policy/common/gson/JacksonFieldAdapterFactoryTest.java
index 9d4b4388..bbeb1e26 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/JacksonFieldAdapterFactoryTest.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/JacksonFieldAdapterFactoryTest.java
@@ -32,8 +32,6 @@ import com.google.gson.reflect.TypeToken;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
-import org.onap.policy.common.gson.JacksonExclusionStrategy;
-import org.onap.policy.common.gson.JacksonFieldAdapterFactory;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.common.gson.annotation.GsonJsonProperty;
diff --git a/gson/src/test/java/org/onap/policy/common/gson/JacksonMethodAdapterFactoryTest.java b/gson/src/test/java/org/onap/policy/common/gson/JacksonMethodAdapterFactoryTest.java
index 47cf4b3b..6377420d 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/JacksonMethodAdapterFactoryTest.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/JacksonMethodAdapterFactoryTest.java
@@ -33,8 +33,6 @@ import com.google.gson.reflect.TypeToken;
import java.util.Map;
import java.util.TreeMap;
import org.junit.Test;
-import org.onap.policy.common.gson.JacksonExclusionStrategy;
-import org.onap.policy.common.gson.JacksonMethodAdapterFactory;
import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/AdapterTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/AdapterTest.java
index 04f37164..33160007 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/internal/AdapterTest.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/internal/AdapterTest.java
@@ -34,11 +34,12 @@ import java.util.List;
import org.junit.Test;
import org.onap.policy.common.gson.JacksonExclusionStrategy;
import org.onap.policy.common.gson.annotation.GsonJsonProperty;
-import org.onap.policy.common.gson.internal.Adapter;
import org.onap.policy.common.gson.internal.DataAdapterFactory.Data;
import org.onap.policy.common.gson.internal.DataAdapterFactory.DerivedData;
public class AdapterTest {
+ private static final String EMPTY_ALIAS = "emptyAlias";
+ private static final String GET_VALUE = ".getValue";
private static final String GET_VALUE_NAME = "getValue";
private static final String VALUE_NAME = "value";
private static final String MY_NAME = AdapterTest.class.getName();
@@ -171,9 +172,9 @@ public class AdapterTest {
adapter = new Adapter(gson, mget(GET_VALUE_NAME), String.class);
assertEquals(VALUE_NAME, adapter.getPropName());
- assertEquals(MY_NAME + ".getValue", adapter.getFullName());
+ assertEquals(MY_NAME + GET_VALUE, adapter.getFullName());
- assertEquals("hello: " + MY_NAME + ".getValue", adapter.makeError("hello: "));
+ assertEquals("hello: " + MY_NAME + GET_VALUE, adapter.makeError("hello: "));
// test setter
@@ -201,7 +202,7 @@ public class AdapterTest {
@Test
public void testDetmPropName() {
- assertEquals("emptyAlias", Adapter.detmPropName(field("emptyAlias")));
+ assertEquals(EMPTY_ALIAS, Adapter.detmPropName(field(EMPTY_ALIAS)));
assertEquals("name-with-alias", Adapter.detmPropName(field("nameWithAlias")));
assertEquals("unaliased", Adapter.detmPropName(field("unaliased")));
assertEquals(null, Adapter.detmPropName(field("$invalidFieldName")));
@@ -209,7 +210,7 @@ public class AdapterTest {
@Test
public void testDetmGetterPropName() {
- assertEquals("emptyAlias", Adapter.detmGetterPropName(mget("getEmptyAlias")));
+ assertEquals(EMPTY_ALIAS, Adapter.detmGetterPropName(mget("getEmptyAlias")));
assertEquals("get-with-alias", Adapter.detmGetterPropName(mget("getWithAlias")));
assertEquals("plain", Adapter.detmGetterPropName(mget("getPlain")));
assertEquals("primBool", Adapter.detmGetterPropName(mget("isPrimBool")));
@@ -222,7 +223,7 @@ public class AdapterTest {
@Test
public void testDetmSetterPropName() {
- assertEquals("emptyAlias", Adapter.detmSetterPropName(mset("setEmptyAlias")));
+ assertEquals(EMPTY_ALIAS, Adapter.detmSetterPropName(mset("setEmptyAlias")));
assertEquals("set-with-alias", Adapter.detmSetterPropName(mset("setWithAlias")));
assertEquals("plain", Adapter.detmSetterPropName(mset("setPlain")));
assertEquals(null, Adapter.detmSetterPropName(mset("noSet")));
@@ -236,8 +237,8 @@ public class AdapterTest {
}
@Test
- public void testGetQualifiedNameMethod() throws Exception {
- assertEquals(MY_NAME + ".getValue", Adapter.getQualifiedName(mget(GET_VALUE_NAME)));
+ public void testGetQualifiedNameMethod() {
+ assertEquals(MY_NAME + GET_VALUE, Adapter.getQualifiedName(mget(GET_VALUE_NAME)));
}
/**
diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/AnyGetterSerializerTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/AnyGetterSerializerTest.java
index 75128420..f68e3e3e 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/internal/AnyGetterSerializerTest.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/internal/AnyGetterSerializerTest.java
@@ -36,7 +36,6 @@ import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.gson.JacksonExclusionStrategy;
-import org.onap.policy.common.gson.internal.AnyGetterSerializer;
import org.onap.policy.common.gson.internal.DataAdapterFactory.Data;
public class AnyGetterSerializerTest {
@@ -61,7 +60,7 @@ public class AnyGetterSerializerTest {
}
@Test
- public void testAddToTree_testCopyLiftedItems() throws Exception {
+ public void testAddToTree_testCopyLiftedItems() {
JsonObject tree = new JsonObject();
tree.addProperty("hello", "world");
@@ -84,7 +83,7 @@ public class AnyGetterSerializerTest {
}
@Test
- public void testAddToTree_NullMap() throws Exception {
+ public void testAddToTree_NullMap() {
JsonObject tree = new JsonObject();
tree.addProperty("hello", "world");
diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/AnySetterDeserializerTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/AnySetterDeserializerTest.java
index b180605e..c03e3695 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/internal/AnySetterDeserializerTest.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/internal/AnySetterDeserializerTest.java
@@ -36,7 +36,6 @@ import java.util.TreeMap;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.gson.JacksonExclusionStrategy;
-import org.onap.policy.common.gson.internal.AnySetterDeserializer;
import org.onap.policy.common.gson.internal.DataAdapterFactory.Data;
public class AnySetterDeserializerTest {
diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/ClassWalkerTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/ClassWalkerTest.java
index 1a15be09..6af4ae4f 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/internal/ClassWalkerTest.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/internal/ClassWalkerTest.java
@@ -42,11 +42,11 @@ import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.common.gson.annotation.GsonJsonProperty;
-import org.onap.policy.common.gson.internal.Adapter;
-import org.onap.policy.common.gson.internal.ClassWalker;
public class ClassWalkerTest {
+ private static final String SET_OVERRIDE = ".setOverride";
+
private MyWalker walker;
/**
@@ -63,12 +63,12 @@ public class ClassWalkerTest {
assertEquals("[Intfc1, Intfc2, Intfc1, Intfc3, Bottom, DerivedFromBottom]", walker.classes.toString());
- List<String> inFields = walker.getInProps(Field.class).stream().map(field -> field.getName())
+ List<String> inFields = walker.getInProps(Field.class).stream().map(Field::getName)
.collect(Collectors.toList());
Collections.sort(inFields);
assertEquals("[exposedField, overriddenValue, transField]", inFields.toString());
- List<String> outFields = walker.getInProps(Field.class).stream().map(field -> field.getName())
+ List<String> outFields = walker.getInProps(Field.class).stream().map(Field::getName)
.collect(Collectors.toList());
Collections.sort(outFields);
assertEquals("[exposedField, overriddenValue, transField]", outFields.toString());
@@ -125,7 +125,7 @@ public class ClassWalkerTest {
assertNotNull(walker.getAnyGetter());
assertEquals("getTheMap", walker.getAnyGetter().getName());
- List<String> getters = walker.getOutProps(Method.class).stream().map(method -> method.getName())
+ List<String> getters = walker.getOutProps(Method.class).stream().map(Method::getName)
.collect(Collectors.toList());
Collections.sort(getters);
assertEquals("[getId, getOnlyOut, getValue]", getters.toString());
@@ -133,7 +133,7 @@ public class ClassWalkerTest {
assertNotNull(walker.getAnySetter());
assertEquals("setMapValue", walker.getAnySetter().getName());
- List<String> setters = walker.getInProps(Method.class).stream().map(method -> method.getName())
+ List<String> setters = walker.getInProps(Method.class).stream().map(Method::getName)
.collect(Collectors.toList());
Collections.sort(setters);
assertEquals("[setId, setOnlyIn, setValue]", setters.toString());
@@ -146,17 +146,17 @@ public class ClassWalkerTest {
// setter with too few parameters
assertThatThrownBy(() -> walker.walkClassHierarchy(AnySetterTooFewParams.class))
.isInstanceOf(JsonParseException.class).hasMessage(ClassWalker.ANY_SETTER_MISMATCH_ERR
- + AnySetterTooFewParams.class.getName() + ".setOverride");
+ + AnySetterTooFewParams.class.getName() + SET_OVERRIDE);
// setter with too many parameters
assertThatThrownBy(() -> walker.walkClassHierarchy(AnySetterTooManyParams.class))
.isInstanceOf(JsonParseException.class).hasMessage(ClassWalker.ANY_SETTER_MISMATCH_ERR
- + AnySetterTooManyParams.class.getName() + ".setOverride");
+ + AnySetterTooManyParams.class.getName() + SET_OVERRIDE);
// setter with invalid parameter type
assertThatThrownBy(() -> walker.walkClassHierarchy(AnySetterInvalidParam.class))
.isInstanceOf(JsonParseException.class).hasMessage(ClassWalker.ANY_SETTER_TYPE_ERR
- + AnySetterInvalidParam.class.getName() + ".setOverride");
+ + AnySetterInvalidParam.class.getName() + SET_OVERRIDE);
}
@Test
@@ -317,10 +317,12 @@ public class ClassWalkerTest {
private String value;
+ @Override
public String getValue() {
return value;
}
+ @Override
public void setValue(String value) {
this.value = value;
}
diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/FieldDeserializerTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/FieldDeserializerTest.java
index 62bab231..509ddb79 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/internal/FieldDeserializerTest.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/internal/FieldDeserializerTest.java
@@ -34,7 +34,6 @@ import java.util.List;
import org.junit.Test;
import org.onap.policy.common.gson.JacksonExclusionStrategy;
import org.onap.policy.common.gson.internal.DataAdapterFactory.Data;
-import org.onap.policy.common.gson.internal.FieldDeserializer;
public class FieldDeserializerTest {
private static final String TEXT_FIELD_NAME = "text";
diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/FieldSerializerTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/FieldSerializerTest.java
index 18167fc0..cc5ef928 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/internal/FieldSerializerTest.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/internal/FieldSerializerTest.java
@@ -33,7 +33,6 @@ import java.util.List;
import org.junit.Test;
import org.onap.policy.common.gson.JacksonExclusionStrategy;
import org.onap.policy.common.gson.internal.DataAdapterFactory.Data;
-import org.onap.policy.common.gson.internal.FieldSerializer;
public class FieldSerializerTest {
private static final String TEXT_FIELD_NAME = "text";
diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/JacksonTypeAdapterTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/JacksonTypeAdapterTest.java
index a75fe17e..6be4e590 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/internal/JacksonTypeAdapterTest.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/internal/JacksonTypeAdapterTest.java
@@ -135,7 +135,7 @@ public class JacksonTypeAdapterTest {
String data = stringAdapter.read(new JsonReader(new StringReader("'read text'".replace('\'', '"'))));
- assertEquals("read text", data.toString());
+ assertEquals("read text", data);
}
private static class Data {
diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/LifterTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/LifterTest.java
index 55a3b674..e0b9eb30 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/internal/LifterTest.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/internal/LifterTest.java
@@ -28,7 +28,6 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.junit.Test;
-import org.onap.policy.common.gson.internal.Lifter;
public class LifterTest {