code improvements-sonar fixes 90/110890/1
authorSravanKumarGunda <sravan.kumar1@huawei.com>
Tue, 4 Aug 2020 15:32:32 +0000 (21:02 +0530)
committerSravanKumarGunda <sravan.kumar1@huawei.com>
Tue, 4 Aug 2020 15:32:32 +0000 (21:02 +0530)
Signed-off-by: SravanKumarGunda <sravan.kumar1@huawei.com>
Issue-ID: CLI-270
Change-Id: I3f663df51e27e7295f9cad51ace100d784ab94bb

framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidRegistration.java
framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java
framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaMerger.java
framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java
framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java
framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
main/src/main/java/org/onap/cli/main/OnapCli.java
profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java

index 1c90e9a..90f8c46 100644 (file)
@@ -26,7 +26,7 @@ public class OnapCommandInvalidRegistration extends OnapCommandException {
 
     private static final long serialVersionUID = 7722163282274482532L;
 
-    public OnapCommandInvalidRegistration(Class cls) {
+    public OnapCommandInvalidRegistration(Class<?> cls) {
         super("0x2001", "Invalid commad class " + cls.getCanonicalName() + " registration, it should be derived from "
                 + OnapCommand.class.getCanonicalName());
     }
index 09050c6..c548f6d 100644 (file)
@@ -290,6 +290,6 @@ public class OnapCommandPrint {
             throw new OnapCommandOutputPrintingFailed(e);  // NOSONAR
         }
      */
-     return "";
+     return ""; //NOSONAR
     }
 }
index 9a6a4e7..0712603 100644 (file)
@@ -35,6 +35,10 @@ public class OnapCommandSchemaMerger {
 
     static Logger logger = LoggerFactory.getLogger(OnapCommandSchemaMerger.class);
 
+    private OnapCommandSchemaMerger(){
+        //It is made private in order to resolve: Utility classes should not have public constructors
+    }
+
     public static Map<String, Object> mergeSchemas(OnapCommand cmd) throws OnapCommandException {
         Map<String, Object> mergedResult = new LinkedHashMap<>();
 
index 839d142..774e1fd 100644 (file)
@@ -453,8 +453,7 @@ public class OnapCommandExecutionStore {
 
     private File getExecutionDir(String executionId) throws OnapCommandExecutionNotFound {
         File []f =  new File(getBasePath()).listFiles((dir, name) -> {
-            if (name.startsWith(executionId)) return true;
-            return false;
+            return name.startsWith(executionId);
         });
 
         if (f.length == 0) {
index 614eb2a..923ae24 100644 (file)
@@ -480,7 +480,7 @@ public class OnapCommandDiscoveryUtils {
 
     public static List<Map<String, Object>> createTestSuite(String cmd, String version) throws OnapCommandException {
 
-        ArrayList<Map<String, Object>> testSamples = new ArrayList();
+        ArrayList<Map<String, Object>> testSamples = new ArrayList<>();
 
 
         List<Resource> resources = new ArrayList<>();
index 6d9b2d2..507490c 100644 (file)
@@ -154,7 +154,7 @@ public class ValidateSchemaTest {
         paraValues.put("is_default_param","yes");
         list.add(paraValues);
         values.put("parameters",list);
-        assertTrue(OnapCommandSchemaLoader.parseSchema(cmd,values,true).size()==2);
+        assertEquals(2, OnapCommandSchemaLoader.parseSchema(cmd,values,true).size());
 
     }
     @Test
@@ -172,7 +172,7 @@ public class ValidateSchemaTest {
         list.add(paraValues);
         attributesValues.put("attributes",list);
         values.put("results",attributesValues);
-        assertTrue(OnapCommandSchemaLoader.parseSchema(cmd,values,true).size()==2);
+        assertEquals(2, OnapCommandSchemaLoader.parseSchema(cmd,values,true).size());
 
     }
 }
index 44c1819..e5fa45b 100644 (file)
@@ -546,8 +546,8 @@ public class OnapCommandUtilsTest {
           mapExample.put("key1", "paramA");
           mapExample.put("key2", "paramB");
           OnapCommandUtils.replaceLineFromResults("line $r{paramA} line $r{paramB}", mapExample);
-          assertTrue(mapExample.get("key1").equals("paramA"));
-          assertTrue(mapExample.get("key2").equals("paramB"));
+          assertEquals("paramA", mapExample.get("key1"));
+          assertEquals("paramB", mapExample.get("key2"));
    }
 
     @Test
index 1c27205..4d7e97a 100644 (file)
@@ -252,7 +252,7 @@ public class OnapCli {
                 // - positional-arg1
                 // - positional-arg2
                 try {
-                    Map<String, Object> values = (Map<String, Object>) OnapCommandDiscoveryUtils.loadYaml(this.paramFile);
+                    Map<String, Object> values = OnapCommandDiscoveryUtils.loadYaml(this.paramFile);
 
                     for (Entry<String, Object> cmdsParam: values.entrySet()) {
                         for (Object param: (List)cmdsParam.getValue()) {
index 7ad3c3f..89504fb 100644 (file)
@@ -223,7 +223,7 @@ public class OnapCommandUtilsTest {
         HttpInput httpInput = new HttpInput();
         httpInput.setMultiparts(multiparts);
         HttpInput input = OnapCommandHttpUtils.populateParameters(params, httpInput);
-        assertTrue(input != null);
+        assertNotNull(input);
     }
 
 }