Fix sonar issues
authorPiotr Marcinkiewicz <piotr.marcinkiewicz@nokia.com>
Thu, 25 Jun 2020 08:24:12 +0000 (10:24 +0200)
committerPiotr Marcinkiewicz <piotr.marcinkiewicz@nokia.com>
Thu, 25 Jun 2020 11:13:53 +0000 (13:13 +0200)
Issue-ID: AAF-1152
Signed-off-by: Piotr Marcinkiewicz <piotr.marcinkiewicz@nokia.com>
Change-Id: I6e6ec500720204af32b8581e97fc563ac5c81acb

certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreator.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/CsrFactoryTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/PrivateKeyToPemEncoderTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvProviderTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvsForCsrTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvsForTlsTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/exception/TlsConfigurationExceptionTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java

index 0ecee79..4826732 100644 (file)
@@ -61,8 +61,8 @@ public class ConvertedArtifactsCreator implements ArtifactsCreator {
     private void createKeystore(List<String> data, PrivateKey privateKey)
             throws PemConversionException, CertFileWriterException {
         Password password = passwordGenerator.generate(PASSWORD_LENGTH);
-        String keystoreArtifactName = String.format("%s.%s", KEYSTORE, fileExtension);
-        String keystorePass = String.format("%s.%s", KEYSTORE, PASS_EXT);
+        String keystoreArtifactName = getFilenameWithExtension(KEYSTORE, fileExtension);
+        String keystorePass = getFilenameWithExtension(KEYSTORE, PASS_EXT);
 
         LOGGER.debug("Attempt to create keystore files and saving data. File names: {}, {}", keystoreArtifactName, keystorePass);
 
@@ -73,8 +73,8 @@ public class ConvertedArtifactsCreator implements ArtifactsCreator {
     private void createTruststore(List<String> data)
             throws PemConversionException, CertFileWriterException {
         Password password = passwordGenerator.generate(PASSWORD_LENGTH);
-        String truststoreArtifactName = String.format("%s.%s", TRUSTSTORE, fileExtension);
-        String truststorePass = String.format("%s.%s", TRUSTSTORE, PASS_EXT);
+        String truststoreArtifactName = getFilenameWithExtension(TRUSTSTORE, fileExtension);
+        String truststorePass = getFilenameWithExtension(TRUSTSTORE, PASS_EXT);
 
         LOGGER.debug("Attempt to create truststore files and saving data. File names: {}, {}", truststoreArtifactName, truststorePass);
 
@@ -85,4 +85,8 @@ public class ConvertedArtifactsCreator implements ArtifactsCreator {
     private byte[] getPasswordAsBytes(Password password) {
         return password.getCurrentPassword().getBytes();
     }
+
+    private String getFilenameWithExtension(String filename, String extension) {
+        return String.format("%s.%s", filename, extension);
+    }
 }
index 3680894..9e256f9 100644 (file)
@@ -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);
index e88976b..ae18e6f 100644 (file)
@@ -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);
 
index def9c1d..41f15bb 100644 (file)
@@ -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
+}
index af6b2d9..74c8c2a 100644 (file)
@@ -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();
     }
 }
index 656bbe5..d6af20c 100644 (file)
@@ -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();
     }
 }
index a33d654..7f599aa 100644 (file)
@@ -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();
     }
 }
index e1144a6..e9e5c3b 100644 (file)
@@ -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);
     }
 }
index 9c0b9d8..e4d71b3 100644 (file)
@@ -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();
     }
 }