From 611f63a4bb71d677cf2665b1794e91148ba42a51 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 17 Jun 2020 08:37:15 -0400 Subject: Cleanup various sonar issues in policy-common Addressed the following issues: - unused imports - unused method parameters - use assertEquals, assertSame instead of assertTrue - provide the parametrized type for this generic Also fixed some checkstyle issues: - removed blank lines between "import" groups Issue-ID: POLICY-2650 Change-Id: I004bb650ac10c49ccd0fc405f6959896fec39f9b Signed-off-by: Jim Hahn --- .../policy/common/logging/eelf/EventDataTest.java | 26 ++++++++++------------ .../logging/eelf/EventTrackInfoHandlerTest.java | 7 +++--- .../common/logging/eelf/EventTrackInfoTest.java | 22 +++++++++--------- .../common/logging/eelf/PolicyLoggerTest.java | 3 --- .../common/logging/flexlogger/FlexLoggerTest.java | 16 ++++++------- .../logging/flexlogger/SystemOutLoggerTest.java | 2 -- 6 files changed, 34 insertions(+), 42 deletions(-) (limited to 'common-logging/src/test/java/org/onap') diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java index 6fe81d27..882cc2cf 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.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-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. @@ -21,13 +21,10 @@ package org.onap.policy.common.logging.eelf; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import java.time.Instant; - import org.junit.Test; public class EventDataTest { @@ -142,32 +139,33 @@ public class EventDataTest { final EventData d3 = new EventData("abc", iend, istart); // same object - assertTrue(d1.equals(d1)); + assertEquals(d1, d1); // compare with null - assertFalse(d1.equals(null)); + assertNotEquals(d1, null); // compare with request id - assertTrue(d1.equals("abc")); - assertFalse(d1.equals("abd")); + // note: ignoring sonar because we want to test d1.equals(), not "abc".equals() + assertEquals(d1, "abc"); // NOSONAR + assertNotEquals(d1, "abd"); // compare with int - different class type - assertFalse(d1.equals(10)); + assertNotEquals(d1, 10); // "this" has null request id - assertFalse(new EventData().equals(d1)); + assertNotEquals(new EventData(), d1); // both null - assertTrue(new EventData().equals(new EventData())); + assertEquals(new EventData(), new EventData()); // this request id is not null, other is null - assertFalse(d1.equals(new EventData())); + assertNotEquals(d1, new EventData()); // neither null, same - assertTrue(d1.equals(d3)); + assertEquals(d1, d3); // neither null, diff - assertFalse(d1.equals(d2)); + assertNotEquals(d1, d2); } } diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandlerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandlerTest.java index d1d5983d..2cc1e59e 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandlerTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandlerTest.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP Policy Engine - Common Modules * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018, 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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,7 +24,6 @@ import static org.junit.Assert.assertEquals; import java.time.Instant; import java.util.concurrent.ConcurrentMap; - import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java index e6024682..0ca5feb5 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.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-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. @@ -23,10 +23,10 @@ package org.onap.policy.common.logging.eelf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.time.Instant; - import org.junit.Before; import org.junit.Test; @@ -62,8 +62,8 @@ public class EventTrackInfoTest { info.storeEventData(data1); info.storeEventData(data2); - assertTrue(data1 == info.getEventDataByRequestId("abc")); - assertTrue(data2 == info.getEventDataByRequestId("def")); + assertSame(data1, info.getEventDataByRequestId("abc")); + assertSame(data2, info.getEventDataByRequestId("def")); assertNull(info.getEventDataByRequestId("hello")); } @@ -86,14 +86,14 @@ public class EventTrackInfoTest { assertEquals(2, info.getEventInfo().size()); // look-up by request id - assertTrue(data1 == info.getEventDataByRequestId("abc")); - assertTrue(data2 == info.getEventDataByRequestId("def")); + assertSame(data1, info.getEventDataByRequestId("abc")); + assertSame(data2, info.getEventDataByRequestId("def")); // doesn't replace existing value info.storeEventData(new EventData("abc", iend, istart)); assertEquals(2, info.getEventInfo().size()); - assertTrue(data1 == info.getEventDataByRequestId("abc")); - assertTrue(data2 == info.getEventDataByRequestId("def")); + assertSame(data1, info.getEventDataByRequestId("abc")); + assertSame(data2, info.getEventDataByRequestId("def")); } /** @@ -111,7 +111,7 @@ public class EventTrackInfoTest { // look-up by request id assertNull(info.getEventDataByRequestId("abc")); - assertTrue(data2 == info.getEventDataByRequestId("def")); + assertSame(data2, info.getEventDataByRequestId("def")); } /** @@ -123,8 +123,8 @@ public class EventTrackInfoTest { info.storeEventData(data2); assertEquals(2, info.getEventInfo().size()); - assertTrue(data1 == info.getEventInfo().get("abc")); - assertTrue(data2 == info.getEventInfo().get("def")); + assertSame(data1, info.getEventInfo().get("abc")); + assertSame(data2, info.getEventInfo().get("def")); } } 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 adb7d366..8688ea3d 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 @@ -37,7 +37,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; import static org.onap.policy.common.logging.eelf.OnapConfigProperties.PARTNER_NAME; import static org.onap.policy.common.logging.eelf.OnapConfigProperties.RESPONSE_CODE; import static org.onap.policy.common.logging.eelf.OnapConfigProperties.RESPONSE_DESCRIPTION; @@ -46,11 +45,9 @@ import static org.onap.policy.common.logging.eelf.OnapConfigProperties.STATUS_CO import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFLogger.Level; - import java.time.Instant; import java.util.Properties; import java.util.UUID; - import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; 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 f43c85df..f5fcefe6 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 @@ -52,15 +52,15 @@ public class FlexLoggerTest { @Test public void testGetLoggerStringEelf() { Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.EELF); - Logger logger = FlexLogger.getLogger("str1"); - assertSame(logger, FlexLogger.getLogger("str1")); + Logger logger = FlexLogger.getLogger(); + assertSame(logger, FlexLogger.getLogger()); } @Test public void testGetLoggerStringSystemOut() { Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT); - Logger logger = FlexLogger.getLogger("str1"); - assertSame(logger, FlexLogger.getLogger("str1")); + Logger logger = FlexLogger.getLogger(); + assertSame(logger, FlexLogger.getLogger()); } @Test @@ -80,15 +80,15 @@ public class FlexLoggerTest { @Test public void testGetLoggerStringBooleanEelf() { Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.EELF); - Logger logger = FlexLogger.getLogger("str1", true); - assertSame(logger, FlexLogger.getLogger("str1", true)); + Logger logger = FlexLogger.getLogger(true); + assertSame(logger, FlexLogger.getLogger(true)); } @Test public void testGetLoggerStringBooleanSystemOut() { Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT); - Logger logger = FlexLogger.getLogger("str1", true); - assertSame(logger, FlexLogger.getLogger("str1", true)); + Logger logger = FlexLogger.getLogger(true); + assertSame(logger, FlexLogger.getLogger(true)); } @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 cde423f5..38c9e0d2 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 @@ -27,11 +27,9 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import com.att.eelf.configuration.EELFLogger.Level; - import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.UUID; - import org.junit.Test; import org.onap.policy.common.logging.eelf.MessageCodes; import org.onap.policy.common.logging.eelf.PolicyLogger; -- cgit 1.2.3-korg