From eaba0c9e1141ec6fa248b89934780bb14d5865fe Mon Sep 17 00:00:00 2001 From: waynedunican Date: Fri, 18 Jun 2021 15:06:29 +0100 Subject: Increase code coverage in clamp-common Issue-ID: POLICY-3403 Change-Id: Ic66b52da8a6256d2a65c2c2767b939e94a417875 Signed-off-by: waynedunican --- .../startstop/CommonCommandLineArgumentsTest.java | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 common/src/test/java/org/onap/policy/clamp/controlloop/common/startstop/CommonCommandLineArgumentsTest.java (limited to 'common/src/test/java') diff --git a/common/src/test/java/org/onap/policy/clamp/controlloop/common/startstop/CommonCommandLineArgumentsTest.java b/common/src/test/java/org/onap/policy/clamp/controlloop/common/startstop/CommonCommandLineArgumentsTest.java new file mode 100644 index 000000000..2d30592e4 --- /dev/null +++ b/common/src/test/java/org/onap/policy/clamp/controlloop/common/startstop/CommonCommandLineArgumentsTest.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.common.startstop; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.apache.commons.cli.Options; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class CommonCommandLineArgumentsTest { + + public static CommonCommandLineArguments cli; + + @BeforeAll + static void setup() { + cli = new CommonCommandLineArguments(new Options()); + } + + @Test + void testConstructor() { + assertThat(cli).isNotNull(); + } + + @Test + void testHelp() { + assertThat(cli.help("DummyClass", new Options())) + .contains("DummyClass [options...]\noptions"); + } + + @Test + void testVersion() { + assertThatCode(() -> cli.version()).doesNotThrowAnyException(); + } + + @Test + void testValidateEmptyFileName() { + assertThatThrownBy(() -> cli.validate("")) + .hasMessageContaining("file was not specified as an argument"); + } + + @Test + void testValidateFileUrlNull() { + assertThatThrownBy(() -> cli.validate("abcd")) + .hasMessageContaining("does not exist"); + } + + @Test + void testValidateFileFound() { + String configFile = "demo/config/RuntimeConfig.json"; + assertThatCode(() -> cli.validate(configFile)).doesNotThrowAnyException(); + } + + @Test + void testValidateNotNormalFile() { + String badFile = "demo/config"; + assertThatThrownBy(() -> cli.validate(badFile)).hasMessageContaining("is not a normal file"); + } + +} -- cgit 1.2.3-korg