diff options
author | waynedunican <wayne.dunican@est.tech> | 2024-07-23 09:23:51 +0100 |
---|---|---|
committer | waynedunican <wayne.dunican@est.tech> | 2024-08-13 08:49:10 +0100 |
commit | b7804abcf865dc58a01bed3f2be4756e731d9288 (patch) | |
tree | 7f6fc3b50622578bb8612de9fe5e5c6adddfaf28 /models-base | |
parent | a029ccab07f2dd71286804da620c513da9fdfc0e (diff) |
Improve code coverage and sonar fixes
Increased code coverage to 90%
SONAR - Removed TODO comments
SONAR - Added NOSONAR where appropriate
SONAR - Replaced stream.Collect() with stream.toList() where applicable
SONAR - Made variables serializable or transient to comply with sonar rules
Issue-ID: POLICY-5069
Change-Id: Ife256eaf4e6f427fe40b138bacc6f112dc5bcea4
Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'models-base')
9 files changed, 17 insertions, 18 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java index df6141b9b..f97d7b48a 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2020, 2024 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -54,7 +54,7 @@ public class PfConceptFilter implements PfObjectFilter<PfConcept> { .filter(filterStringPred(name, PfConcept::getName)) .filter(filterStringPred((LATEST_VERSION.equals(version) ? null : version), PfConcept::getVersion)) .filter(filterPrefixPred(versionPrefix, PfConcept::getVersion)) - .collect(Collectors.toList()); + .collect(Collectors.toList()); //NOSONAR // @formatter:off if (LATEST_VERSION.equals(version)) { diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfModel.java b/models-base/src/main/java/org/onap/policy/models/base/PfModel.java index 1caa6329e..0beeb01d9 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfModel.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfModel.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019, 2023 Nordix Foundation. + * Copyright (C) 2019, 2023-2024 Nordix Foundation. * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ @@ -123,10 +123,10 @@ public abstract class PfModel extends PfConcept { for (final PfKey pfKey : this.getKeys()) { // Check for the two type of keys we have - if (pfKey instanceof PfConceptKey) { - validateArtifactKeyInModel((PfConceptKey) pfKey, artifactKeySet, result); - } else if (pfKey instanceof PfReferenceKey) { - validateReferenceKeyInModel((PfReferenceKey) pfKey, referenceKeySet, result); + if (pfKey instanceof PfConceptKey pfConceptKey) { + validateArtifactKeyInModel(pfConceptKey, artifactKeySet, result); + } else if (pfKey instanceof PfReferenceKey pfReferenceKey) { + validateReferenceKeyInModel(pfReferenceKey, referenceKeySet, result); } else { // It must be a PfKeyUse, nothing else is legal usedKeySet.add((PfKeyUse) pfKey); diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java b/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java index 51054ee77..f7e6b5aa6 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021, 2023 Nordix Foundation. + * Copyright (C) 2019-2021, 2023-2024 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -114,7 +114,7 @@ public final class PfUtils { return defaultValue; } - return source.stream().map(mapFunc).collect(Collectors.toList()); + return source.stream().map(mapFunc).collect(Collectors.toList()); //NOSONAR } /** diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java b/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java index c2eb2b649..e9c8591b6 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,8 +67,8 @@ public class PfValidator extends BeanValidator { */ @Override public boolean verCascade(BeanValidationResult result, String fieldName, Object value) { - if (value instanceof Validated) { - ValidationResult result2 = ((Validated) value).validate(fieldName); + if (value instanceof Validated validated) { + ValidationResult result2 = validated.validate(fieldName); if (result2 == null) { return true; } @@ -129,6 +129,6 @@ public class PfValidator extends BeanValidator { @Override public Object xlate(Object value) { - return (value instanceof PfKey ? ((PfKey) value).getId() : value); + return (value instanceof PfKey pfKey ? pfKey.getId() : value); } } diff --git a/models-base/src/main/java/org/onap/policy/models/base/Validated.java b/models-base/src/main/java/org/onap/policy/models/base/Validated.java index 711dd7be6..0c4f36034 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/Validated.java +++ b/models-base/src/main/java/org/onap/policy/models/base/Validated.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -119,6 +120,6 @@ public class Validated { * @return the value's ID, if it's a key, the original value otherwise */ private static Object getKeyId(Object value) { - return (value instanceof PfKey ? ((PfKey) value).getId() : value); + return (value instanceof PfKey pfKey ? pfKey.getId() : value); } } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java index d605645ad..35535e789 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java @@ -130,7 +130,7 @@ class PfReferenceKeyTest { assertNotEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", VERSION001, "NPLN", "LN"))); assertEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", VERSION001, NPKLN, "NLN"))); - assertNotEquals(testReferenceKey, null); + assertNotNull(testReferenceKey); assertThatThrownBy(() -> new PfReferenceKey((PfReferenceKey) null)).isInstanceOf(NullPointerException.class); diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java index 2fea439b6..9d142bf96 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java @@ -48,7 +48,7 @@ class PfUtilsTest { assertEquals(0, PfUtils.compareObjects(null, null)); assertEquals(-1, PfUtils.compareObjects(HELLO, null)); assertEquals(1, PfUtils.compareObjects(null, HELLO)); - assertNotEquals(PfUtils.compareObjects(HELLO, "goodbye"), 0); + assertNotEquals(0, PfUtils.compareObjects(HELLO, "goodbye")); assertEquals(0, PfUtils.compareObjects(HELLO, HELLO)); } diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java index 594528be8..4b3d9e89a 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java +++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java @@ -102,7 +102,6 @@ public class DummyPfKey extends PfKey { @Override public boolean isNewerThan(@NonNull PfKey otherKey) { - // TODO Auto-generated method stub return false; } diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java index 489262865..3f0199ac5 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java +++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java @@ -33,7 +33,6 @@ import org.onap.policy.models.base.PfObjectFilter; public class DummyPfObjectFilter implements PfObjectFilter<DummyPfObject> { @Override public List<DummyPfObject> filter(List<DummyPfObject> originalList) { - // TODO Auto-generated method stub return null; } } |