From ae7046edae59b0b0df2c42edd264b1398f337f16 Mon Sep 17 00:00:00 2001 From: alexradzin Date: Wed, 1 Nov 2023 17:33:20 +0200 Subject: [PATCH] removed code smells --- .../com/firebolt/jdbc/connection/FireboltConnection.java | 2 +- .../jdbc/service/FireboltAuthenticationService.java | 9 ++++----- ...ireboltConnectionServiceSecretAuthenticationTest.java | 2 +- ...FireboltConnectionUserPasswordAuthenticationTest.java | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/firebolt/jdbc/connection/FireboltConnection.java b/src/main/java/com/firebolt/jdbc/connection/FireboltConnection.java index 0334dbdb1..12f0740c3 100644 --- a/src/main/java/com/firebolt/jdbc/connection/FireboltConnection.java +++ b/src/main/java/com/firebolt/jdbc/connection/FireboltConnection.java @@ -75,7 +75,7 @@ public abstract class FireboltConnection implements Connection { protected FireboltConnection(@NonNull String url, Properties connectionSettings, FireboltAuthenticationService fireboltAuthenticationService, - FireboltStatementService fireboltStatementService) throws SQLException { + FireboltStatementService fireboltStatementService) { this.loginProperties = extractFireboltProperties(url, connectionSettings); this.fireboltAuthenticationService = fireboltAuthenticationService; diff --git a/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java b/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java index dcd4b66ad..7ff3decfa 100644 --- a/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java +++ b/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java @@ -12,7 +12,6 @@ import javax.xml.bind.DatatypeConverter; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.Optional; import static java.lang.String.format; import static java.util.Optional.ofNullable; @@ -27,8 +26,8 @@ public class FireboltAuthenticationService { .variableExpiration().build(); private static final long TOKEN_EXPIRATION_OFFSET = 5L; private static final long TOKEN_TTL_THRESHOLD = 60L; - private static final String errorMessage = "Failed to connect to Firebolt with the error: %s, see logs for more info."; - private static final String errorMessageFromServer = "Failed to connect to Firebolt with the error from the server: %s, see logs for more info."; + private static final String ERROR_MESSAGE = "Failed to connect to Firebolt with the error: %s, see logs for more info."; + private static final String ERROR_MESSAGE_FROM_SERVER = "Failed to connect to Firebolt with the error from the server: %s, see logs for more info."; private final FireboltAuthenticationClient fireboltAuthenticationClient; public FireboltConnectionTokens getConnectionTokens(String host, FireboltProperties loginProperties) throws FireboltException { @@ -48,11 +47,11 @@ public FireboltConnectionTokens getConnectionTokens(String host, FireboltPropert } } catch (FireboltException e) { log.error("Failed to connect to Firebolt", e); - String msg = ofNullable(e.getErrorMessageFromServer()).map(m -> format(errorMessageFromServer, m)).orElse(format(errorMessage, e.getMessage())); + String msg = ofNullable(e.getErrorMessageFromServer()).map(m -> format(ERROR_MESSAGE_FROM_SERVER, m)).orElse(format(ERROR_MESSAGE, e.getMessage())); throw new FireboltException(msg, e); } catch (Exception e) { log.error("Failed to connect to Firebolt", e); - throw new FireboltException(format(errorMessage, e.getMessage()), e); + throw new FireboltException(format(ERROR_MESSAGE, e.getMessage()), e); } } diff --git a/src/test/java/com/firebolt/jdbc/connection/FireboltConnectionServiceSecretAuthenticationTest.java b/src/test/java/com/firebolt/jdbc/connection/FireboltConnectionServiceSecretAuthenticationTest.java index e31201303..c09ae40a9 100644 --- a/src/test/java/com/firebolt/jdbc/connection/FireboltConnectionServiceSecretAuthenticationTest.java +++ b/src/test/java/com/firebolt/jdbc/connection/FireboltConnectionServiceSecretAuthenticationTest.java @@ -19,7 +19,7 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -public class FireboltConnectionServiceSecretAuthenticationTest extends FireboltConnectionTest { +class FireboltConnectionServiceSecretAuthenticationTest extends FireboltConnectionTest { private static final String SYSTEM_ENGINE_URL = "jdbc:firebolt:db?env=dev&account=dev"; @Test diff --git a/src/test/java/com/firebolt/jdbc/connection/FireboltConnectionUserPasswordAuthenticationTest.java b/src/test/java/com/firebolt/jdbc/connection/FireboltConnectionUserPasswordAuthenticationTest.java index 70921deda..ad1324e95 100644 --- a/src/test/java/com/firebolt/jdbc/connection/FireboltConnectionUserPasswordAuthenticationTest.java +++ b/src/test/java/com/firebolt/jdbc/connection/FireboltConnectionUserPasswordAuthenticationTest.java @@ -17,7 +17,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; -public class FireboltConnectionUserPasswordAuthenticationTest extends FireboltConnectionTest { +class FireboltConnectionUserPasswordAuthenticationTest extends FireboltConnectionTest { private static final String SYSTEM_ENGINE_URL = "jdbc:firebolt:db?env=dev&account=dev&engine=system"; @Test void shouldNotValidateConnectionWhenCallingIsValidWhenUsingSystemEngine() throws SQLException {