From: Teryk Bellahsene Date: Tue, 13 Jan 2015 11:26:22 +0000 (+0100) Subject: fix quality flaws X-Git-Tag: latest-silver-master-#65~236 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e92ffa6e63e7321ab090e764cdf5307a67268d78;p=sonarqube.git fix quality flaws --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDates.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDates.java index dcd1feac493..da74eaf1307 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDates.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDates.java @@ -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())); } }); } diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java index a3602e8f3f2..3ae8f107ba0 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java @@ -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() diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/DefaultIssueComment.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/DefaultIssueComment.java index ad77a21f1c1..1388477326f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/DefaultIssueComment.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/DefaultIssueComment.java @@ -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; - } }