Skip to content
Permalink
Browse files

test: add tests for Driver and PgConnection (#1402)

add tests that check behaviour with null-arguments
  • Loading branch information...
AlexElin authored and davecramer committed Feb 17, 2019
1 parent 6b124a0 commit 7b52b0c9e5b9aa9a9c655bb68f23bf4ec57fd51c
@@ -200,11 +200,15 @@ private Properties loadDefaultProperties() throws IOException {
* @param url the URL of the database to connect to
* @param info a list of arbitrary tag/value pairs as connection arguments
* @return a connection to the URL or null if it isnt us
* @throws SQLException if a database access error occurs
* @exception SQLException if a database access error occurs or the url is
* {@code null}
* @see java.sql.Driver#connect
*/
@Override
public Connection connect(String url, Properties info) throws SQLException {
if (url == null) {
throw new SQLException("url is null");
}
// get defaults
Properties defaults;

@@ -1538,18 +1538,17 @@ public void run() {
}

public void abort(Executor executor) throws SQLException {
if (executor == null) {
throw new SQLException("executor is null");
}
if (isClosed()) {
return;
}

SQL_PERMISSION_ABORT.checkGuard(this);

AbortCommand command = new AbortCommand();
if (executor != null) {
executor.execute(command);
} else {
command.run();
}
executor.execute(command);
}

public void setNetworkTimeout(Executor executor /*not used*/, int milliseconds) throws SQLException {
@@ -45,6 +45,17 @@ public void urlIsNotForPostgreSQL() throws SQLException {
assertNull(driver.connect("jdbc:otherdb:database", new Properties()));
}

/**
* According to the javadoc of java.sql.Driver.connect(...), calling abort when the {@code executor} is {@code null}
* results in SQLException
*/
@Test(expected = SQLException.class)
public void urlIsNull() throws SQLException {
Driver driver = new Driver();

driver.connect(null, new Properties());
}

/*
* This tests the acceptsURL() method with a couple of well and poorly formed jdbc urls.
*/
@@ -84,4 +84,13 @@ public void testAbortOnClosedConnection() throws SQLException {
fail(e.getMessage());
}
}

/**
* According to the javadoc, calling abort when the {@code executor} is {@code null}
* results in SQLException
*/
@Test(expected = SQLException.class)
public void abortWithNullExecutor() throws SQLException {
con.abort(null);
}
}

0 comments on commit 7b52b0c

Please sign in to comment.
You can’t perform that action at this time.