]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 6 Feb 2014 10:24:47 +0000 (11:24 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 6 Feb 2014 10:24:47 +0000 (11:24 +0100)
sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java

index 408ced20c9d089d105c647df053bece5e4d3788c..1ff0b86a1efeab5b184e52a10bf8daa2155de056 100644 (file)
@@ -24,6 +24,8 @@ import org.sonar.api.issue.internal.DefaultIssueComment;
 import org.sonar.api.issue.internal.FieldDiffs;
 import org.sonar.api.utils.DateUtils;
 
+import java.util.Date;
+
 import static org.fest.assertions.Assertions.assertThat;
 
 public class IssueChangeDtoTest {
@@ -62,14 +64,51 @@ public class IssueChangeDtoTest {
 
   @Test
   public void to_comment() throws Exception {
-    FieldDiffs diffs = new FieldDiffs();
-    diffs.setDiff("severity", "INFO", "BLOCKER");
-    diffs.setUserLogin("emmerik");
-    diffs.setCreationDate(null);
+    IssueChangeDto changeDto = new IssueChangeDto()
+      .setKey("EFGH")
+      .setUserLogin("emmerik")
+      .setChangeData("Some text")
+      .setIssueKey("ABCDE")
+      .setCreatedAt(new Date())
+      .setUpdatedAt(new Date());
+
+    DefaultIssueComment comment = changeDto.toComment();
+    assertThat(comment.key()).isEqualTo("EFGH");
+    assertThat(comment.markdownText()).isEqualTo("Some text");
+    assertThat(comment.createdAt()).isNotNull();
+    assertThat(comment.updatedAt()).isNotNull();
+    assertThat(comment.userLogin()).isEqualTo("emmerik");
+    assertThat(comment.issueKey()).isEqualTo("ABCDE");
+  }
 
-    DefaultIssueComment comment = IssueChangeDto.of("ABCDE", diffs).toComment();
+  @Test
+  public void to_field_diffs_with_issue_creation_date() throws Exception {
+    IssueChangeDto changeDto = new IssueChangeDto()
+      .setKey("EFGH")
+      .setUserLogin("emmerik")
+      .setChangeData("Some text")
+      .setIssueKey("ABCDE")
+      .setIssueChangeCreationDate(new Date());
 
+    FieldDiffs diffs = changeDto.toFieldDiffs();
+    assertThat(diffs.userLogin()).isEqualTo("emmerik");
+    assertThat(diffs.issueKey()).isEqualTo("ABCDE");
+    assertThat(diffs.creationDate()).isNotNull();
+  }
+
+  @Test
+  public void to_field_diffs_with_create_at() throws Exception {
+    IssueChangeDto changeDto = new IssueChangeDto()
+      .setKey("EFGH")
+      .setUserLogin("emmerik")
+      .setChangeData("Some text")
+      .setIssueKey("ABCDE")
+      .setCreatedAt(new Date());
 
+    FieldDiffs diffs = changeDto.toFieldDiffs();
+    assertThat(diffs.userLogin()).isEqualTo("emmerik");
+    assertThat(diffs.issueKey()).isEqualTo("ABCDE");
+    assertThat(diffs.creationDate()).isNotNull();
   }
 
   @Test