]> source.dussan.org Git - sonarqube.git/commitdiff
issues - fix contracts
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 10 Feb 2015 17:59:17 +0000 (18:59 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 10 Feb 2015 18:54:51 +0000 (19:54 +0100)
sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java
sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDays.java
sonar-core/src/main/java/org/sonar/core/issue/db/BatchIssueDto.java
sonar-core/src/test/java/org/sonar/core/persistence/SemaphoreDaoTest.java

index 21dd83e51ab40a24b94722b8dfee230c02a9efe5..fb55fdde0a41e08922d3312ec0f719101ceda8a9 100644 (file)
@@ -39,7 +39,6 @@ import javax.annotation.Nullable;
 import java.util.Date;
 
 import static org.sonar.api.utils.DateUtils.formatDateTime;
-import static org.sonar.api.utils.DateUtils.longToDate;
 
 /**
  * Used by views !!
@@ -104,7 +103,7 @@ public class ProjectConfigurator implements BatchComponent {
           throw new IllegalArgumentException(
             "'sonar.projectDate' property cannot be older than the date of the last known quality snapshot on this project. Value: '" +
               settings.getString(CoreProperties.PROJECT_DATE_PROPERTY) + "'. " +
-              "Latest quality snapshot: '" + formatDateTime(longToDate(lastSnapshot.getCreatedAtMs()))
+              "Latest quality snapshot: '" + formatDateTime(lastSnapshot.getCreatedAt())
               + "'. This property may only be used to rebuild the past in a chronological order.");
         }
       }
index 5183236cc054b3d0404df51aad8f4595e48a4376..21ab5d15e13ebdad52bc347cf51ef8411fdb195c 100644 (file)
@@ -28,12 +28,9 @@ import org.sonar.api.resources.Qualifiers;
 import org.sonar.batch.components.PastSnapshot;
 
 import javax.annotation.CheckForNull;
-
 import java.util.Date;
 import java.util.List;
 
-import static org.sonar.api.utils.DateUtils.longToDate;
-
 public class PastSnapshotFinderByDays implements BatchExtension {
 
   private DatabaseSession session;
@@ -43,7 +40,7 @@ public class PastSnapshotFinderByDays implements BatchExtension {
   }
 
   public PastSnapshot findFromDays(Snapshot projectSnapshot, int days) {
-    Date targetDate = DateUtils.addDays(longToDate(projectSnapshot.getCreatedAtMs()), -days);
+    Date targetDate = DateUtils.addDays(projectSnapshot.getCreatedAt(), -days);
     String hql = "from " + Snapshot.class.getSimpleName() + " where resourceId=:resourceId AND status=:status AND createdAt<:date AND qualifier<>:lib order by createdAt asc";
     List<Snapshot> snapshots = session.createQuery(hql)
       .setParameter("date", projectSnapshot.getCreatedAtMs())
@@ -67,7 +64,7 @@ public class PastSnapshotFinderByDays implements BatchExtension {
     long bestDistance = Long.MAX_VALUE;
     Snapshot nearest = null;
     for (Snapshot snapshot : snapshots) {
-      long distance = distance(longToDate(snapshot.getCreatedAtMs()), targetDate);
+      long distance = distance(snapshot.getCreatedAt(), targetDate);
       if (distance <= bestDistance) {
         bestDistance = distance;
         nearest = snapshot;
index 85ee2e47bcbf53a3ba029d3e99080fd549962ea7..bd8dd1760c72728348c8ff0c4d5d7efa2501d651 100644 (file)
 
 package org.sonar.core.issue.db;
 
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
 import java.util.Date;
 
-import static org.sonar.api.utils.DateUtils.dateToLong;
-import static org.sonar.api.utils.DateUtils.longToDate;
-
 public class BatchIssueDto {
 
   private String kee;
@@ -152,13 +146,12 @@ public class BatchIssueDto {
     return this;
   }
 
-  @CheckForNull
   public Date getCreationDate() {
-    return longToDate(creationDate);
+    return new Date(creationDate);
   }
 
-  public BatchIssueDto setCreationDate(@Nullable Date creationDate) {
-    this.creationDate = dateToLong(creationDate);
+  public BatchIssueDto setCreationDate(Date creationDate) {
+    this.creationDate = creationDate.getTime();
     return this;
   }
 
index 5710a80c2a708f9034a890230c5f04de5a8b52e3..6d9c6d74eb1d332e28c4c3d10c2cb0084fa2a52d 100644 (file)
@@ -35,6 +35,8 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class SemaphoreDaoTest extends AbstractDaoTestCase {
 
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
   private SemaphoreDao dao;
   private System2 system;
 
@@ -44,8 +46,14 @@ public class SemaphoreDaoTest extends AbstractDaoTestCase {
     dao = new SemaphoreDao(getMyBatis(), system);
   }
 
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
+  @Test
+  public void should_fail_to_acquire_if_null_semaphore_name() {
+    thrown.expect(IllegalArgumentException.class);
+    thrown.expectMessage("Semaphore name must not be empty");
+
+    SemaphoreDao dao = new SemaphoreDao(getMyBatis(), system);
+    dao.acquire(null, 5000);
+  }
 
   @Test
   public void should_fail_to_acquire_if_blank_semaphore_name() {
@@ -53,7 +61,7 @@ public class SemaphoreDaoTest extends AbstractDaoTestCase {
     thrown.expectMessage("Semaphore name must not be empty");
 
     SemaphoreDao dao = new SemaphoreDao(getMyBatis(), system);
-    dao.acquire(null, 5000);
+    dao.acquire("", 5000);
   }
 
   @Test
@@ -111,6 +119,14 @@ public class SemaphoreDaoTest extends AbstractDaoTestCase {
     assertThat(selectSemaphore("foo")).isNull();
   }
 
+  @Test
+  public void fail_to_update_null_semaphore() throws Exception {
+    thrown.expect(IllegalArgumentException.class);
+    thrown.expectMessage("Semaphore must not be null");
+
+    dao.update(null);
+  }
+
   @Test
   public void create_and_acquire_semaphore_when_maxage_is_zeo() throws Exception {
     Semaphores.Semaphore lock = dao.acquire("foo", 0);