diff options
author | SravanKumarGunda <sravan.kumar1@huawei.com> | 2020-07-14 14:55:47 +0530 |
---|---|---|
committer | SravanKumarGunda <sravan.kumar1@huawei.com> | 2020-07-14 19:22:59 +0530 |
commit | 9a08d687e48312beef47bce357d374ede2ce0dc7 (patch) | |
tree | 3717d377dd4ea90f4e88c28d52bb3c0d5d28f34c | |
parent | 5f23e02caa5ab128a4c01866dec91eaea8dc7cee (diff) |
Code Improvements
Signed-off-by: SravanKumarGunda <sravan.kumar1@huawei.com>
Issue-ID: CLI-270
Change-Id: I3de621dab68f153c16a36102239b095c60abf9ab
26 files changed, 64 insertions, 70 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java index 7a125ce5..09050c6c 100644 --- a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java +++ b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java @@ -71,10 +71,7 @@ public class OnapCommandPrint { * @return list */ public List<String> getColumn(String header) { - if (this.data.get(header) == null) { - this.data.put(header, new ArrayList<String>()); - } - return this.data.get(header); + return this.data.computeIfAbsent(header, k -> new ArrayList<String>()); } public boolean isPrintTitle() { diff --git a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java index 04a81aa7..7de56025 100644 --- a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java +++ b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java @@ -511,7 +511,7 @@ public class OnapCommandSchemaLoader { * @throws OnapCommandInvalidSchema * exception */ - public static Map<String, Object> loadSchema(InputStream stream, String schemaName) throws OnapCommandInvalidSchema { + public static Map<String, Object> loadSchema(InputStream stream, String schemaName) throws OnapCommandInvalidSchema { //NOSONAR return OnapCommandDiscoveryUtils.loadYaml(stream); } diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java index 15996a8f..7352eced 100644 --- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java +++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java @@ -17,7 +17,6 @@ package org.onap.cli.fw.store; import java.io.File; -import java.io.FilenameFilter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java index 677c45ea..39645120 100644 --- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java +++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java @@ -19,7 +19,6 @@ package org.onap.cli.fw.store; import static org.onap.cli.fw.conf.OnapCommandConstants.DATA_PATH_PROFILE_JSON; import java.io.File; -import java.io.FilenameFilter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -147,8 +146,7 @@ public class OnapCommandProfileStore { } private void load(String profileName, boolean include) throws OnapCommandException { - List<OnapCommandParamEntity> params= new ArrayList<>(); - params = this.loadParamFromCache(profileName); + List<OnapCommandParamEntity> params = this.loadParamFromCache(profileName); for (OnapCommandParamEntity p : params) { if (include) { diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java index b2999077..b866db09 100644 --- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java +++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java @@ -113,7 +113,7 @@ public class OnapCommandDiscoveryUtils { * exception */ public static List<OnapCommandSchemaInfo> discoverOrLoadSchemas(boolean forceRefresh) throws OnapCommandException { - List<OnapCommandSchemaInfo> schemas = new ArrayList<>(); + List<OnapCommandSchemaInfo> schemas = new ArrayList<>(); //NOSONAR if (forceRefresh || Boolean.parseBoolean(OnapCommandConfig.getPropertyValue(OnapCommandConstants.DISCOVER_ALWAYS)) || !OnapCommandDiscoveryUtils.isAlreadyDiscovered()) { schemas = OnapCommandDiscoveryUtils.discoverSchemas(); @@ -219,13 +219,7 @@ public class OnapCommandDiscoveryUtils { * exception */ public static Map<String, Object> loadSchema(Resource resource) throws OnapCommandInvalidSchema { - Map<String, Object> values = null; - try { - values = loadYaml(resource.getInputStream()); - } catch (Exception e) { - throw new OnapCommandInvalidSchema(resource.getFilename(), e); - } - return values; + return loadYaml(resource); } /** diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java index 60bf2d2b..58fe7df6 100644 --- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java +++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java @@ -328,11 +328,11 @@ public class OnapCommandUtils { || OnapCommandParameterType.JSON.equals(param.getParameterType()) || OnapCommandParameterType.YAML.equals(param.getParameterType())) { // ignore the front and back double quotes in json body - String va_ = params.get(paramName).getValue().toString(); + String value = params.get(paramName).getValue().toString(); if (idxS > 0) - result.append(line.substring(currentIdx, idxS - 1) + va_); + result.append(line.substring(currentIdx, idxS - 1) + value); else - result.append(va_); + result.append(value); currentIdx = idxE + 2; } else if (OnapCommandParameterType.MAP.equals(param.getParameterType())) { try { diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommandTest.java index f094203b..5b5c6fac 100644 --- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommandTest.java +++ b/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommandTest.java @@ -27,7 +27,7 @@ public class OnapSchemaValidateCommandTest { @Ignore @Test - public void validateSchemaCommandTest1() throws OnapCommandException { + public void validateSchemaCommandTest1() throws OnapCommandException { //NOSONAR OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("schema-validate"); cmd.getParametersMap().get("schema-location").setValue("schema-validate-pass.yaml"); cmd.getParametersMap().get("internal-schema").setValue("true"); @@ -36,7 +36,7 @@ public class OnapSchemaValidateCommandTest { @Ignore @Test - public void validateSchemaCommandTest2() throws OnapCommandException { + public void validateSchemaCommandTest2() throws OnapCommandException { //NOSONAR OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("schema-validate"); cmd.getParametersMap().get("schema-location").setValue( ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-pass.yaml").getFile()); diff --git a/framework/src/test/java/org/onap/cli/fw/info/OnapCommandInfoTest.java b/framework/src/test/java/org/onap/cli/fw/info/OnapCommandInfoTest.java index 337ee1a5..3e9cfd72 100644 --- a/framework/src/test/java/org/onap/cli/fw/info/OnapCommandInfoTest.java +++ b/framework/src/test/java/org/onap/cli/fw/info/OnapCommandInfoTest.java @@ -16,7 +16,7 @@ package org.onap.cli.fw.info; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; import org.junit.Test; import org.onap.cli.fw.cmd.OnapCommandType; @@ -31,8 +31,8 @@ public class OnapCommandInfoTest { info.setProduct("open-cli"); info.setService("test"); - assertTrue(info.getCommandType().equals(OnapCommandType.CMD)); - assertTrue(info.getState().equals(OnapCommandState.STABLE)); + assertEquals(OnapCommandType.CMD, info.getCommandType()); + assertEquals(OnapCommandState.STABLE, info.getState()); } } diff --git a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java index 1bf42e00..17d14235 100644 --- a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java +++ b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java @@ -17,6 +17,7 @@ package org.onap.cli.fw.input; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.HashMap; @@ -48,7 +49,7 @@ public class OnapCommandParameterTest { && param.isOptional() && !param.isSecured() && param.getParameterType().equals(OnapCommandParameterType.JSON)); - assertTrue("value".equals(param.getValue())); + assertEquals("value", param.getValue()); param.setParameterType(OnapCommandParameterType.ARRAY); List<String> list = Arrays.asList("1", "2", "3"); @@ -84,7 +85,7 @@ public class OnapCommandParameterTest { String envValue = param.getEnvVarNameFromrRawDefaultValue(); - assertTrue("DAFAULT_VALUE".equals(envValue)); + assertEquals("DAFAULT_VALUE", envValue); } @Test @@ -97,7 +98,7 @@ public class OnapCommandParameterTest { try { param.validate(); } catch (OnapCommandException e) { - assertTrue("0x7003::Parameter null is mandatory".equals(e.getMessage())); + assertEquals("0x7003::Parameter null is mandatory", e.getMessage()); } } @@ -107,7 +108,7 @@ public class OnapCommandParameterTest { param.setName("name"); param.setParameterType(OnapCommandParameterType.ARRAY); param.setValue("value"); - assertTrue("[\"1\",\"2\",\"3\"]".equals(param.getValue())); + assertEquals("[\"1\",\"2\",\"3\"]", param.getValue()); } @@ -117,7 +118,7 @@ public class OnapCommandParameterTest { param.setName("name"); param.setParameterType(OnapCommandParameterType.MAP); param.setValue("value"); - assertTrue("{\"One\":\"1\",\"Two\":\"2\",\"Three\":\"3\"}".equals(param.getValue())); + assertEquals("{\"One\":\"1\",\"Two\":\"2\",\"Three\":\"3\"}", param.getValue()); } @Test(expected = OnapCommandInvalidParameterValue.class) diff --git a/framework/src/test/java/org/onap/cli/fw/input/ParameterTypeTest.java b/framework/src/test/java/org/onap/cli/fw/input/ParameterTypeTest.java index a42b9120..bfe13a0b 100644 --- a/framework/src/test/java/org/onap/cli/fw/input/ParameterTypeTest.java +++ b/framework/src/test/java/org/onap/cli/fw/input/ParameterTypeTest.java @@ -18,6 +18,7 @@ package org.onap.cli.fw.input; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.junit.Assert.assertEquals; import org.junit.Test; import org.onap.cli.fw.error.OnapCommandInvalidParameterType; @@ -44,7 +45,7 @@ public class ParameterTypeTest { try { OnapCommandParameterType.get("name"); } catch (OnapCommandInvalidParameterType e) { - assertTrue("0x7001::Parameter type name is invalid".equals(e.getMessage())); + assertEquals("0x7001::Parameter type name is invalid", e.getMessage()); } } diff --git a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultAttributeTest.java b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultAttributeTest.java index f2c22b21..66e151bd 100644 --- a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultAttributeTest.java +++ b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultAttributeTest.java @@ -18,6 +18,7 @@ package org.onap.cli.fw.output; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.junit.Assert.assertEquals; import org.junit.Test; import org.onap.cli.fw.error.OnapCommandInvalidResultAttributeScope; @@ -36,7 +37,7 @@ public class OnapCommandResultAttributeTest { try { OnapCommandResultAttributeScope.get("name"); } catch (OnapCommandInvalidResultAttributeScope e) { - assertTrue("0x8002::Result atrribute name is invalid".equals(e.getMessage())); + assertEquals("0x8002::Result atrribute name is invalid", e.getMessage()); } } diff --git a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java index d5d04888..83a46088 100644 --- a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java +++ b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java @@ -35,7 +35,7 @@ public class OnapCommandResultTest { @Test @Ignore - public void commandResultObjTest() throws OnapCommandException { + public void commandResultObjTest() throws OnapCommandException { //NOSONAR OnapCommandResult res = new OnapCommandResult(); res.setDebugInfo("debugInfo"); res.setIncludeSeparator(true); @@ -58,7 +58,7 @@ public class OnapCommandResultTest { @Test @Ignore - public void commandResultPrintLandscapeTableTest() throws OnapCommandException { + public void commandResultPrintLandscapeTableTest() throws OnapCommandException { //NOSONAR OnapCommandResult res = new OnapCommandResult(); res.setDebugInfo("debugInfo"); res.setIncludeSeparator(true); @@ -86,7 +86,7 @@ public class OnapCommandResultTest { @Test @Ignore - public void commandResultPrintLandscapeJsonTest() throws OnapCommandException { + public void commandResultPrintLandscapeJsonTest() throws OnapCommandException { //NOSONAR OnapCommandResult res = new OnapCommandResult(); res.setDebugInfo("debugInfo"); res.setIncludeSeparator(true); @@ -116,7 +116,7 @@ public class OnapCommandResultTest { @Test @Ignore - public void commandResultPrintLandscapeCsvTest() throws OnapCommandException { + public void commandResultPrintLandscapeCsvTest() throws OnapCommandException { //NOSONAR OnapCommandResult res = new OnapCommandResult(); res.setDebugInfo("debugInfo"); res.setIncludeSeparator(true); @@ -150,7 +150,7 @@ public class OnapCommandResultTest { @Test @Ignore - public void commandResultPrintPortraitCsvTest() throws OnapCommandException { + public void commandResultPrintPortraitCsvTest() throws OnapCommandException { //NOSONAR OnapCommandResult res = new OnapCommandResult(); res.setDebugInfo("debugInfo"); res.setIncludeSeparator(true); @@ -182,7 +182,7 @@ public class OnapCommandResultTest { @Test @Ignore - public void commandResultPrintPortraitTableTest() throws OnapCommandException { + public void commandResultPrintPortraitTableTest() throws OnapCommandException { //NOSONAR OnapCommandResult res = new OnapCommandResult(); res.setDebugInfo("debugInfo"); res.setIncludeSeparator(true); diff --git a/framework/src/test/java/org/onap/cli/fw/output/PrintDirectionTest.java b/framework/src/test/java/org/onap/cli/fw/output/PrintDirectionTest.java index ae8dd2e1..2d30de91 100644 --- a/framework/src/test/java/org/onap/cli/fw/output/PrintDirectionTest.java +++ b/framework/src/test/java/org/onap/cli/fw/output/PrintDirectionTest.java @@ -18,6 +18,7 @@ package org.onap.cli.fw.output; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.junit.Assert.assertEquals; import org.junit.Test; import org.onap.cli.fw.error.OnapCommandInvalidPrintDirection; @@ -36,7 +37,7 @@ public class PrintDirectionTest { try { OnapCommandPrintDirection.get("name"); } catch (OnapCommandInvalidPrintDirection e) { - assertTrue("0x8003::Print direction name is invalid".equals(e.getMessage())); + assertEquals("0x8003::Print direction name is invalid", e.getMessage()); } } diff --git a/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java b/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java index 850d31e7..ff728a33 100644 --- a/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java +++ b/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java @@ -30,7 +30,7 @@ public class OnapCommandPrintTest { @Test @Ignore - public void printCsvTest() throws OnapCommandOutputPrintingFailed { + public void printCsvTest() throws OnapCommandOutputPrintingFailed { //NOSONAR OnapCommandPrint pr = new OnapCommandPrint(); pr.setDirection(OnapCommandPrintDirection.LANDSCAPE); pr.setPrintTitle(true); diff --git a/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java b/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java index 2b3c62ba..3b8876cf 100644 --- a/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java +++ b/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java @@ -105,7 +105,7 @@ public class OnapCommandRegistrarTest { } @OnapCommandSchema(schema = "sample-test-schema.yaml") -final class OnapCommandTest extends OnapCommand { +final class OnapCommandTest extends OnapCommand { //NOSONAR public OnapCommandTest() { diff --git a/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java b/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java index e951793e..6d9b2d2c 100644 --- a/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java +++ b/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java @@ -27,6 +27,7 @@ import org.junit.Test; import org.onap.cli.fw.cmd.OnapCommand; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandInvalidSchema; +import static org.junit.Assert.assertEquals; public class ValidateSchemaTest { @@ -123,7 +124,7 @@ public class ValidateSchemaTest { protected void run() throws OnapCommandException {} }; List<String> errorList5 = OnapCommandSchemaLoader.loadSchema(cmd5, "schema-validate-pass.yaml", true, true); - assertTrue(errorList5.size() == 0); + assertEquals(0, errorList5.size()); } diff --git a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java index d7bd8051..44c18194 100644 --- a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java +++ b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java @@ -263,7 +263,7 @@ public class OnapCommandUtilsTest { @Test @Ignore - public void invalidSchemaFileTest() throws OnapCommandException { + public void invalidSchemaFileTest() throws OnapCommandException { //NOSONAR Map<String, ?> map = null; try { map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test-schema1.yaml", "1.0"); @@ -371,7 +371,7 @@ public class OnapCommandUtilsTest { } Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters()); - assertTrue(map.size() == 18); + assertEquals(18, map.size()); } @Test @@ -554,6 +554,6 @@ public class OnapCommandUtilsTest { public void loadYamlTest() throws OnapCommandInvalidSchema { File file=new File("src/test/resources/sample-test-info.yaml"); Map<String, Object> values= OnapCommandDiscoveryUtils.loadYaml(file.getAbsolutePath()); - assertEquals(values.get("name"),"sample-test-info"); + assertEquals("sample-test-info",values.get("name")); } } diff --git a/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java b/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java index 427bab77..14043f37 100644 --- a/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java +++ b/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java @@ -88,9 +88,9 @@ public class OpenInterfaceGrpcServer { @Override public void run() { // Use stderr here since the logger may have been reset by its JVM shutdown hook. - System.err.println("*** shutting down gRPC server since JVM is shutting down"); + System.err.println("*** shutting down gRPC server since JVM is shutting down"); //NOSONAR OpenInterfaceGrpcServer.this.stop(); - System.err.println("*** server shut down"); + System.err.println("*** server shut down"); //NOSONAR } }); } diff --git a/main/src/main/java/org/onap/cli/main/OnapCli.java b/main/src/main/java/org/onap/cli/main/OnapCli.java index b11b1b2b..061c1f7b 100644 --- a/main/src/main/java/org/onap/cli/main/OnapCli.java +++ b/main/src/main/java/org/onap/cli/main/OnapCli.java @@ -158,11 +158,11 @@ public class OnapCli { } protected void print(String msg) { - System.out.println(msg); + System.out.println(msg); //NOSONAR } protected void printerr(String msg) { - System.err.println(msg); + System.err.println(msg); //NOSONAR } private void print(Throwable throwable) { @@ -515,7 +515,7 @@ public class OnapCli { //refer params from profile if (this.profile != null) { - Map<String, String> paramCache = new HashMap<>(); + Map<String, String> paramCache = new HashMap<>(); //NOSONAR if (this.product == null) paramCache = OnapCommandRegistrar.getRegistrar().getParamCache(); else diff --git a/main/src/test/java/org/onap/cli/main/interactive/StringCompleterTest.java b/main/src/test/java/org/onap/cli/main/interactive/StringCompleterTest.java index 32f3be8a..853ceb49 100644 --- a/main/src/test/java/org/onap/cli/main/interactive/StringCompleterTest.java +++ b/main/src/test/java/org/onap/cli/main/interactive/StringCompleterTest.java @@ -16,12 +16,11 @@ package org.onap.cli.main.interactive; -import static org.junit.Assert.assertTrue; - import java.util.ArrayList; import java.util.Arrays; import org.junit.Test; +import static org.junit.Assert.assertEquals; public class StringCompleterTest { @@ -29,20 +28,20 @@ public class StringCompleterTest { public void completeTest() { StringCompleter com = new StringCompleter(Arrays.asList(new String[] { "test", "testing1", "testing2" })); int result = com.complete("test", 1, new ArrayList<CharSequence>()); - assertTrue(result == 0); + assertEquals(0, result); result = com.complete(null, 1, new ArrayList<CharSequence>()); - assertTrue(result == 0); + assertEquals(0, result); com.add("test", "testing1", "testing2"); result = com.complete("test", 1, new ArrayList<CharSequence>()); - assertTrue(result == 0); + assertEquals(0, result); result = com.complete("sfds", 1, new ArrayList<CharSequence>()); - assertTrue(result == -1); + assertEquals(-1, result); result = com.complete("test", 1, new ArrayList<CharSequence>()); - assertTrue(result == 0); + assertEquals(0, result); } } diff --git a/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java b/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java index e74981fb..05249898 100644 --- a/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java +++ b/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java @@ -405,7 +405,7 @@ public class OnapCliUtilsTest { paramslist.add(param1); OnapCliArgsParser.populateParams(paramslist, Arrays.asList("--yaml", "name", "--yaml", "test-schema")); - Assert.assertTrue(paramslist.iterator().next().getValue().equals("test-schema")); + Assert.assertEquals("test-schema", paramslist.iterator().next().getValue()); } @Test public void testReadYamlStringFromUrlForFile() throws OnapCommandException { @@ -417,6 +417,6 @@ public class OnapCliUtilsTest { paramslist.add(param1); OnapCliArgsParser.populateParams(paramslist, Arrays.asList("--yaml", "main/src/test/resources/open-cli-schema/sample-test-schema.yaml", "--yaml", "test-schema")); - Assert.assertTrue(paramslist.iterator().next().getValue().equals("test-schema")); + Assert.assertEquals("test-schema", paramslist.iterator().next().getValue()); } }
\ No newline at end of file diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java index 387ec3be..e17f8615 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java @@ -183,8 +183,8 @@ public class OnapHttpCommand extends OnapCommand { OnapCommandParameter context = contextOpt.get(); Map<String, String> map = (Map<String, String>) context.getValue(); - mockingEnabled = map.containsKey(OnapCommandHttpConstants.VERIFY_DISABLE_MOCKING) - && "true".equals(map.get(OnapCommandHttpConstants.VERIFY_DISABLE_MOCKING)) ? false : true; + mockingEnabled = !(map.containsKey(OnapCommandHttpConstants.VERIFY_DISABLE_MOCKING) + && "true".equals(map.get(OnapCommandHttpConstants.VERIFY_DISABLE_MOCKING))); if (mockingEnabled) { String mockedFile = ((Map<String, String>) context.getValue()).get(OnapCommandConstants.VERIFY_MOCO); diff --git a/profiles/http/src/test/java/org/onap/cli/fw/http/HttpInputOutputTest.java b/profiles/http/src/test/java/org/onap/cli/fw/http/HttpInputOutputTest.java index 597a3280..28439aaf 100644 --- a/profiles/http/src/test/java/org/onap/cli/fw/http/HttpInputOutputTest.java +++ b/profiles/http/src/test/java/org/onap/cli/fw/http/HttpInputOutputTest.java @@ -23,6 +23,7 @@ import java.util.HashMap; import org.junit.Test; import org.onap.cli.fw.http.connect.HttpInput; import org.onap.cli.fw.http.connect.HttpResult; +import static org.junit.Assert.assertEquals; public class HttpInputOutputTest { @@ -45,7 +46,7 @@ public class HttpInputOutputTest { String msg = "\nURL: uri\nMethod: method\nRequest Queries: {}\nRequest Body: body\nRequest Headers: " + "{}\nRequest Cookies: {}\nbinaryData=false\nContext={}"; - assertTrue(msg.equals(inp.toString())); + assertEquals(msg, inp.toString()); } @Test @@ -62,8 +63,8 @@ public class HttpInputOutputTest { out.setRespCookies(new HashMap<String, String>()); out.setRespHeaders(new HashMap<String, String>()); out.setStatus(200); - assertTrue("\nHTTP Status: 200\nResponse Body: body\nResponse Headers: {}\nResponse Cookies: {}" - .equals(out.toString())); + assertEquals("\nHTTP Status: 200\nResponse Body: body\nResponse Headers: {}\nResponse Cookies: {}" + , out.toString()); } } diff --git a/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java b/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java index 6807321e..7ad3c3ff 100644 --- a/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java +++ b/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java @@ -55,6 +55,7 @@ import org.onap.cli.fw.error.OnapCommandResultEmpty; import static org.junit.Assert.assertFalse; import org.onap.cli.fw.http.connect.HttpInput; import org.onap.cli.fw.http.connect.HttpInput.Part; +import static org.junit.Assert.assertNotNull; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class OnapCommandUtilsTest { @@ -67,7 +68,7 @@ public class OnapCommandUtilsTest { @Test public void oclipCommandUtilsInputStreamNotNullTest() throws OnapCommandException { Map<String, ?> map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test1-schema-http.yaml", "1.0"); - assertTrue(map != null); + assertNotNull(map); } @Test @@ -76,7 +77,7 @@ public class OnapCommandUtilsTest { cmd.setName("sample-create-http"); try { OnapCommandSchemaHttpLoader.loadHttpSchema(cmd, "sample-test-schema-http.yaml", true, true); - assertTrue(cmd.getSuccessStatusCodes().size() == 2); + assertEquals(2, cmd.getSuccessStatusCodes().size()); } catch (OnapCommandParameterNameConflict | OnapCommandParameterOptionConflict | OnapCommandInvalidParameterType | OnapCommandInvalidPrintDirection | OnapCommandInvalidResultAttributeScope | OnapCommandSchemaNotFound | OnapCommandInvalidSchema @@ -97,10 +98,10 @@ public class OnapCommandUtilsTest { } }; OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema-auth-required.yaml", true, false); - assertTrue("sample-test".equals(cmd.getName())); + assertEquals("sample-test", cmd.getName()); Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters()); - assertTrue(map.size() == 9); + assertEquals(9, map.size()); } @Test(expected = OnapCommandHttpHeaderNotFound.class) diff --git a/validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java b/validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java index 48ae7db4..3436a50f 100644 --- a/validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java +++ b/validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java @@ -55,7 +55,7 @@ public class SampleYamlGenerator { writer.close(); } - private static void writeMultilineKeyValue(PrintWriter writer, String key, String value, boolean debug) { + private static void writeMultilineKeyValue(PrintWriter writer, String key, String value, boolean debug) { //NOSONAR writer.write(printTabs() + key + ":"); if (value.isEmpty()) { return; diff --git a/validate/validation/src/test/java/org/onap/cli/validation/OnapValidationTest.java b/validate/validation/src/test/java/org/onap/cli/validation/OnapValidationTest.java index 9c46de86..d24fe1e7 100644 --- a/validate/validation/src/test/java/org/onap/cli/validation/OnapValidationTest.java +++ b/validate/validation/src/test/java/org/onap/cli/validation/OnapValidationTest.java @@ -95,7 +95,7 @@ public class OnapValidationTest { Date end = new Date(); System.out.println("[ Total time " + (end.getTime() - start.getTime()) + " ms ]\n"); try { - Thread.sleep(2000); + Thread.sleep(2000); //NOSONAR } catch (InterruptedException e) { System.out.println(new Date()); } |