]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3306 Improve unit test to fix issue on it-sonar-persistence tests
authorJulien Lancelot <julien.lancelot@gmail.com>
Mon, 3 Dec 2012 14:32:08 +0000 (15:32 +0100)
committerJulien Lancelot <julien.lancelot@gmail.com>
Mon, 3 Dec 2012 14:32:08 +0000 (15:32 +0100)
sonar-core/src/test/java/org/sonar/core/persistence/SemaphoreDaoTest.java

index 30fd3363958d952b2c52434fe154e2444c8c2b88..781d5c959971631aa7583b900ff5f9d5004e4561 100644 (file)
@@ -27,9 +27,6 @@ import org.junit.rules.ExpectedException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
 import java.util.Date;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.CyclicBarrier;
@@ -237,34 +234,12 @@ public class SemaphoreDaoTest extends AbstractDaoTestCase {
   }
 
   private boolean isRecent(Date date) {
-    Date futur = DateUtils.addDays(now(), 1);
-    Date past = DateUtils.addDays(now(), -1);
+    Date now = new Date();
+    Date futur = DateUtils.addDays(now, 1);
+    Date past = DateUtils.addDays(now, -1);
     return date.after(past) && date.before(futur);
   }
 
-  private Date now() {
-    Connection connection = null;
-    PreparedStatement statement = null;
-    ResultSet rs = null;
-    try {
-      connection = getConnection();
-      rs = null;
-      statement = connection.prepareStatement("select current_timestamp");
-      rs = statement.executeQuery();
-      if (rs.next()) {
-        return new Date();
-      }
-      return null;
-
-    } catch (Exception e) {
-      throw new RuntimeException(e);
-    } finally {
-      DatabaseUtils.closeQuietly(rs);
-      DatabaseUtils.closeQuietly(statement);
-      DatabaseUtils.closeQuietly(connection);
-    }
-  }
-
   private static class Runner extends Thread {
     SemaphoreDao dao;
     AtomicInteger locks;