diff options
author | 2025-01-09 10:18:33 +0000 | |
---|---|---|
committer | 2025-01-09 10:19:40 +0000 | |
commit | 6c92566dd754a7b54e3ee34b5bac5c041c799c72 (patch) | |
tree | dd6e144cb94b170b6c10481823624c9418089fd3 | |
parent | 2d2f5489c70e1334df2779390b67a53bd47a13c3 (diff) |
Fix sonar issues
- fixing sonar issues on code to generate a new common artifact
with parent new dependencies.
Issue-ID: POLICY-5240
Change-Id: I47b2ace072708e576d5fc5a82c2419925cbed7ed
Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
8 files changed, 37 insertions, 48 deletions
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValueValidator.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValueValidator.java index 0cd3776d..1b42876a 100644 --- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValueValidator.java +++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValueValidator.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2024 Nordix Foundation + * Modifications Copyright (C) 2024-2025 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,8 +62,7 @@ class TestValueValidator extends ValidatorUtil { validator.validateValue(result, MY_FIELD, null); assertThat(result.getResult()).isNull(); - validator.addAnnotation(NotNull.class, - (result2, fieldName, value) -> result2.validateNotNull(fieldName, value)); + validator.addAnnotation(NotNull.class, BeanValidationResult::validateNotNull); validator.validateValue(result, MY_FIELD, null); assertThat(result.getResult()).contains(MY_FIELD, "null"); } @@ -75,8 +74,7 @@ class TestValueValidator extends ValidatorUtil { validator.validateValue(result, MY_FIELD, HELLO); assertThat(result.getResult()).isNull(); - validator.addAnnotation(NotNull.class, - (result2, fieldName, value) -> result2.validateNotNull(fieldName, value)); + validator.addAnnotation(NotNull.class, BeanValidationResult::validateNotNull); validator.validateValue(result, MY_FIELD, HELLO); assertThat(result.getResult()).isNull(); } @@ -93,7 +91,6 @@ class TestValueValidator extends ValidatorUtil { assertThat(validator.isNullAllowed()).isTrue(); // "null" flag should become false with this annotation - assertThat(validator.isNullAllowed()).isTrue(); validator.addAnnotation(NotNull.class, (result2, fieldName, value) -> true); assertThat(validator.isNullAllowed()).isFalse(); } @@ -109,7 +106,7 @@ class TestValueValidator extends ValidatorUtil { // the field DOES have this annotation validator.addAnnotation(NotNull.class, (result2, fieldName, annot, value) -> { - wasNull.set(annot instanceof NotNull); + wasNull.set(annot != null); return result2.validateNotNull(fieldName, value); }); assertThat(validator.isEmpty()).isFalse(); diff --git a/gson/src/test/java/org/onap/policy/common/gson/GsonMessageBodyHandlerTest.java b/gson/src/test/java/org/onap/policy/common/gson/GsonMessageBodyHandlerTest.java index 00e1caf0..579b9fda 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/GsonMessageBodyHandlerTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/GsonMessageBodyHandlerTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023-2024 Nordix Foundation. + * Modifications Copyright (C) 2023-2025 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -137,7 +137,7 @@ class GsonMessageBodyHandlerTest { // use a derived type, but specify the base type when reading @SuppressWarnings("rawtypes") - Class clazz = new MyObject() {}.getClass(); + Class clazz = MyObject.class; @SuppressWarnings("unchecked") Class<Object> objclazz = clazz; diff --git a/gson/src/test/java/org/onap/policy/common/gson/JacksonExclusionStrategyTest.java b/gson/src/test/java/org/onap/policy/common/gson/JacksonExclusionStrategyTest.java index 38f2f32a..fc3c6675 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/JacksonExclusionStrategyTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/JacksonExclusionStrategyTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. - * Modificaitons Copyright (C) 2023-2024 Nordix Foundation. + * Modificaitons Copyright (C) 2023-2025 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +29,12 @@ import com.google.gson.FieldAttributes; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; +import java.io.Serial; import java.lang.reflect.GenericArrayType; import java.util.LinkedList; import java.util.TreeMap; +import lombok.Getter; +import lombok.Setter; import lombok.ToString; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -91,7 +94,7 @@ class JacksonExclusionStrategyTest { // generic classes should NOT be managed Class<?>[] unmanaged = { - new Data[0].getClass(), Enum.class, boolean.class, byte.class, short.class, int.class, + Data[].class, Enum.class, boolean.class, byte.class, short.class, int.class, long.class, float.class, double.class, char.class, Boolean.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, Character.class, String.class, MyMap.class, MyList.class, MyJson.class, GenericArrayType.class}; @@ -104,36 +107,27 @@ class JacksonExclusionStrategyTest { /** * Used to verify that no fields are exposed. */ + @Getter + @Setter @ToString public static class Data { private int id; public String text; - public int getId() { - return id; - } - void setId(int id) { this.id = id; } - public String getText() { - return text; - } - void setText(String text) { this.text = text; } } + @Getter @ToString(callSuper = true) public static class Derived extends Data { protected String value; - public String getValue() { - return value; - } - void setValue(String value) { this.value = value; } @@ -142,34 +136,34 @@ class JacksonExclusionStrategyTest { /** * Used to verify that enums are not managed. */ - public static enum Enum { + public enum Enum { UP, DOWN, } /** * Used to verify that interfaces <i>are</i> managed. */ - public static interface Intfc { + public interface Intfc { int getId(); } /** * Used to verify that Maps are not managed. */ + @Getter public static class MyMap extends TreeMap<String, Data> { + @Serial private static final long serialVersionUID = 1L; private int mapId; - public int getMapId() { - return mapId; - } } /** * Used to verify that Collections are not managed. */ public static class MyList extends LinkedList<Data> { + @Serial private static final long serialVersionUID = 1L; } diff --git a/message-bus/src/test/java/org/onap/policy/common/message/bus/event/client/BidirectionalTopicClientTest.java b/message-bus/src/test/java/org/onap/policy/common/message/bus/event/client/BidirectionalTopicClientTest.java index ba33ff9a..3bfd4292 100644 --- a/message-bus/src/test/java/org/onap/policy/common/message/bus/event/client/BidirectionalTopicClientTest.java +++ b/message-bus/src/test/java/org/onap/policy/common/message/bus/event/client/BidirectionalTopicClientTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2024 Nordix Foundation. + * Modifications Copyright (C) 2024-2025 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.Arrays; +import java.util.List; import java.util.Properties; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; @@ -119,11 +120,11 @@ class BidirectionalTopicClientTest { lenient().when(source.offer(anyString())).thenReturn(true); lenient().when(source.getTopicCommInfrastructure()).thenReturn(SOURCE_INFRA); - lenient().when(endpoint.getTopicSinks(anyString())).thenReturn(Arrays.asList()); - lenient().when(endpoint.getTopicSinks(SINK_TOPIC)).thenReturn(Arrays.asList(sink)); + lenient().when(endpoint.getTopicSinks(anyString())).thenReturn(List.of()); + lenient().when(endpoint.getTopicSinks(SINK_TOPIC)).thenReturn(List.of(sink)); - lenient().when(endpoint.getTopicSources(any())).thenReturn(Arrays.asList()); - lenient().when(endpoint.getTopicSources(Arrays.asList(SOURCE_TOPIC))).thenReturn(Arrays.asList(source)); + lenient().when(endpoint.getTopicSources(any())).thenReturn(List.of()); + lenient().when(endpoint.getTopicSources(List.of(SOURCE_TOPIC))).thenReturn(List.of(source)); theMessage = new MyMessage(MY_TEXT); @@ -161,7 +162,7 @@ class BidirectionalTopicClientTest { .hasMessage("no sources for topic: unknown-source"); // too many sources - when(endpoint.getTopicSources(Arrays.asList(SOURCE_TOPIC))).thenReturn(Arrays.asList(source, source)); + when(endpoint.getTopicSources(List.of(SOURCE_TOPIC))).thenReturn(Arrays.asList(source, source)); assertThatThrownBy(() -> new BidirectionalTopicClient2(SINK_TOPIC, SOURCE_TOPIC)) .isInstanceOf(BidirectionalTopicClientException.class) @@ -381,9 +382,9 @@ class BidirectionalTopicClientTest { @Override public boolean send(String messageText) { - boolean result = super.send(messageText); + boolean messageSent = super.send(messageText); sendSem.release(); - return result; + return messageSent; } @Override diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/rest/CommonTestData.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/rest/CommonTestData.java index 3e16b8a5..8c43e1f6 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/rest/CommonTestData.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/rest/CommonTestData.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019, 2024 Nordix Foundation. + * Copyright (C) 2019, 2024-2025 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,6 @@ package org.onap.policy.common.endpoints.rest; import java.io.File; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Map; import java.util.TreeMap; diff --git a/utils/src/test/java/org/onap/policy/common/utils/coder/PropertyCoderTest.java b/utils/src/test/java/org/onap/policy/common/utils/coder/PropertyCoderTest.java index d45f43b0..5559155f 100644 --- a/utils/src/test/java/org/onap/policy/common/utils/coder/PropertyCoderTest.java +++ b/utils/src/test/java/org/onap/policy/common/utils/coder/PropertyCoderTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2024 Nordix Foundation + * Modifications Copyright (C) 2024-2025 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,7 @@ class PropertyCoderTest { * For "pass", the encrypted value was generated via: * java org.onap.policy.common.utils.security.CryptoUtils enc hello abcdefghijklmnopqrstuvwxyzabcdef */ - private static final String json = + private static final String JSON = ("{'aes_encryption_key':'abcdefghijklmnopqrstuvwxyzabcdef'" + ",'xacml.pdp.rest.password':'enc:FSfOhDygtmnX3gkMSfTFMoBFW+AG5k6goNj2KZgQmeF0DqgcMg=='" + ",'xacml.pdp.rest.user':'testpdp'" @@ -72,7 +72,7 @@ class PropertyCoderTest { @Test void testPropertyCoder() { - MyClass data = propertyCoder.decode(json, AES_ENCRYPTION_KEY, MyClass.class); + MyClass data = propertyCoder.decode(JSON, AES_ENCRYPTION_KEY, MyClass.class); assertEquals("alpha", data.getPdpRestPass()); assertEquals("hello", data.servers.get(0).pass); assertEquals("server1", data.servers.get(0).name); @@ -82,7 +82,7 @@ class PropertyCoderTest { @Test void testPropertyCoderReader() { - Reader reader = new StringReader(json); + Reader reader = new StringReader(JSON); MyClass data = propertyCoder.decode(reader, AES_ENCRYPTION_KEY, MyClass.class); assertEquals("alpha", data.getPdpRestPass()); assertEquals("hello", data.servers.get(0).pass); diff --git a/utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderObjectTest.java b/utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderObjectTest.java index c597b7f6..0e4967be 100644 --- a/utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderObjectTest.java +++ b/utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderObjectTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2024 Nordix Foundation + * Modifications Copyright (C) 2024-2025 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ class StandardCoderObjectTest { private static final String PROP1 = "abc"; private static final String PROP2 = "ghi"; private static final Integer PROP2_INDEX = 1; - private static final String PROP2b = "jkl"; + private static final String PROP_2_B = "jkl"; private static final String VAL1 = "def"; private static final String VAL2 = "mno"; private static final String JSON = "{'abc':'def','ghi':[{},{'jkl':'mno'}]}".replace('\'', '"'); @@ -71,7 +71,7 @@ class StandardCoderObjectTest { assertEquals(VAL1, sco.getString(PROP1)); // multiple fields - assertEquals(VAL2, sco.getString(PROP2, PROP2_INDEX, PROP2b)); + assertEquals(VAL2, sco.getString(PROP2, PROP2_INDEX, PROP_2_B)); // not found assertNull(sco.getString("xyz")); diff --git a/utils/src/test/java/org/onap/policy/common/utils/validation/TestParameterValidationUtils.java b/utils/src/test/java/org/onap/policy/common/utils/validation/TestParameterValidationUtils.java index a85e8ec8..9f10ba9a 100644 --- a/utils/src/test/java/org/onap/policy/common/utils/validation/TestParameterValidationUtils.java +++ b/utils/src/test/java/org/onap/policy/common/utils/validation/TestParameterValidationUtils.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2024 Nordix Foundation + * Modifications Copyright (C) 2024-2025 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,6 @@ class TestParameterValidationUtils { @Test void testValidateIntParameter() { assertTrue(ParameterValidationUtils.validateIntParameter(5555)); - assertTrue(ParameterValidationUtils.validateIntParameter(Integer.valueOf(7777))); assertFalse(ParameterValidationUtils.validateIntParameter(0)); assertFalse(ParameterValidationUtils.validateIntParameter(-1)); } @@ -52,7 +51,6 @@ class TestParameterValidationUtils { @Test void testValidateLongParameter() { assertTrue(ParameterValidationUtils.validateLongParameter(5555L)); - assertTrue(ParameterValidationUtils.validateLongParameter(Long.valueOf(7777L))); assertFalse(ParameterValidationUtils.validateLongParameter(0L)); assertFalse(ParameterValidationUtils.validateLongParameter(-1L)); } |