diff options
author | 2020-06-25 10:24:12 +0200 | |
---|---|---|
committer | 2020-06-25 13:13:53 +0200 | |
commit | a7340508d11b52ab77f79db24472eab293f64227 (patch) | |
tree | c6497ca97925c2ce44f3903a5175e99145a4db95 /certServiceClient/src/test/java/org/onap/aaf/certservice | |
parent | 34d11834cbe76992246f3a4c5df5807af2e7d0d2 (diff) |
Fix sonar issues
Issue-ID: AAF-1152
Signed-off-by: Piotr Marcinkiewicz <piotr.marcinkiewicz@nokia.com>
Change-Id: I6e6ec500720204af32b8581e97fc563ac5c81acb
Diffstat (limited to 'certServiceClient/src/test/java/org/onap/aaf/certservice')
8 files changed, 80 insertions, 68 deletions
diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java index 36808941..9e256f98 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java @@ -35,7 +35,7 @@ class CertServiceClientTest { AppExitHandler appExitHandler = new AppExitHandler(); @Test - public void shouldExitWithDefinedExitCode_onRunCallWhenNoEnvsPresent() { + void shouldExitWithDefinedExitCode_onRunCallWhenNoEnvsPresent() { // given doNothing().when(appExitHandler).exit(CLIENT_CONFIGURATION_EXCEPTION); doNothing().when(appExitHandler).exit(SUCCESS); diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/CsrFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/CsrFactoryTest.java index e88976bf..ae18e6fb 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/CsrFactoryTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/CsrFactoryTest.java @@ -31,8 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - -public class CsrFactoryTest { +class CsrFactoryTest { CsrConfiguration config = mock(CsrConfiguration.class); diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/PrivateKeyToPemEncoderTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/PrivateKeyToPemEncoderTest.java index def9c1d5..41f15bb7 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/PrivateKeyToPemEncoderTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/PrivateKeyToPemEncoderTest.java @@ -44,7 +44,7 @@ class PrivateKeyToPemEncoderTest { private static final String PRIVATE_KEY_PEM_PATH = RESOURCES_DIR + "rsaPrivateKeyPem"; @Test - public void shouldReturnProperlyEncodedPrivateKey() throws InvalidKeySpecException, NoSuchAlgorithmException, PkEncodingException, IOException { + void shouldReturnProperlyEncodedPrivateKey() throws InvalidKeySpecException, NoSuchAlgorithmException, PkEncodingException, IOException { //given String expectedPem = Files.readString(Paths.get(PRIVATE_KEY_PEM_PATH)); PrivateKeyToPemEncoder testedPkEncoder = new PrivateKeyToPemEncoder(); @@ -63,4 +63,4 @@ class PrivateKeyToPemEncoderTest { KeyFactory kf = KeyFactory.getInstance(ENCRYPTION_ALGORITHM); return kf.generatePrivate(spec); } -}
\ No newline at end of file +} diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvProviderTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvProviderTest.java index af6b2d9f..74c8c2a1 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvProviderTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvProviderTest.java @@ -36,12 +36,12 @@ class EnvProviderTest { private EnvProvider envProvider; @BeforeEach - public void setUp() { + void setUp() { envProvider = Mockito.spy(EnvProvider.class); } @Test - public void shouldReturnSystemEnvVariableWhenItWasDefined() { + void shouldReturnSystemEnvVariableWhenItWasDefined() { // given when(envProvider.getSystemEnv(TEST_ENV)).thenReturn(TEST_ENV_VALUE); @@ -49,16 +49,17 @@ class EnvProviderTest { final Optional<String> testEnv = envProvider.readEnvVariable(TEST_ENV); // then - assertThat(testEnv.isPresent()).isTrue(); - assertThat(testEnv.get()).isEqualTo(TEST_ENV_VALUE); + assertThat(testEnv) + .isPresent() + .contains(TEST_ENV_VALUE); } @Test - public void shouldReportThatSystemEnvVariableIsNotPresentWhenItWasNotDefined() { + void shouldReportThatSystemEnvVariableIsNotPresentWhenItWasNotDefined() { // when final Optional<String> testEnv = envProvider.readEnvVariable(TEST_ENV); // then - assertThat(testEnv.isPresent()).isFalse(); + assertThat(testEnv).isNotPresent(); } } diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvsForCsrTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvsForCsrTest.java index 656bbe59..d6af20c6 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvsForCsrTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvsForCsrTest.java @@ -47,17 +47,18 @@ class EnvsForCsrTest { final Optional<String> testEnv = envsForCsr.getCommonName(); // then - assertThat(testEnv.isPresent()).isTrue(); - assertThat(testEnv.get()).isEqualTo(TEST_ENV); + assertThat(testEnv) + .isPresent() + .contains(TEST_ENV); } @Test - public void shouldReportThatSystemEnvCommonNameVariableIsNotPresentWhenItWasNotDefined() { + void shouldReportThatSystemEnvCommonNameVariableIsNotPresentWhenItWasNotDefined() { // when final Optional<String> testEnv = envsForCsr.getCommonName(); // then - assertThat(testEnv.isPresent()).isFalse(); + assertThat(testEnv).isNotPresent(); } @Test @@ -69,17 +70,18 @@ class EnvsForCsrTest { final Optional<String> testEnv = envsForCsr.getOrganization(); // then - assertThat(testEnv.isPresent()).isTrue(); - assertThat(testEnv.get()).isEqualTo(TEST_ENV); + assertThat(testEnv) + .isPresent() + .contains(TEST_ENV); } @Test - public void shouldReportThatSystemEnvOrganizationVariableIsNotPresentWhenItWasNotDefined() { + void shouldReportThatSystemEnvOrganizationVariableIsNotPresentWhenItWasNotDefined() { // when final Optional<String> testEnv = envsForCsr.getOrganization(); // then - assertThat(testEnv.isPresent()).isFalse(); + assertThat(testEnv).isNotPresent(); } @Test @@ -91,8 +93,9 @@ class EnvsForCsrTest { final Optional<String> testEnv = envsForCsr.getOrganizationUnit(); // then - assertThat(testEnv.isPresent()).isTrue(); - assertThat(testEnv.get()).isEqualTo(TEST_ENV); + assertThat(testEnv) + .isPresent() + .contains(TEST_ENV); } @Test @@ -101,7 +104,7 @@ class EnvsForCsrTest { final Optional<String> testEnv = envsForCsr.getOrganizationUnit(); // then - assertThat(testEnv.isPresent()).isFalse(); + assertThat(testEnv).isNotPresent(); } @Test @@ -113,17 +116,18 @@ class EnvsForCsrTest { final Optional<String> testEnv = envsForCsr.getLocation(); // then - assertThat(testEnv.isPresent()).isTrue(); - assertThat(testEnv.get()).isEqualTo(TEST_ENV); + assertThat(testEnv) + .isPresent() + .contains(TEST_ENV); } @Test - public void shouldReportThatSystemEnvLocationVariableIsNotPresentWhenItWasNotDefined() { + void shouldReportThatSystemEnvLocationVariableIsNotPresentWhenItWasNotDefined() { // when final Optional<String> testEnv = envsForCsr.getLocation(); // then - assertThat(testEnv.isPresent()).isFalse(); + assertThat(testEnv).isNotPresent(); } @Test @@ -135,17 +139,18 @@ class EnvsForCsrTest { final Optional<String> testEnv = envsForCsr.getState(); // then - assertThat(testEnv.isPresent()).isTrue(); - assertThat(testEnv.get()).isEqualTo(TEST_ENV); + assertThat(testEnv) + .isPresent() + .contains(TEST_ENV); } @Test - public void shouldReportThatSystemEnvStateVariableIsNotPresentWhenItWasNotDefined() { + void shouldReportThatSystemEnvStateVariableIsNotPresentWhenItWasNotDefined() { // when final Optional<String> testEnv = envsForCsr.getState(); // then - assertThat(testEnv.isPresent()).isFalse(); + assertThat(testEnv).isNotPresent(); } @Test @@ -157,17 +162,18 @@ class EnvsForCsrTest { final Optional<String> testEnv = envsForCsr.getCountry(); // then - assertThat(testEnv.isPresent()).isTrue(); - assertThat(testEnv.get()).isEqualTo(TEST_ENV); + assertThat(testEnv) + .isPresent() + .contains(TEST_ENV); } @Test - public void shouldReportThatSystemEnvCountryVariableIsNotPresentWhenItWasNotDefined() { + void shouldReportThatSystemEnvCountryVariableIsNotPresentWhenItWasNotDefined() { // when final Optional<String> testEnv = envsForCsr.getCountry(); // then - assertThat(testEnv.isPresent()).isFalse(); + assertThat(testEnv).isNotPresent(); } @Test @@ -179,8 +185,9 @@ class EnvsForCsrTest { final Optional<String> testEnv = envsForCsr.getSubjectAlternativesName(); // then - assertThat(testEnv.isPresent()).isTrue(); - assertThat(testEnv.get()).isEqualTo(TEST_ENV); + assertThat(testEnv) + .isPresent() + .contains(TEST_ENV); } @Test @@ -189,6 +196,6 @@ class EnvsForCsrTest { final Optional<String> testEnv = envsForCsr.getSubjectAlternativesName(); // then - assertThat(testEnv.isPresent()).isFalse(); + assertThat(testEnv).isNotPresent(); } } diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvsForTlsTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvsForTlsTest.java index a33d6541..7f599aa5 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvsForTlsTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvsForTlsTest.java @@ -48,17 +48,18 @@ class EnvsForTlsTest { final Optional<String> testEnv = envsForTls.getKeystorePath(); // then - assertThat(testEnv.isPresent()).isTrue(); - assertThat(testEnv.get()).isEqualTo(TEST_ENV); + assertThat(testEnv) + .isPresent() + .contains(TEST_ENV); } @Test - public void shouldReportThatSystemEnvKeyStorePathVariableIsNotPresentWhenItWasNotDefined() { + void shouldReportThatSystemEnvKeyStorePathVariableIsNotPresentWhenItWasNotDefined() { // when final Optional<String> testEnv = envsForTls.getKeystorePath(); // then - assertThat(testEnv.isPresent()).isFalse(); + assertThat(testEnv).isNotPresent(); } @Test @@ -70,17 +71,18 @@ class EnvsForTlsTest { final Optional<String> testEnv = envsForTls.getKeystorePassword(); // then - assertThat(testEnv.isPresent()).isTrue(); - assertThat(testEnv.get()).isEqualTo(TEST_ENV); + assertThat(testEnv) + .isPresent() + .contains(TEST_ENV); } @Test - public void shouldReportThatSystemEnvKeyStorePasswordVariableIsNotPresentWhenItWasNotDefined() { + void shouldReportThatSystemEnvKeyStorePasswordVariableIsNotPresentWhenItWasNotDefined() { // when final Optional<String> testEnv = envsForTls.getKeystorePassword(); // then - assertThat(testEnv.isPresent()).isFalse(); + assertThat(testEnv).isNotPresent(); } @Test @@ -92,17 +94,18 @@ class EnvsForTlsTest { final Optional<String> testEnv = envsForTls.getTruststorePath(); // then - assertThat(testEnv.isPresent()).isTrue(); - assertThat(testEnv.get()).isEqualTo(TEST_ENV); + assertThat(testEnv) + .isPresent() + .contains(TEST_ENV); } @Test - public void shouldReportThatSystemEnvTrustStorePathVariableIsNotPresentWhenItWasNotDefined() { + void shouldReportThatSystemEnvTrustStorePathVariableIsNotPresentWhenItWasNotDefined() { // when final Optional<String> testEnv = envsForTls.getTruststorePath(); // then - assertThat(testEnv.isPresent()).isFalse(); + assertThat(testEnv).isNotPresent(); } @Test @@ -114,16 +117,17 @@ class EnvsForTlsTest { final Optional<String> testEnv = envsForTls.getTruststorePassword(); // then - assertThat(testEnv.isPresent()).isTrue(); - assertThat(testEnv.get()).isEqualTo(TEST_ENV); + assertThat(testEnv) + .isPresent() + .contains(TEST_ENV); } @Test - public void shouldReportThatSystemEnvTrustStorePasswordVariableIsNotPresentWhenItWasNotDefined() { + void shouldReportThatSystemEnvTrustStorePasswordVariableIsNotPresentWhenItWasNotDefined() { // when final Optional<String> testEnv = envsForTls.getTruststorePassword(); // then - assertThat(testEnv.isPresent()).isFalse(); + assertThat(testEnv).isNotPresent(); } } diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/exception/TlsConfigurationExceptionTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/exception/TlsConfigurationExceptionTest.java index e1144a6b..e9e5c3bf 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/exception/TlsConfigurationExceptionTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/exception/TlsConfigurationExceptionTest.java @@ -26,10 +26,10 @@ import org.onap.aaf.certservice.client.api.ExitStatus; import static org.assertj.core.api.Assertions.assertThat; -public class TlsConfigurationExceptionTest { +class TlsConfigurationExceptionTest { @Test - public void containsProperExitStatus() { + void containsProperExitStatus() { // Given ExitStatus exitStatus = null; @@ -41,7 +41,8 @@ public class TlsConfigurationExceptionTest { } // Then - assertThat(exitStatus).isNotNull(); - assertThat(exitStatus).isEqualTo(ExitStatus.TLS_CONFIGURATION_EXCEPTION); + assertThat(exitStatus) + .isNotNull() + .isEqualTo(ExitStatus.TLS_CONFIGURATION_EXCEPTION); } } diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java index 9c0b9d8f..e4d71b31 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java @@ -27,67 +27,67 @@ import org.mockito.Mockito; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; -public class AbstractConfigurationFactoryTest { +class AbstractConfigurationFactoryTest { private final AbstractConfigurationFactory cut = mock(AbstractConfigurationFactory.class, Mockito.CALLS_REAL_METHODS); @ParameterizedTest @ValueSource(strings = {"/var/log", "/", "/var/log/", "/second_var", "/second-var"}) - public void shouldAcceptValidPath(String path) { + void shouldAcceptValidPath(String path) { assertThat(cut.isPathValid(path)).isTrue(); } @ParameterizedTest @ValueSource(strings = {"/var/log?", "", "var_", "var", "//", "/var//log"}) - public void shouldRejectInvalidPath(String path) { + void shouldRejectInvalidPath(String path) { assertThat(cut.isPathValid(path)).isFalse(); } @ParameterizedTest @ValueSource(strings = {"PL", "DE", "PN", "US", "IO", "CA", "KH", "CO", "DK", "EC", "CZ", "CN", "BR", "BD", "BE"}) - public void shouldAcceptValidCountryCode(String countryCode) { + void shouldAcceptValidCountryCode(String countryCode) { assertThat(cut.isCountryValid(countryCode)).isTrue(); } @ParameterizedTest @ValueSource(strings = {"", "QQ", "AFG", "D", "&*", "!", "ONAP", "p", "pl", "us", "afg"}) - public void shouldRejectInvalidCountryCode(String countryCode) { + void shouldRejectInvalidCountryCode(String countryCode) { assertThat(cut.isCountryValid(countryCode)).isFalse(); } @ParameterizedTest @ValueSource(strings = {"caname", "caname1", "123caName", "ca1name"}) - public void shouldAcceptValidAlphanumeric(String caName) { + void shouldAcceptValidAlphanumeric(String caName) { assertThat(cut.isAlphaNumeric(caName)).isTrue(); } @ParameterizedTest @ValueSource(strings = {"44caname$", "#caname1", "1c_aname", "ca1-name"}) - public void shouldRejectInvalidAlphanumeric(String caName) { + void shouldRejectInvalidAlphanumeric(String caName) { assertThat(cut.isAlphaNumeric(caName)).isFalse(); } @ParameterizedTest @ValueSource(strings = {"example.com", "www.example.com"}) - public void shouldAcceptValidCommonName(String commonName) { + void shouldAcceptValidCommonName(String commonName) { assertThat(cut.isCommonNameValid(commonName)).isTrue(); } @ParameterizedTest @ValueSource(strings = {"https://example.com", "http://example.com", "example.com:8080", "0.0.0.0", "@#$%.com"}) - public void shouldRejectInvalidCommonName(String commonName) { + void shouldRejectInvalidCommonName(String commonName) { assertThat(cut.isCommonNameValid(commonName)).isFalse(); } @ParameterizedTest @ValueSource(strings = {"JKS", "P12", "PEM"}) - public void shouldAcceptValidOutputType(String outputType) { + void shouldAcceptValidOutputType(String outputType) { assertThat(cut.isOutputTypeValid(outputType)).isTrue(); } @ParameterizedTest @ValueSource(strings = {"jks", "p12", "pem", "", "pass", "!@$#pp"}) - public void shouldRejectInvalidOutputType(String outputType) { + void shouldRejectInvalidOutputType(String outputType) { assertThat(cut.isOutputTypeValid(outputType)).isFalse(); } } |