Skip to content
This repository has been archived by the owner on Feb 7, 2025. It is now read-only.

Commit

Permalink
ternaries for properties object - all tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg3lopez committed Dec 8, 2023
1 parent b1d46f6 commit 2f3136d
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,27 @@ protected Connection connect() throws SQLException {
+ "/"
+ ApplicationContext.getProperty("DB_NAME");

// Ternaries prevent NullPointerException during testing since we decided not to mock env
// vars.
var user =
ApplicationContext.getProperty("DB_USER") == null
? ""
: ApplicationContext.getProperty("DB_USER");
var pass =
ApplicationContext.getProperty("DB_PASS") == null
? ""
: ApplicationContext.getProperty("DB_PASS");
var ssl =
ApplicationContext.getProperty("DB_SSL") == null
? ""
: ApplicationContext.getProperty("DB_SSL");

Properties props = new Properties();
props.setProperty("user", ApplicationContext.getProperty("DB_USER"));
props.setProperty("password", ApplicationContext.getProperty("DB_PASS"));
props.setProperty("user", user);
props.setProperty("password", pass);

// TODO: Change this based on env
props.setProperty("ssl", ApplicationContext.getProperty("DB_SSL"));
props.setProperty("ssl", ssl);
conn = driverManager.getConnection(url, props);
logger.logInfo("DB Connected Successfully");
return conn;
Expand Down

0 comments on commit 2f3136d

Please sign in to comment.