aboutsummaryrefslogtreecommitdiffstats
path: root/utils-test/src/main/java/org/onap/policy/common/utils/io/Serializer.java
diff options
context:
space:
mode:
Diffstat (limited to 'utils-test/src/main/java/org/onap/policy/common/utils/io/Serializer.java')
-rw-r--r--utils-test/src/main/java/org/onap/policy/common/utils/io/Serializer.java28
1 files changed, 14 insertions, 14 deletions
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 9ab26d32..f3e1418a 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-2019 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.
@@ -25,10 +25,13 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
/**
* Utilities for testing serialization and de-serialization of objects.
*/
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class Serializer {
/**
@@ -37,13 +40,6 @@ public class Serializer {
private static Factory factory = new Factory();
/**
- * The constructor.
- */
- private Serializer() {
-
- }
-
- /**
* Serializes an object into a byte array.
*
* @param object the object to be serialized
@@ -51,8 +47,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
@@ -73,10 +69,10 @@ public class Serializer {
* @return the object that was de-serialized from the byte array
* @throws IOException if an error occurs
*/
- public static <T> T deserialize(Class<T> clazz, byte[] data) throws IOException {
+ 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,
@@ -133,7 +129,11 @@ public class Serializer {
*/
public Object readObject(ObjectInputStream ois) throws IOException {
try {
- return ois.readObject();
+ /*
+ * This class is only used by junit tests. In addition, it is only used by
+ * deserialize(), which has been made "private", thus disabling sonar.
+ */
+ return ois.readObject(); // NOSONAR
} catch (ClassNotFoundException e) {
throw new IOException(e);