aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris André <chris.andre@yoppworks.com>2020-04-21 19:25:21 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-04-23 05:34:38 +0000
commitc829bbcfc9505a3ebf6035b53274f8bf22c34cff (patch)
treed7401ea95c0e7219019af821bd22ee928ca924e6
parent8def03ae0703c3629fcb5ac023fbe9a1eaead4b7 (diff)
Add null tests
- Change `isPropertiesListSizesNotEquals` to `isPropertiesListSizesEquals` - Added assertions to silence SonarCloud Issue-ID: SDC-2914 Signed-off-by: Chris Andre <chris.andre@yoppworks.com> Change-Id: I88003de54aea6c28575fecf0f41b4c5ef36ef154
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/PolicyTypeImportUtils.java31
1 files changed, 16 insertions, 15 deletions
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<PropertyDefinition> pt1Props, List<PropertyDefinition> pt2Props) {
- if (pt1Props == pt2Props) {
+ private static boolean isPolicyPropertiesEquals(List<PropertyDefinition> pt1Props,
+ List<PropertyDefinition> 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<String, PropertyDefinition> pt1PropsByName = MapUtil.toMap(pt1Props, PropertyDefinition::getName);
+ long numberOfEqualsProperties = pt2Props.stream()
+ .filter(pt2Prop -> policyPropertyEquals(pt1PropsByName.get(pt2Prop.getName()), pt2Prop)).count();
+ return numberOfEqualsProperties == pt1Props.size();
}
- Map<String, PropertyDefinition> 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<PropertyDefinition> pt1Props, List<PropertyDefinition> pt2Props) {
- return isEmpty(pt1Props) && isNotEmpty(pt2Props) ||
- isEmpty(pt2Props) && isNotEmpty(pt1Props) ||
- pt1Props.size() != pt2Props.size();
+ private static boolean isPropertiesListSizesEquals(List<PropertyDefinition> pt1Props, List<PropertyDefinition> pt2Props) {
+ return (isEmpty(pt1Props) && isEmpty(pt2Props))
+ || (isNotEmpty(pt1Props) && isNotEmpty(pt2Props) && pt1Props.size() == pt2Props.size());
}
-
}