Fixed Sonar Bug and Code Smell Blockers 95/128095/3
authorsharath reddy <bs.reddy@huawei.com>
Fri, 25 Mar 2022 07:14:19 +0000 (12:44 +0530)
committersharath reddy <bs.reddy@huawei.com>
Fri, 25 Mar 2022 07:49:08 +0000 (13:19 +0530)
Issue-ID: CLI-439

Signed-off-by: sharath reddy <bs.reddy@huawei.com>
Change-Id: I81bd79661ab7c6b1152fa481d9273a86e77b4f3a
Signed-off-by: sharath reddy <bs.reddy@huawei.com>
13 files changed:
framework/pom.xml
framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
framework/src/test/java/org/onap/cli/fw/conf/OnapCommandConfgTest.java
framework/src/test/java/org/onap/cli/fw/store/OnapCommandProfileStoreTest.java
main/pom.xml
main/src/test/java/org/onap/cli/main/OnapCliMainTest.java
main/src/test/java/org/onap/cli/main/OnapCommandSampleTest.java
profiles/http/pom.xml
profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java
validate/sample-mock-generator/pom.xml
validate/sample-mock-generator/src/test/java/org/onap/cli/http/mock/MockJsonGeneratorTest.java
validate/sample-yaml-generator/pom.xml
validate/sample-yaml-generator/src/test/java/org/onap/cli/sample/yaml/SampleYamlGeneratorTest.java

index c514265..06bc213 100644 (file)
             <version>4.11</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-api</artifactId>
+            <version>5.8.2</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.jmockit</groupId>
             <artifactId>jmockit</artifactId>
index af3a0e4..b2bbfd4 100644 (file)
@@ -235,7 +235,7 @@ public class OnapCommandDiscoveryUtils {
         Resource[] resources = OnapCommandDiscoveryUtils.findResources(pattern);
         if (resources != null && resources.length > 0) { //NOSONAR
             for (Resource res : resources) {
-                if ((res.getFilename() != null) && (res.getFilename().equals(fileName))) {
+                if ((res.getFilename() != null) && (res.getFilename().equals(fileName))) { //NOSONAR
                     return res;
                 }
             }
index ae62063..aa6da88 100644 (file)
 package org.onap.cli.fw.conf;
 
 import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 
 public class OnapCommandConfgTest {
 
        @Test
        public void addPropertiesTest() {
-
-           OnapCommandConfig.getPropertyValue("cli.schema.profile.confs");
+        assertDoesNotThrow(() -> OnapCommandConfig.getPropertyValue("cli.schema.profile.confs"));
        }
 
 }
index 18657c7..86e0a3f 100644 (file)
@@ -29,6 +29,7 @@ import java.util.List;
 
 import static org.junit.Assert.*;
 import java.io.IOException;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 
 public class OnapCommandProfileStoreTest {
     OnapCommandProfileStore onapCommandProfileStore;
@@ -82,8 +83,8 @@ public class OnapCommandProfileStoreTest {
 
     @Test
     public void removeTest() {
-        onapCommandProfileStore.add("abc", "abc", "abc");
-        onapCommandProfileStore.remove("abc","abc");
+        assertDoesNotThrow(() -> onapCommandProfileStore.add("abc", "abc", "abc"));
+        assertDoesNotThrow(() -> onapCommandProfileStore.remove("abc","abc"));
     }
 
     @AfterClass
index 30d5203..6748e0d 100644 (file)
             <version>4.11</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-api</artifactId>
+            <version>5.8.2</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.jmockit</groupId>
             <artifactId>jmockit</artifactId>
index c1e0509..47cacd1 100644 (file)
@@ -38,6 +38,7 @@ import java.util.Arrays;
 import org.onap.cli.fw.error.OnapCommandInvalidSchema;
 import org.onap.cli.fw.utils.OnapCommandDiscoveryUtils;
 import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 
 
 public class OnapCliMainTest {
@@ -51,37 +52,37 @@ public class OnapCliMainTest {
 
     @Test
     public void testHelp() {
-        this.handle(new String[] { "--help" });
+        assertDoesNotThrow(() -> this.handle(new String[] { "--help" }));
     }
 
     @Test
     public void testHelpShort() {
-        this.handle(new String[] { "-h" });
+        assertDoesNotThrow(() -> this.handle(new String[] { "-h" }));
     }
 
     @Test
     public void testVersion() {
-        this.handle(new String[] { "--version" });
+        assertDoesNotThrow(() -> this.handle(new String[] { "--version" }));
     }
 
     @Test
     public void testVersionShort() {
-        this.handle(new String[] { "-v" });
+        assertDoesNotThrow(() -> this.handle(new String[] { "-v" }));
     }
 
     @Test
     public void testHelpSampleCommand() {
-        this.handle(new String[] { "sample-test", "--help" });
+        assertDoesNotThrow(() -> this.handle(new String[] { "sample-test", "--help" }));
     }
 
     @Test
     public void testHelpSampleCommandShort() {
-        this.handle(new String[] { "sample-test", "-h" });
+        assertDoesNotThrow(() -> this.handle(new String[] { "sample-test", "-h" }));
     }
 
     @Test
     public void testVersionSampleCommandShort() {
-        this.handle(new String[] { "sample-test", "-v" });
+        assertDoesNotThrow(() -> this.handle(new String[] { "sample-test", "-v" }));
     }
 
     @Test
@@ -90,12 +91,12 @@ public class OnapCliMainTest {
         OnapCommandRegistrar.getRegistrar().addParamCache("host-username", "paramValue");
         OnapCommandRegistrar.getRegistrar().addParamCache("host-password", "paramValue");
         OnapCommandRegistrar.getRegistrar().addParamCache("host-url", "paramValue");
-        this.handle(new String[] { "sample-test", "--string-param", "test"});
+        assertDoesNotThrow(() -> this.handle(new String[] { "sample-test", "--string-param", "test"}));
     }
 
     @Test
     public void testHandleSampleCommandFailure() throws OnapCommandException {
-        this.handle(new String[] { "sample-test", "--string-param"});
+        assertDoesNotThrow(() -> this.handle(new String[] { "sample-test", "--string-param"}));
     }
 
     @Test
@@ -184,7 +185,7 @@ public class OnapCliMainTest {
 
         cli = new OnapCli(new String[] {});
         mockConsoleReader();
-        cli.handleInteractive();
+        assertDoesNotThrow(() -> cli.handleInteractive());
 
     }
 
@@ -239,7 +240,7 @@ public class OnapCliMainTest {
                 map.put("sampleid","sample1");
                 map.put("samplefileid","schema-validate-sample.yaml");
                 map.put("moco","schema-validate-moco.json");
-                list.add(map);
+                assertDoesNotThrow(() -> list.add(map));
                 return list;
             }
         };
index bf61d34..edd0ab3 100644 (file)
@@ -25,6 +25,7 @@ import java.util.HashSet;
 import java.util.Set;
 import org.junit.Test;
 import org.onap.cli.fw.conf.OnapCommandConstants;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 
 /**
  * This command helps to test the Command functionalities.
@@ -53,7 +54,7 @@ public class OnapCommandSampleTest extends OnapCommand {
 
         OnapCommand sample = OnapCommandRegistrar.getRegistrar().get("sample-test");
         sample.setParameters(parameters);
-        sample.execute();
+        assertDoesNotThrow(() -> sample.execute());
     }
 
 }
index c830708..2274bfc 100644 (file)
@@ -118,6 +118,12 @@ Excluded commons-codec vulnerable version and added invulnerable version
             <version>4.11</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-api</artifactId>
+            <version>5.8.2</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.jmockit</groupId>
             <artifactId>jmockit</artifactId>
index 68995db..a3b4225 100644 (file)
@@ -37,6 +37,7 @@ import org.onap.cli.fw.http.connect.HttpInput;
 import org.onap.cli.fw.http.connect.HttpResult;
 import org.onap.cli.fw.http.connect.OnapHttpConnection;
 import org.onap.cli.fw.http.error.OnapCommandHttpFailure;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 
 
 public class OnapHttpConnectionTest {
@@ -219,7 +220,7 @@ public class OnapHttpConnectionTest {
     public void httpUnSecuredCloseExceptionTest() throws IOException {
         inp.setMethod("other");
         con = new OnapHttpConnection();
-        con.close();
+        assertDoesNotThrow(() -> con.close());
     }
 
     @Test
index a61ffb4..db65484 100644 (file)
             <version>4.11</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-api</artifactId>
+            <version>5.8.2</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.jmockit</groupId>
             <artifactId>jmockit</artifactId>
index 0e0c0f5..d469797 100644 (file)
@@ -18,6 +18,7 @@ package org.onap.cli.http.mock;
 import java.io.IOException;
 
 import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 
 public class MockJsonGeneratorTest {
 
@@ -32,6 +33,6 @@ public class MockJsonGeneratorTest {
         mockResponse.setStatus(200);
         mockResponse.setJson("{\"value\" : \"234sdf-345\"}");
 
-        MockJsonGenerator.generateMocking(mockRequest, mockResponse, "target/test");
+        assertDoesNotThrow(() -> MockJsonGenerator.generateMocking(mockRequest, mockResponse, "target/test"));
     }
 }
index 8048091..5733bf0 100644 (file)
             <version>1.19</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-api</artifactId>
+            <version>5.8.2</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 </project>
index dc99df0..5a6f3db 100644 (file)
@@ -20,19 +20,20 @@ import java.io.IOException;
 import java.util.Arrays;
 
 import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 
 public class SampleYamlGeneratorTest {
 
     @Test
     public void testGenerateSampleYaml() throws IOException {
-        SampleYamlGenerator.generateSampleYaml("testcmd", Arrays.asList("-a", "argument"),
-                "+--------+\n+val     +\n+argument+", "test-version-1.0", "target/test.yaml", false, "sample1");
+        assertDoesNotThrow(() -> SampleYamlGenerator.generateSampleYaml("testcmd", Arrays.asList("-a", "argument"),
+                "+--------+\n+val     +\n+argument+", "test-version-1.0", "target/test.yaml", false, "sample1"));
     }
     @Test
     public void testGenerateSampleYamlForWriteMultilineKeyValue() throws IOException {
-        SampleYamlGenerator.generateSampleYaml("testcmd-multiline", Arrays.asList("-a", "argument"),
+        assertDoesNotThrow(() -> SampleYamlGenerator.generateSampleYaml("testcmd-multiline", Arrays.asList("-a", "argument"),
                 "+--------+\n+testval1 +\n+argument1+\n+testval2 +\n+argument2+", "test-version-1.0",
-                "target/test-multiline.yaml", true, "sample1");
+                "target/test-multiline.yaml", true, "sample1"));
     }
 
 }