Fix weakness causing NPE 77/55677/2
authorGabriel <adam.krysiak@nokia.com>
Tue, 3 Jul 2018 08:30:01 +0000 (10:30 +0200)
committerGabriel <adam.krysiak@nokia.com>
Tue, 3 Jul 2018 08:51:53 +0000 (10:51 +0200)
Change-Id: I1f6bfa75990082dc411d813528702cc3cc140f5c
Issue-ID: CLAMP-193
Signed-off-by: Gabriel <adam.krysiak@nokia.com>
src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java
src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java

index 9c94021..240094e 100644 (file)
@@ -17,6 +17,7 @@
  * See the License for the specific language governing permissions and\r
  * limitations under the License.\r
  * ============LICENSE_END============================================\r
+ * Modifications copyright (c) 2018 Nokia\r
  * ===================================================================\r
  * \r
  */\r
@@ -227,13 +228,12 @@ public class SdcCatalogServices {
      */\r
     public List<SdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(\r
             List<SdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {\r
-        List<SdcResourceBasicInfo> cldsSdcResourceBasicInfoList = null;\r
+        List<SdcResourceBasicInfo> cldsSdcResourceBasicInfoList = new ArrayList<>();\r
         if (rawCldsSdcResourceListBasicList != null && !rawCldsSdcResourceListBasicList.isEmpty()) {\r
             // sort list\r
             Collections.sort(rawCldsSdcResourceListBasicList);\r
             // and then take only the resources with the max version (last in\r
             // the list with the same name)\r
-            cldsSdcResourceBasicInfoList = new ArrayList<>();\r
             for (int i = 1; i < rawCldsSdcResourceListBasicList.size(); i++) {\r
                 // compare name with previous - if not equal, then keep the\r
                 // previous (it's the last with that name)\r
index 4a13c62..330ee60 100644 (file)
  * 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<SdcResourceBasicInfo> firstResult = catalogServices
+            .removeDuplicateSdcResourceBasicInfo(null);
+        List<SdcResourceBasicInfo> secondResult = catalogServices
+            .removeDuplicateSdcResourceBasicInfo(new ArrayList<>());
+
+        // then
+        assertThat(firstResult).isEmpty();
+        assertThat(secondResult).isEmpty();
+    }
+
     @Test
     public void getServiceUuidFromServiceInvariantIdTest() throws Exception {
         SdcCatalogServices spy = Mockito.spy(sdcCatalogWired);