Fix Sonar issues for policy-common 78/142678/1
authordanielhanrahan <daniel.hanrahan@est.tech>
Thu, 4 Dec 2025 20:08:26 +0000 (20:08 +0000)
committerdanielhanrahan <daniel.hanrahan@est.tech>
Mon, 8 Dec 2025 08:59:01 +0000 (08:59 +0000)
Issue-ID: POLICY-5423
Change-Id: I8b1a6dc9cd52d2cde8958531b3ecc6a3d2f7249f
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
37 files changed:
policy-common/src/test/java/org/onap/policy/common/endpoints/listeners/JsonListenerTest.java
policy-common/src/test/java/org/onap/policy/common/endpoints/listeners/MessageTypeDispatcherTest.java
policy-common/src/test/java/org/onap/policy/common/endpoints/listeners/ScoListenerTest.java
policy-common/src/test/java/org/onap/policy/common/gson/JacksonExclusionStrategyTest.java
policy-common/src/test/java/org/onap/policy/common/gson/internal/AdapterTest.java
policy-common/src/test/java/org/onap/policy/common/gson/internal/ClassWalkerTest.java
policy-common/src/test/java/org/onap/policy/common/message/bus/event/TopicEndpointProxyTest.java
policy-common/src/test/java/org/onap/policy/common/message/bus/event/base/BusConsumerTest.java
policy-common/src/test/java/org/onap/policy/common/message/bus/event/base/InlineBusTopicSinkTest.java
policy-common/src/test/java/org/onap/policy/common/message/bus/event/base/SingleThreadedBusTopicSourceTest.java
policy-common/src/test/java/org/onap/policy/common/message/bus/event/base/TopicFactoryTestBase.java
policy-common/src/test/java/org/onap/policy/common/message/bus/event/client/TopicSinkClientTest.java
policy-common/src/test/java/org/onap/policy/common/message/bus/event/kafka/InlineKafkaTopicSinkTest.java
policy-common/src/test/java/org/onap/policy/common/message/bus/event/kafka/KafkaTopicSinkFactoryTest.java
policy-common/src/test/java/org/onap/policy/common/message/bus/event/kafka/KafkaTopicSourceFactoryTest.java
policy-common/src/test/java/org/onap/policy/common/message/bus/event/kafka/SingleThreadedKafkaTopicSourceTest.java
policy-common/src/test/java/org/onap/policy/common/message/bus/event/noop/NoopTopicFactoryTest.java
policy-common/src/test/java/org/onap/policy/common/message/bus/features/NetLoggerFeatureApiTest.java
policy-common/src/test/java/org/onap/policy/common/message/bus/utils/NetLoggerUtilTest.java
policy-common/src/test/java/org/onap/policy/common/parameters/topic/BusTopicParamsTest.java
policy-common/src/test/java/org/onap/policy/common/spring/utils/CustomImplicitNamingStrategyTest.java
policy-common/src/test/java/org/onap/policy/common/utils/coder/StandardCoderObjectTest.java
policy-common/src/test/java/org/onap/policy/common/utils/coder/StandardCoderTest.java
policy-common/src/test/java/org/onap/policy/common/utils/coder/StandardYamlCoderTest.java
policy-common/src/test/java/org/onap/policy/common/utils/coder/YamlJsonTranslatorTest.java
policy-common/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsBuilderTest.java
policy-common/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java
policy-common/src/test/java/org/onap/policy/common/utils/properties/PropertyUtilsTest.java
policy-common/src/test/java/org/onap/policy/common/utils/resources/ResourceUtilsTest.java
policy-common/src/test/java/org/onap/policy/common/utils/services/FeatureApiUtilsTest.java
policy-common/src/test/java/org/onap/policy/common/utils/services/OrderedServiceImplTest.java
policy-common/src/test/java/org/onap/policy/common/utils/services/ServiceManagerContainerTest.java
policy-common/src/test/java/org/onap/policy/common/utils/services/ServiceManagerTest.java
policy-common/src/test/java/org/onap/policy/common/utils/test/ExceptionsTesterTest.java
policy-common/src/test/java/org/onap/policy/common/utils/test/ThrowablesTesterTest.java
policy-common/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java
policy-common/src/test/java/org/onap/policy/common/utils/validation/VersionTest.java

index c2e5f90..8070ffa 100644 (file)
@@ -64,7 +64,7 @@ class JsonListenerTest {
      * Initializes statics.
      */
     @BeforeAll
-    public static void setUpBeforeClass() {
+    static void setUpBeforeClass() {
         saveLevel = logger.getLevel();
         logger.setLevel(Level.INFO);
 
@@ -73,7 +73,7 @@ class JsonListenerTest {
     }
 
     @AfterAll
-    public static void tearDownAfterClass() {
+    static void tearDownAfterClass() {
         logger.setLevel(saveLevel);
         appender.stop();
     }
@@ -82,7 +82,7 @@ class JsonListenerTest {
      * Initializes mocks and a listener.
      */
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         appender.clearExtractions();
 
         primary = new JsonListener() {
@@ -94,7 +94,7 @@ class JsonListenerTest {
     }
 
     @AfterEach
-    public void tearDown() {
+    void tearDown() {
         logger.detachAppender(appender);
     }
 
index e0184bd..a132c45 100644 (file)
@@ -70,7 +70,7 @@ class MessageTypeDispatcherTest {
      * Initializes statics.
      */
     @BeforeAll
-    public static void setUpBeforeClass() {
+    static void setUpBeforeClass() {
         saveLevel = logger.getLevel();
         logger.setLevel(Level.INFO);
 
@@ -79,7 +79,7 @@ class MessageTypeDispatcherTest {
     }
 
     @AfterAll
-    public static void tearDownAfterClass() {
+    static void tearDownAfterClass() {
         logger.setLevel(saveLevel);
         appender.stop();
     }
@@ -89,7 +89,7 @@ class MessageTypeDispatcherTest {
      */
     @BeforeEach
     @SuppressWarnings("unchecked")
-    public void setUp() {
+    void setUp() {
         appender.clearExtractions();
 
         secondary1 = mock(ScoListener.class);
@@ -99,7 +99,7 @@ class MessageTypeDispatcherTest {
     }
 
     @AfterEach
-    public void tearDown() {
+    void tearDown() {
         logger.detachAppender(appender);
     }
 
index cb8fb70..fd7f0c0 100644 (file)
@@ -67,7 +67,7 @@ class ScoListenerTest {
      * Initializes statics.
      */
     @BeforeAll
-    public static void setUpBeforeClass() {
+    static void setUpBeforeClass() {
         saveLevel = logger.getLevel();
         logger.setLevel(Level.INFO);
 
@@ -76,7 +76,7 @@ class ScoListenerTest {
     }
 
     @AfterAll
-    public static void tearDownAfterClass() {
+    static void tearDownAfterClass() {
         logger.setLevel(saveLevel);
         appender.stop();
     }
@@ -85,7 +85,7 @@ class ScoListenerTest {
      * Create various mocks and primary handler.
      */
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         appender.clearExtractions();
 
         primary = new ScoListener<MyMessage>(MyMessage.class) {
@@ -98,7 +98,7 @@ class ScoListenerTest {
     }
 
     @AfterEach
-    public void tearDown() {
+    void tearDown() {
         logger.detachAppender(appender);
     }
 
index fc3c667..bc14e45 100644 (file)
@@ -45,7 +45,7 @@ class JacksonExclusionStrategyTest {
     private static Gson gson;
 
     @BeforeAll
-    public static void setUpBeforeClass() {
+    static void setUpBeforeClass() {
         strategy = new JacksonExclusionStrategy();
         gson = new GsonBuilder().setExclusionStrategies(strategy).create();
     }
index ebe2b72..ed7a849 100644 (file)
@@ -83,7 +83,7 @@ class AdapterTest {
     private Data dataField;
 
     @BeforeAll
-    public static void setUpBeforeClass() {
+    static void setUpBeforeClass() {
         saveFactory = (Factory) ReflectionTestUtils.getField(Adapter.class, FACTORY_FIELD);
     }
 
index 007724a..ef65c97 100644 (file)
@@ -358,6 +358,7 @@ class ClassWalkerTest {
         }
 
         // has a param - shouldn't be serialized
+        @SuppressWarnings("unused")
         public int getWithParams(String text) {
             return 1000;
         }
index 6f0e38d..b7239c0 100644 (file)
@@ -107,7 +107,7 @@ class TopicEndpointProxyTest {
      * Destroys all managed topics.
      */
     @AfterEach
-    public void tearDown() {
+    void tearDown() {
         NoopTopicFactories.getSinkFactory().destroy();
         NoopTopicFactories.getSourceFactory().destroy();
         KafkaTopicFactories.getSinkFactory().destroy();
index 207023e..f8fe410 100644 (file)
@@ -72,7 +72,7 @@ class BusConsumerTest extends TopicTestBase {
     }
 
     @AfterEach
-    public void tearDown() throws Exception {
+    void tearDown() throws Exception {
         closeable.close();
     }
 
@@ -181,7 +181,7 @@ class BusConsumerTest extends TopicTestBase {
         KafkaConsumerWrapper kafkaConsumerWrapper = new KafkaConsumerWrapper(makeKafkaBuilder().build());
         kafkaConsumerWrapper.consumer = mockedKafkaConsumer;
 
-        when(mockedKafkaConsumer.poll(any())).thenReturn(new ConsumerRecords<>(Collections.emptyMap()));
+        when(mockedKafkaConsumer.poll(any())).thenReturn(ConsumerRecords.empty());
 
         Iterable<String> result = kafkaConsumerWrapper.fetch();
 
@@ -195,6 +195,7 @@ class BusConsumerTest extends TopicTestBase {
     }
 
     @Test
+    @SuppressWarnings("deprecation")
     void testFetchWithMessages() {
         // Setup
         KafkaConsumerWrapper kafkaConsumerWrapper = new KafkaConsumerWrapper(makeKafkaBuilder().build());
@@ -224,6 +225,7 @@ class BusConsumerTest extends TopicTestBase {
     }
 
     @Test
+    @SuppressWarnings("deprecation")
     void testFetchWithMessagesAndTraceParent() {
         // Setup
         KafkaConsumerWrapper kafkaConsumerWrapper = new KafkaConsumerWrapper(makeKafkaBuilder().build());
index 8444b48..ef35464 100644 (file)
@@ -125,11 +125,10 @@ public abstract class TopicFactoryTestBase<T extends Topic> extends TopicTestBas
         List<T> lst = buildTopics(builder.build());
         assertEquals(4, lst.size());
 
-        int index = 0;
-        T item = lst.get(index++);
-        assertNotSame(item, lst.get(index++));
-        assertSame(item, lst.get(index++));
-        assertSame(item, lst.get(index++));
+        T item = lst.get(0);
+        assertNotSame(item, lst.get(1));
+        assertSame(item, lst.get(2));
+        assertSame(item, lst.get(3));
     }
 
     /**
@@ -140,9 +139,8 @@ public abstract class TopicFactoryTestBase<T extends Topic> extends TopicTestBas
 
         List<T> lst = buildTopics(makePropBuilder().makeTopic(MY_TOPIC).makeTopic(TOPIC2).build());
 
-        int index = 0;
-        T item1 = lst.get(index++);
-        T item2 = lst.get(index++);
+        T item1 = lst.get(0);
+        T item2 = lst.get(1);
 
         assertEquals(2, getInventory().size());
         assertTrue(getInventory().contains(item1));
@@ -192,9 +190,8 @@ public abstract class TopicFactoryTestBase<T extends Topic> extends TopicTestBas
 
         List<T> lst = buildTopics(makePropBuilder().makeTopic(MY_TOPIC).makeTopic(TOPIC2).build());
 
-        int index = 0;
-        T item1 = lst.get(index++);
-        T item2 = lst.get(index++);
+        T item1 = lst.get(0);
+        T item2 = lst.get(1);
 
         item1.start();
         item2.start();
index 67b15ec..938f222 100644 (file)
@@ -54,7 +54,7 @@ class TopicSinkClientTest {
      * @throws Exception if an error occurs
      */
     @BeforeEach
-    public void setUp() throws Exception {
+    void setUp() throws Exception {
         sink = mock(TopicSink.class);
         when(sink.send(anyString())).thenReturn(true);
 
@@ -71,7 +71,7 @@ class TopicSinkClientTest {
     }
 
     @AfterAll
-    public static void tearDown() {
+    static void tearDown() {
         // clear all topics after the tests
         TopicEndpointManager.getManager().shutdown();
     }
index 4dcba86..0e8ea06 100644 (file)
@@ -98,7 +98,7 @@ public abstract class NoopTopicFactoryTest<F extends NoopTopicFactory<T>, T exte
 
         // duplicate - should be the same, as these topics are managed
         List<String> randomServers = new ArrayList<>();
-        randomServers.add(RandomStringUtils.randomAlphanumeric(8));
+        randomServers.add(RandomStringUtils.secure().nextAlphanumeric(8));
         T item3 = buildTopic(randomServers, TOPIC2, true);
         assertSame(item2, item3);
 
index 776c5d5..1dae500 100644 (file)
@@ -44,7 +44,7 @@ class NetLoggerFeatureApiTest {
     private NetLoggerFeatureApi featureApi;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         featureApi = new NetLoggerFeatureApi() {
             @Override
             public boolean beforeLog(Logger eventLogger, EventType type, CommInfrastructure protocol, String topic,
index df621f5..d9809fd 100644 (file)
@@ -50,7 +50,7 @@ class NetLoggerUtilTest {
      * Obtains the test implementation of NetLoggerFeatureApi.
      */
     @BeforeAll
-    public static void setUp() {
+    static void setUp() {
         netLoggerFeature = (NetLoggerFeature) NetLoggerFeatureProviders.getProviders().getList().get(0);
     }
 
@@ -58,7 +58,7 @@ class NetLoggerUtilTest {
      * Clears events list and resets return/exceptions flags before invoking every unit test.
      */
     @BeforeEach
-    public void reset() {
+    void reset() {
         TestAppender.clear();
         netLoggerFeature.setReturnValue(false, false);
         netLoggerFeature.setExceptions(false, false);
index c474e5f..656b88c 100644 (file)
@@ -61,7 +61,7 @@ class BusTopicParamsTest {
     protected TopicParamsBuilder builder;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         addProps = new TreeMap<>();
         addProps.put("my-key-A", "my-value-A");
         addProps.put("my-key-B", "my-value-B");
index e7c3ad5..09719dd 100644 (file)
@@ -42,7 +42,7 @@ class CustomImplicitNamingStrategyTest {
     static ImplicitJoinColumnNameSource source;
 
     @BeforeAll
-    public static void setUpBeforeClass() {
+    static void setUpBeforeClass() {
         strategy = new CustomImplicitNamingStrategy();
         source = mock(ImplicitJoinColumnNameSource.class);
     }
index 0e4967b..16fff83 100644 (file)
@@ -50,7 +50,7 @@ class StandardCoderObjectTest {
      * @throws Exception if an error occurs
      */
     @BeforeEach
-    public void setUp() throws Exception {
+    void setUp() throws Exception {
         sco = new StandardCoderObject(gson.fromJson(JSON, JsonElement.class));
     }
 
index 269893e..45feb35 100644 (file)
@@ -66,7 +66,7 @@ class StandardCoderTest {
     private StandardCoder coder;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         coder = new StandardCoder();
     }
 
index d504b82..51933b1 100644 (file)
@@ -43,7 +43,7 @@ class StandardYamlCoderTest {
     private Container cont;
 
     @BeforeEach
-    public void setUp() throws CoderException {
+    void setUp() throws CoderException {
         coder = new StandardYamlCoder();
         cont = coder.decode(YAML_FILE, Container.class);
     }
index 563181c..1b82238 100644 (file)
@@ -53,7 +53,7 @@ class YamlJsonTranslatorTest {
      * @throws IOException if an error occurs
      */
     @BeforeEach
-    public void setUp() throws IOException {
+    void setUp() throws IOException {
         translator = new YamlJsonTranslator();
 
         try (FileReader rdr = new FileReader(YAML_FILE)) {
index d85653d..105f678 100644 (file)
@@ -39,7 +39,7 @@ class GsonTestUtilsBuilderTest {
     private GsonTestUtils utils;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         utils = new MyBuilder().build();
     }
 
index d355823..20b78b8 100644 (file)
@@ -47,7 +47,7 @@ class GsonTestUtilsTest {
     private GsonTestUtils utils;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         utils = new GsonTestUtils();
     }
 
index a8b37f5..b1ca018 100644 (file)
@@ -43,7 +43,7 @@ class PropertyUtilsTest {
      * Initializes {@link #utils}.
      */
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         Properties properties = new Properties();
         properties.put("myPrefix.my-string", "some text");
         properties.put("myPrefix.empty-string", "");
index 7b41d97..b3369cb 100644 (file)
@@ -64,7 +64,7 @@ class ResourceUtilsTest {
      * @throws IOException Signals that an I/O exception has occurred.
      */
     @BeforeEach
-    public void setupResourceUtilsTest() throws IOException {
+    void setupResourceUtilsTest() throws IOException {
         tmpDir = new File(System.getProperty("java.io.tmpdir"));
         tmpEmptyFile = File.createTempFile(this.getClass().getName(), ".tmp");
         tmpUsedFile = File.createTempFile(this.getClass().getName(), ".tmp");
@@ -81,7 +81,7 @@ class ResourceUtilsTest {
      * Clean resource utils test.
      */
     @AfterEach
-    public void cleanDownResourceUtilsTest() {
+    void cleanDownResourceUtilsTest() {
         assertTrue(tmpEmptyFile.delete());
         assertTrue(tmpUsedFile.delete());
     }
index 3de9377..3d80323 100644 (file)
@@ -43,7 +43,7 @@ class FeatureApiUtilsTest {
      * Initializes fields.
      */
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         tried = new LinkedList<>();
         errors = new LinkedList<>();
         pred = new MyPred();
index 1508009..52c3a9c 100644 (file)
@@ -40,7 +40,7 @@ class OrderedServiceImplTest {
      * Saves the original state of the ordered service list to restore after each test.
      */
     @BeforeAll
-    public static void setup() {
+    static void setup() {
         List<GenericService> implementers = GenericService.providers.getList();
         highPrioService = implementers.get(0);
         lowPrioService = implementers.get(1);
@@ -50,7 +50,7 @@ class OrderedServiceImplTest {
      * Restores original state after each test.
      */
     @BeforeEach
-    public void resetOrder() {
+    void resetOrder() {
         highPrioService.setSequenceNumber(HIGH_PRIORITY_NUM);
         lowPrioService.setSequenceNumber(LOW_PRIORITY_NUM);
     }
@@ -203,4 +203,4 @@ class OrderedServiceImplTest {
 
     }
 
-}
\ No newline at end of file
+}
index 1bae46c..080b9a3 100644 (file)
@@ -46,7 +46,7 @@ class ServiceManagerContainerTest {
      * Set up.
      */
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         starter = mock(RunnableWithEx.class);
         stopper = mock(RunnableWithEx.class);
         startObj = mock(Startable.class);
index dc55558..95c63d4 100644 (file)
@@ -49,7 +49,7 @@ class ServiceManagerTest {
      * Initializes {@link #svcmgr}.
      */
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         svcmgr = new ServiceManager(MY_NAME);
     }
 
index 81a8503..2004009 100644 (file)
@@ -48,6 +48,7 @@ class ExceptionsTesterTest {
     public static class NoConstructorsException extends Exception {
         private static final long serialVersionUID = 1L;
 
+        @SuppressWarnings("unused")
         public NoConstructorsException(int value) {
             super();
         }
index 7775ef3..0a437b5 100644 (file)
@@ -119,6 +119,7 @@ class ThrowablesTesterTest {
     public static class NoConstructorsThrowable extends Throwable {
         private static final long serialVersionUID = 1L;
 
+        @SuppressWarnings("unused")
         public NoConstructorsThrowable(int value) {
             super();
         }
index 9367209..f7fd24b 100644 (file)
@@ -60,13 +60,13 @@ class ExtractAppenderTest {
     private List<Thread> threads;
 
     @BeforeAll
-    public static void setUpBeforeClass() {
+    static void setUpBeforeClass() {
         logger = (Logger) LoggerFactory.getLogger(ExtractAppenderTest.class);
         logger.setLevel(Level.INFO);
     }
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         threads = new LinkedList<>();
     }
 
@@ -74,7 +74,7 @@ class ExtractAppenderTest {
      * Tear down all appenders and threads.
      */
     @AfterEach
-    public void tearDown() throws Exception {
+    void tearDown() throws Exception {
         logger.detachAndStopAllAppenders();
 
         for (Thread p : threads) {
index 1902312..5d5c5da 100644 (file)
@@ -40,7 +40,7 @@ class VersionTest {
     private Version vers;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         vers = new Version(MAJOR, MINOR, PATCH);
     }