Java:
* Sets the database user
* Sets the database password
* Sets the database url
* The variables that are required for the connection to the database are initialized in the constructor
*/
public DataBaseConnection() {
final String databaseuser = "root";
final String databasepassword = "swp_20I";
final String url = "jdbc:mysql://heimlich/hala?useLegacyDatetimeCode=false&serverTimezone=UTC";
dataSource = new MysqlDataSource();
dataSource.setUser(databaseuser);
dataSource.setPassword(databasepassword);
dataSource.setUrl(url);
dataSource.setDatabaseName("hala");
}
/**
* Returns a new {@code Connection} to the sql database
* @return a new {@code Connection} to the sql database
* @throws SQLException if a database access error occurs
*/
public Connection getConnection() throws SQLException {
return dataSource.getConnection();
}
}
Wie könnte ich die Verbindiung testen, für jede Vorschlag oder Lösung wäre ich sehr dankbar.
Ich hab so versuch, aber leider funktioniert nicht:
//SQLException
final DataBaseConnection connection = mock(DataBaseConnection.class);
given(connection.getConnection()).willThrow(new SQLException());