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()));
}
});
}
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 {
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);
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()
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+
import java.io.Serializable;
import java.util.Date;
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;
return updatedAt;
}
- public DefaultIssueComment setUpdatedAt(Date updatedAt) {
+ public DefaultIssueComment setUpdatedAt(@Nullable Date updatedAt) {
this.updatedAt = updatedAt;
return this;
}
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;
- }
}