From 0cfec3c5d53ed995e66f135ccd584d7ab0950258 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Tue, 3 Jul 2018 10:30:01 +0200 Subject: Fix weakness causing NPE Change-Id: I1f6bfa75990082dc411d813528702cc3cc140f5c Issue-ID: CLAMP-193 Signed-off-by: Gabriel --- .../clds/client/req/sdc/SdcCatalogServices.java | 4 ++-- .../onap/clamp/clds/it/SdcCatalogServicesItCase.java | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java b/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java index 9c9402100..240094e61 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java +++ b/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java @@ -17,6 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END============================================ + * Modifications copyright (c) 2018 Nokia * =================================================================== * */ @@ -227,13 +228,12 @@ public class SdcCatalogServices { */ public List removeDuplicateSdcResourceBasicInfo( List rawCldsSdcResourceListBasicList) { - List cldsSdcResourceBasicInfoList = null; + List cldsSdcResourceBasicInfoList = new ArrayList<>(); if (rawCldsSdcResourceListBasicList != null && !rawCldsSdcResourceListBasicList.isEmpty()) { // sort list Collections.sort(rawCldsSdcResourceListBasicList); // and then take only the resources with the max version (last in // the list with the same name) - cldsSdcResourceBasicInfoList = new ArrayList<>(); for (int i = 1; i < rawCldsSdcResourceListBasicList.size(); i++) { // compare name with previous - if not equal, then keep the // previous (it's the last with that name) diff --git a/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java b/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java index 4a13c62aa..330ee6056 100644 --- a/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java @@ -17,14 +17,17 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END============================================ + * Modifications copyright (c) 2018 Nokia * =================================================================== * */ package org.onap.clamp.clds.it; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertTrue; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -170,6 +173,23 @@ public class SdcCatalogServicesItCase { assertTrue("1.0".equals(res2.getVersion())); } + + @Test + public void removeDuplicateSdcFunctionShouldNotReturnNull(){ + // given + SdcCatalogServices catalogServices = new SdcCatalogServices(); + + // when + List firstResult = catalogServices + .removeDuplicateSdcResourceBasicInfo(null); + List secondResult = catalogServices + .removeDuplicateSdcResourceBasicInfo(new ArrayList<>()); + + // then + assertThat(firstResult).isEmpty(); + assertThat(secondResult).isEmpty(); + } + @Test public void getServiceUuidFromServiceInvariantIdTest() throws Exception { SdcCatalogServices spy = Mockito.spy(sdcCatalogWired); -- cgit 1.2.3-korg