aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-10-18 11:24:03 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-10-18 11:24:03 +0200
commit5f5c2ec04cce8e225e4bb8c564defe88b6a8ca73 (patch)
treeba0f5e76a147ab3be76d139923b2e9027161225f /sonar-core
parente5e0806dc26dbb84138d4118cacc7300f526e7a7 (diff)
downloadsonarqube-5f5c2ec04cce8e225e4bb8c564defe88b6a8ca73.tar.gz
sonarqube-5f5c2ec04cce8e225e4bb8c564defe88b6a8ca73.zip
Fix compatibility of unit test with Java 5
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/DatabaseUtilsTest.java44
1 files changed, 40 insertions, 4 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/DatabaseUtilsTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/DatabaseUtilsTest.java
index fa06f57d9bd..7c0080db435 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/DatabaseUtilsTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/DatabaseUtilsTest.java
@@ -37,10 +37,10 @@ public class DatabaseUtilsTest extends AbstractDaoTestCase {
@Test
public void should_close_connection() throws SQLException {
Connection connection = getConnection();
- assertThat(connection.isClosed()).isFalse();
+ assertThat(isClosed(connection)).isFalse();
DatabaseUtils.closeQuietly(connection);
- assertThat(connection.isClosed()).isTrue();
+ assertThat(isClosed(connection)).isTrue();
}
@Test
@@ -59,8 +59,8 @@ public class DatabaseUtilsTest extends AbstractDaoTestCase {
DatabaseUtils.closeQuietly(rs);
DatabaseUtils.closeQuietly(statement);
- assertThat(statement.isClosed()).isTrue();
- // can not execute: assertThat(rs.isClosed()).isTrue(); -> isClosed() has been introduced in Java 6
+ assertThat(isClosed(statement)).isTrue();
+ assertThat(isClosed(rs)).isTrue();
} finally {
DatabaseUtils.closeQuietly(connection);
}
@@ -98,4 +98,40 @@ public class DatabaseUtilsTest extends AbstractDaoTestCase {
// no failure
verify(rs).close(); // just to be sure
}
+
+ /**
+ * Connection.isClosed() has been introduced in java 1.6
+ */
+ private boolean isClosed(Connection c) {
+ try {
+ c.createStatement().execute("SELECT 1");
+ return false;
+ } catch (Exception e) {
+ return true;
+ }
+ }
+
+ /**
+ * Statement.isClosed() has been introduced in java 1.6
+ */
+ private boolean isClosed(Statement s) {
+ try {
+ s.execute("SELECT 1");
+ return false;
+ } catch (Exception e) {
+ return true;
+ }
+ }
+
+ /**
+ * ResultSet.isClosed() has been introduced in java 1.6
+ */
+ private boolean isClosed(ResultSet rs) {
+ try {
+ rs.next();
+ return false;
+ } catch (Exception e) {
+ return true;
+ }
+ }
}