aboutsummaryrefslogtreecommitdiffstats
path: root/gson/src/test/java/org/onap/policy/common/gson/internal
diff options
context:
space:
mode:
Diffstat (limited to 'gson/src/test/java/org/onap/policy/common/gson/internal')
-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/DataAdapterFactory.java15
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/internal/FieldDeserializerTest.java10
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/internal/FieldSerializerTest.java6
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/internal/JacksonTypeAdapterTest.java9
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/internal/MethodAdapterTest.java11
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/internal/MethodDeserializerTest.java7
-rw-r--r--gson/src/test/java/org/onap/policy/common/gson/internal/MethodSerializerTest.java7
8 files changed, 36 insertions, 46 deletions
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 9d80c860..fd999951 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
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +43,7 @@ import org.onap.policy.common.gson.annotation.GsonJsonProperty;
import org.onap.policy.common.gson.internal.Adapter.Factory;
import org.onap.policy.common.gson.internal.DataAdapterFactory.Data;
import org.onap.policy.common.gson.internal.DataAdapterFactory.DerivedData;
-import org.powermock.reflect.Whitebox;
+import org.springframework.test.util.ReflectionTestUtils;
public class AdapterTest {
private static final String GET_INVALID_NAME = "get$InvalidName";
@@ -83,12 +84,12 @@ public class AdapterTest {
@BeforeClass
public static void setUpBeforeClass() {
- saveFactory = Whitebox.getInternalState(Adapter.class, FACTORY_FIELD);
+ saveFactory = (Factory) ReflectionTestUtils.getField(Adapter.class, FACTORY_FIELD);
}
@After
public void tearDown() {
- Whitebox.setInternalState(Adapter.class, FACTORY_FIELD, saveFactory);
+ ReflectionTestUtils.setField(Adapter.class, FACTORY_FIELD, saveFactory);
}
@Test
@@ -98,7 +99,7 @@ public class AdapterTest {
// return an invalid field name
Factory factory = mock(Factory.class);
when(factory.getName(any(Field.class))).thenReturn("$invalidFieldName");
- Whitebox.setInternalState(Adapter.class, FACTORY_FIELD, factory);
+ ReflectionTestUtils.setField(Adapter.class, FACTORY_FIELD, factory);
assertFalse(Adapter.isManaged(field(VALUE_NAME)));
}
@@ -108,7 +109,7 @@ public class AdapterTest {
// return an invalid method name
Factory factory = mock(Factory.class);
- Whitebox.setInternalState(Adapter.class, FACTORY_FIELD, factory);
+ ReflectionTestUtils.setField(Adapter.class, FACTORY_FIELD, factory);
when(factory.getName(any(Method.class))).thenReturn(GET_INVALID_NAME);
assertFalse(Adapter.isManaged(mget(GET_VALUE_NAME)));
@@ -240,7 +241,7 @@ public class AdapterTest {
// return an invalid field name
Factory factory = mock(Factory.class);
when(factory.getName(any(Field.class))).thenReturn("$invalidFieldName");
- Whitebox.setInternalState(Adapter.class, FACTORY_FIELD, factory);
+ ReflectionTestUtils.setField(Adapter.class, FACTORY_FIELD, factory);
assertEquals(null, Adapter.detmPropName(field(VALUE_NAME)));
}
@@ -257,7 +258,7 @@ public class AdapterTest {
// return an invalid method name
Factory factory = mock(Factory.class);
- Whitebox.setInternalState(Adapter.class, FACTORY_FIELD, factory);
+ ReflectionTestUtils.setField(Adapter.class, FACTORY_FIELD, factory);
when(factory.getName(any(Method.class))).thenReturn(GET_INVALID_NAME);
assertEquals(null, Adapter.detmGetterPropName(mget(GET_VALUE_NAME)));
@@ -273,7 +274,7 @@ public class AdapterTest {
// return an invalid method name
Factory factory = mock(Factory.class);
- Whitebox.setInternalState(Adapter.class, FACTORY_FIELD, factory);
+ ReflectionTestUtils.setField(Adapter.class, FACTORY_FIELD, factory);
when(factory.getName(any(Method.class))).thenReturn(SET_INVALID_NAME);
assertEquals(null, Adapter.detmSetterPropName(mset(SET_VALUE_NAME)));
diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/DataAdapterFactory.java b/gson/src/test/java/org/onap/policy/common/gson/internal/DataAdapterFactory.java
index 2799d8ba..d2cdf7f8 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/internal/DataAdapterFactory.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/internal/DataAdapterFactory.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 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.
@@ -35,6 +35,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+import lombok.ToString;
/**
* Factory used with test Data.
@@ -54,6 +55,7 @@ public class DataAdapterFactory implements TypeAdapterFactory {
/**
* Object handled by this factory.
*/
+ @ToString
public static class Data {
private int id;
@@ -72,16 +74,12 @@ public class DataAdapterFactory implements TypeAdapterFactory {
public void setId(int id) {
this.id = id;
}
-
- @Override
- public String toString() {
- return "Data [id=" + id + "]";
- }
}
/**
* Object derived from Data.
*/
+ @ToString(callSuper = true)
public static class DerivedData extends Data {
private String text;
@@ -101,11 +99,6 @@ public class DataAdapterFactory implements TypeAdapterFactory {
public void setText(String text) {
this.text = text;
}
-
- @Override
- public String toString() {
- return "DerivedData [text=" + text + ", toString()=" + super.toString() + "]";
- }
}
/**
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 509ddb79..acb241e6 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
@@ -1,8 +1,8 @@
-/*
+/*-
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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,18 +61,18 @@ public class FieldDeserializerTest {
// no value in tree - text remains unchanged
text = INITIAL_VALUE;
deser.getFromTree(json, this);
- assertEquals(text, INITIAL_VALUE);
+ assertEquals(INITIAL_VALUE, text);
// null value in tree - text remains unchanged
json.add(TEXT_FIELD_NAME, JsonNull.INSTANCE);
deser.getFromTree(json, this);
- assertEquals(text, INITIAL_VALUE);
+ assertEquals(INITIAL_VALUE, text);
// now assign a value - text should be changed now
json.addProperty(TEXT_FIELD_NAME, NEW_VALUE);
deser.getFromTree(json, this);
- assertEquals(text, NEW_VALUE);
+ assertEquals(NEW_VALUE, text);
/*
* check list field
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 cc5ef928..156e4ef3 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -89,7 +89,9 @@ public class FieldSerializerTest {
text = "world";
- assertThatThrownBy(() -> ser.addToTree(this, new JsonObject())).isInstanceOf(JsonParseException.class)
+ JsonObject obj = new JsonObject();
+
+ assertThatThrownBy(() -> ser.addToTree(this, obj)).isInstanceOf(JsonParseException.class)
.hasMessage(FieldSerializer.GET_ERR + FieldSerializerTest.class.getName() + ".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 6be4e590..5e73d06e 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 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.
@@ -33,6 +33,7 @@ import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
+import lombok.ToString;
import org.junit.Before;
import org.junit.Test;
@@ -138,6 +139,7 @@ public class JacksonTypeAdapterTest {
assertEquals("read text", data);
}
+ @ToString
private static class Data {
private String id;
private String value;
@@ -155,11 +157,6 @@ public class JacksonTypeAdapterTest {
this.id = id;
this.value = value;
}
-
- @Override
- public String toString() {
- return "Data [id=" + id + ", value=" + value + "]";
- }
}
private abstract static class NamedSer implements Serializer {
diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/MethodAdapterTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/MethodAdapterTest.java
index 9f39e3ce..6c13865d 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/internal/MethodAdapterTest.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/internal/MethodAdapterTest.java
@@ -1,8 +1,8 @@
-/*
+/*--
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -26,7 +26,6 @@ import static org.junit.Assert.assertEquals;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import org.junit.Test;
-import org.onap.policy.common.gson.internal.MethodAdapter;
public class MethodAdapterTest {
private static final Gson gson = new Gson();
@@ -36,16 +35,16 @@ public class MethodAdapterTest {
@Test
public void testMethodAdapter_testInvoke() throws Exception {
MethodAdapter adapter =
- new MethodAdapter(gson, MethodAdapterTest.class.getDeclaredMethod("getValue"), String.class);
+ new MethodAdapter(gson, MethodAdapterTest.class.getDeclaredMethod("getValue"), String.class);
assertEquals("hello", adapter.invoke(this));
MethodAdapter adapter2 = new MethodAdapter(gson,
- MethodAdapterTest.class.getDeclaredMethod("setValue", String.class), String.class);
+ MethodAdapterTest.class.getDeclaredMethod("setValue", String.class), String.class);
adapter2.invoke(this, "world");
assertEquals("world", saved);
assertThatThrownBy(() -> adapter2.invoke(this, 100)).isInstanceOf(JsonParseException.class)
- .hasMessage(MethodAdapter.INVOKE_ERR + MethodAdapterTest.class.getName() + ".setValue");
+ .hasMessage(MethodAdapter.INVOKE_ERR + MethodAdapterTest.class.getName() + ".setValue");
}
public String getValue() {
diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/MethodDeserializerTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/MethodDeserializerTest.java
index 338644ae..7fcfca18 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/internal/MethodDeserializerTest.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/internal/MethodDeserializerTest.java
@@ -1,8 +1,8 @@
-/*
+/*--
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -32,7 +32,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.MethodDeserializer;
public class MethodDeserializerTest {
private static final String PROP_NAME = "text";
@@ -43,7 +42,7 @@ public class MethodDeserializerTest {
private static DataAdapterFactory dataAdapter = new DataAdapterFactory();
private static Gson gson = new GsonBuilder().registerTypeAdapterFactory(dataAdapter)
- .setExclusionStrategies(new JacksonExclusionStrategy()).create();
+ .setExclusionStrategies(new JacksonExclusionStrategy()).create();
private MethodDeserializer deser;
diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/MethodSerializerTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/MethodSerializerTest.java
index 586bf54d..ed240513 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/internal/MethodSerializerTest.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/internal/MethodSerializerTest.java
@@ -1,8 +1,8 @@
-/*
+/*--
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -31,7 +31,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.MethodSerializer;
public class MethodSerializerTest {
private static final String PROP_NAME = "text";
@@ -40,7 +39,7 @@ public class MethodSerializerTest {
private static DataAdapterFactory dataAdapter = new DataAdapterFactory();
private static Gson gson = new GsonBuilder().registerTypeAdapterFactory(dataAdapter)
- .setExclusionStrategies(new JacksonExclusionStrategy()).create();
+ .setExclusionStrategies(new JacksonExclusionStrategy()).create();
private MethodSerializer ser;