From 9f9131575d2e2b1002a3e108f7793a97fa7652ab Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Mon, 6 Apr 2020 12:17:11 -0400 Subject: Address sonar issues in ONAP-logging Addressed the following sonar issues in ONAP-logging: - use Map instead of ConcurrentHashMap - remove unusued fields - use Map.computeIfAbsent() instead of get()/put() pair - readObject is unsafe - use try-with-resources - junit should assert something Also removed some unused imports. Issue-ID: POLICY-2305 Signed-off-by: Jim Hahn Change-Id: I3480a55da4d0e771f8083c97770a6c9707d871f7 Signed-off-by: Jim Hahn --- .../java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java | 5 +++-- .../org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java | 5 ++++- .../java/org/onap/policy/common/logging/flexlogger/Logger4JTest.java | 3 ++- .../onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java | 3 ++- 4 files changed, 11 insertions(+), 5 deletions(-) (limited to 'common-logging/src/test/java') diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java index 6af3632a..db4eb786 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java @@ -30,6 +30,7 @@ import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN; import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS; import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID; import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -613,7 +614,7 @@ public class PolicyLoggerTest { @Test public void testInitNullProperties() { - PolicyLogger.init(null); + assertThatCode(() -> PolicyLogger.init(null)).doesNotThrowAnyException(); } @Test @@ -630,7 +631,7 @@ public class PolicyLoggerTest { properties.setProperty("stop.check.point", "0"); properties.setProperty("logger.property", "LOG4J"); - PolicyLogger.init(properties); + assertThatCode(() -> PolicyLogger.init(properties)).doesNotThrowAnyException(); } @Test diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java index a74dd94d..ebc4b212 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java @@ -21,6 +21,7 @@ package org.onap.policy.common.logging.flexlogger; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertSame; @@ -131,7 +132,9 @@ public class FlexLoggerTest { changedKeys.add("error.level"); changedKeys.add("audit.level"); PropertiesCallBack propertiesCallBack = new PropertiesCallBack("name"); - propertiesCallBack.propertiesChanged(PropertyUtil.getProperties("config/policyLogger.properties"), changedKeys); + assertThatCode(() -> propertiesCallBack + .propertiesChanged(PropertyUtil.getProperties("config/policyLogger.properties"), changedKeys)) + .doesNotThrowAnyException(); } } diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/Logger4JTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/Logger4JTest.java index 99c343c0..d174aafc 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/Logger4JTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/Logger4JTest.java @@ -21,6 +21,7 @@ package org.onap.policy.common.logging.flexlogger; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; @@ -41,7 +42,7 @@ public class Logger4JTest { @Test public void testLogger4JClassOfQ() { - new Logger4J(this.getClass()); + assertThatCode(() -> new Logger4J(this.getClass())).doesNotThrowAnyException(); } @Test diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java index 92df0297..6804fd0c 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java @@ -21,6 +21,7 @@ package org.onap.policy.common.logging.flexlogger; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -41,7 +42,7 @@ public class SystemOutLoggerTest { @Test public void testSystemOutLoggerClassOfQ() { - new SystemOutLogger(SystemOutLoggerTest.class); + assertThatCode(() -> new SystemOutLogger(SystemOutLoggerTest.class)).doesNotThrowAnyException(); } @Test -- cgit 1.2.3-korg