PostgresConnection implements IStorageConnection { public void close() throws StorageException { try { connection.close(); } catch (SQLException e) { throw new StorageException("Error closing JDBC connection: ", e); } } PostgresConnection(final ConnectionOptions options); ICompiledQuery compileQuery(final IPreparedQuery preparedQuery); boolean validate(); void close(); void commit(); void rollback();  }
@Test public void MustCorrectCloseConnection() throws StorageException, SQLException { testPostgresConnection.close(); verify(connection).close(); }
@Test public void MustInCorrectCloseConnectionWhenCloseThrowException() throws StorageException, SQLException { doThrow(new SQLException()).when(connection).close(); try { testPostgresConnection.close(); } catch (StorageException e) { verify(connection).close(); return; } assertTrue("Must throw exception", false); }