From c829bbcfc9505a3ebf6035b53274f8bf22c34cff Mon Sep 17 00:00:00 2001 From: Chris André Date: Tue, 21 Apr 2020 19:25:21 -0400 Subject: Add null tests - Change `isPropertiesListSizesNotEquals` to `isPropertiesListSizesEquals` - Added assertions to silence SonarCloud Issue-ID: SDC-2914 Signed-off-by: Chris Andre Change-Id: I88003de54aea6c28575fecf0f41b4c5ef36ef154 --- .../impl/utils/PolicyTypeImportUtils.java | 31 +++++++++++----------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'catalog-be/src') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/PolicyTypeImportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/PolicyTypeImportUtils.java index 92badd5d04..4516a226d4 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/PolicyTypeImportUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/PolicyTypeImportUtils.java @@ -54,19 +54,22 @@ public class PolicyTypeImportUtils { PolicyTypeImportUtils.isPolicyPropertiesEquals(pt1.getProperties(), pt2.getProperties()); } - private static boolean isPolicyPropertiesEquals(List pt1Props, List pt2Props) { - if (pt1Props == pt2Props) { + private static boolean isPolicyPropertiesEquals(List pt1Props, + List pt2Props) { + if ((pt1Props == pt2Props) + || pt1Props == null && isEmpty(pt2Props) + || pt2Props == null && isEmpty(pt1Props)) { return true; - } - if (pt1Props == null && isEmpty(pt2Props) || pt2Props == null && isEmpty(pt1Props)) { - return true; - } - if (isPropertiesListSizesNotEquals(pt1Props, pt2Props)) { + } else if (!isPropertiesListSizesEquals(pt1Props, pt2Props)) { return false; + } else { + // The two cases tested by these assertions should have been taken care of by the previous two tests + assert (pt1Props != null && pt2Props != null); + Map pt1PropsByName = MapUtil.toMap(pt1Props, PropertyDefinition::getName); + long numberOfEqualsProperties = pt2Props.stream() + .filter(pt2Prop -> policyPropertyEquals(pt1PropsByName.get(pt2Prop.getName()), pt2Prop)).count(); + return numberOfEqualsProperties == pt1Props.size(); } - Map pt1PropsByName = MapUtil.toMap(pt1Props, PropertyDefinition::getName); - long numberOfEqualsProperties = pt2Props.stream().filter(pt2Prop -> policyPropertyEquals(pt1PropsByName.get(pt2Prop.getName()), pt2Prop)).count(); - return numberOfEqualsProperties == pt1Props.size(); } private static boolean policyPropertyEquals(PropertyDefinition pt1Prop, PropertyDefinition pt2Prop) { @@ -85,10 +88,8 @@ public class PolicyTypeImportUtils { Objects.equals(pt1Prop.getType(), pt2Prop.getType()); } - private static boolean isPropertiesListSizesNotEquals(List pt1Props, List pt2Props) { - return isEmpty(pt1Props) && isNotEmpty(pt2Props) || - isEmpty(pt2Props) && isNotEmpty(pt1Props) || - pt1Props.size() != pt2Props.size(); + private static boolean isPropertiesListSizesEquals(List pt1Props, List pt2Props) { + return (isEmpty(pt1Props) && isEmpty(pt2Props)) + || (isNotEmpty(pt1Props) && isNotEmpty(pt2Props) && pt1Props.size() == pt2Props.size()); } - } -- cgit 1.2.3-korg