]> source.dussan.org Git - sonarqube.git/commitdiff
fix quality flaws
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 13 Jan 2015 11:26:22 +0000 (12:26 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 13 Jan 2015 11:26:22 +0000 (12:26 +0100)
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDates.java
sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java
sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/DefaultIssueComment.java

index dcd1feac4938baeff971434b72b75e2b3efba741..da74eaf13079f7e1bb4b106d93e828858fb38bb9 100644 (file)
@@ -57,21 +57,13 @@ public class FeedIssueChangesLongDates extends BaseDataChange {
 
         updateColumn(update, 1, createdAt);
         updateColumn(update, 2, updatedAt);
-        if (functionalCreatedAt == null) {
-          update.setLong(3, null);
-        } else {
-          update.setLong(3, functionalCreatedAt.getTime());
-        }
+        update.setLong(3, functionalCreatedAt == null ? null : functionalCreatedAt.getTime());
         update.setLong(4, id);
         return true;
       }
 
       private void updateColumn(SqlStatement update, int position, Date time) throws SQLException {
-        if (time == null) {
-          update.setLong(position, now);
-        } else {
-          update.setLong(position, Math.min(now, time.getTime()));
-        }
+        update.setLong(position, time == null ? now : Math.min(now, time.getTime()));
       }
     });
   }
index a3602e8f3f2a57e56bc381f4a03bb792688974dc..3ae8f107ba08f05835fe54c3cea5a87765f8f890 100644 (file)
@@ -22,10 +22,10 @@ package org.sonar.core.issue.db;
 import org.junit.Test;
 import org.sonar.api.issue.internal.DefaultIssueComment;
 import org.sonar.api.issue.internal.FieldDiffs;
-import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.api.utils.DateUtils.parseDate;
 
 public class IssueChangeDtoTest {
 
@@ -39,16 +39,26 @@ public class IssueChangeDtoTest {
     assertThat(dto.getChangeType()).isEqualTo("comment");
     assertThat(dto.getCreatedAt()).isNotNull();
     assertThat(dto.getUpdatedAt()).isNotNull();
+    assertThat(dto.getIssueChangeCreationDate()).isNotNull();
     assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
     assertThat(dto.getUserLogin()).isEqualTo("emmerik");
   }
 
+  @Test
+  public void create_from_comment_with_created_at() throws Exception {
+    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+    comment.setCreatedAt(parseDate("2015-01-13"));
+
+    IssueChangeDto dto = IssueChangeDto.of(comment);
+
+    assertThat(dto.getIssueChangeCreationDate()).isEqualTo(parseDate("2015-01-13").getTime());
+  }
+
   @Test
   public void create_from_diff() throws Exception {
     FieldDiffs diffs = new FieldDiffs();
     diffs.setDiff("severity", "INFO", "BLOCKER");
     diffs.setUserLogin("emmerik");
-    diffs.setCreationDate(DateUtils.parseDate("2014-01-03"));
 
     IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs);
 
@@ -56,11 +66,23 @@ public class IssueChangeDtoTest {
     assertThat(dto.getChangeType()).isEqualTo("diff");
     assertThat(dto.getCreatedAt()).isNotNull();
     assertThat(dto.getUpdatedAt()).isNotNull();
-    assertThat(dto.getIssueChangeCreationDate()).isEqualTo(DateUtils.parseDate("2014-01-03").getTime());
+    assertThat(dto.getIssueChangeCreationDate()).isNull();
     assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
     assertThat(dto.getUserLogin()).isEqualTo("emmerik");
   }
 
+  @Test
+  public void create_from_diff_with_created_at() throws Exception {
+    FieldDiffs diffs = new FieldDiffs();
+    diffs.setDiff("severity", "INFO", "BLOCKER");
+    diffs.setUserLogin("emmerik");
+    diffs.setCreationDate(parseDate("2015-01-13"));
+
+    IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs);
+
+    assertThat(dto.getIssueChangeCreationDate()).isEqualTo(parseDate("2015-01-13").getTime());
+  }
+
   @Test
   public void to_comment() throws Exception {
     IssueChangeDto changeDto = new IssueChangeDto()
index ad77a21f1c18731a0853234c5055b1011b00aaa8..1388477326f941b359d97d9f4749751be9544b20 100644 (file)
@@ -24,6 +24,7 @@ import org.sonar.api.utils.internal.Uuids;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
+
 import java.io.Serializable;
 import java.util.Date;
 
@@ -41,6 +42,18 @@ public class DefaultIssueComment implements Serializable, IssueComment {
   private String markdownText;
   private boolean isNew;
 
+  public static DefaultIssueComment create(String issueKey, @Nullable String login, String markdownText) {
+    DefaultIssueComment comment = new DefaultIssueComment();
+    comment.setIssueKey(issueKey);
+    comment.setKey(Uuids.create());
+    Date now = new Date();
+    comment.setUserLogin(login);
+    comment.setMarkdownText(markdownText);
+    comment.setCreatedAt(now).setUpdatedAt(now);
+    comment.setNew(true);
+    return comment;
+  }
+
   @Override
   public String markdownText() {
     return markdownText;
@@ -100,7 +113,7 @@ public class DefaultIssueComment implements Serializable, IssueComment {
     return updatedAt;
   }
 
-  public DefaultIssueComment setUpdatedAt(Date updatedAt) {
+  public DefaultIssueComment setUpdatedAt(@Nullable Date updatedAt) {
     this.updatedAt = updatedAt;
     return this;
   }
@@ -113,16 +126,4 @@ public class DefaultIssueComment implements Serializable, IssueComment {
     isNew = b;
     return this;
   }
-
-  public static DefaultIssueComment create(String issueKey, @Nullable String login, String markdownText) {
-    DefaultIssueComment comment = new DefaultIssueComment();
-    comment.setIssueKey(issueKey);
-    comment.setKey(Uuids.create());
-    Date now = new Date();
-    comment.setUserLogin(login);
-    comment.setMarkdownText(markdownText);
-    comment.setCreatedAt(now).setUpdatedAt(now);
-    comment.setNew(true);
-    return comment;
-  }
 }