aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java6
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java5
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java7
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/workflow/IssueWorkflowTest.java20
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/DefaultIssue.java8
5 files changed, 29 insertions, 17 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
index 5ac780e3883..7ffa9905721 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.batch.issue;
+import org.apache.commons.lang.time.DateUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -39,6 +40,7 @@ import org.sonar.api.rules.Violation;
import org.sonar.api.utils.Duration;
import org.sonar.api.utils.MessageException;
+import java.util.Calendar;
import java.util.Date;
import static org.assertj.core.api.Assertions.assertThat;
@@ -152,7 +154,7 @@ public class ModuleIssuesTest {
ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class);
verify(cache).put(argument.capture());
assertThat(argument.getValue().severity()).isEqualTo(Severity.CRITICAL);
- assertThat(argument.getValue().creationDate()).isEqualTo(analysisDate);
+ assertThat(argument.getValue().creationDate()).isEqualTo(DateUtils.truncate(analysisDate, Calendar.SECOND));
}
@Test
@@ -171,7 +173,7 @@ public class ModuleIssuesTest {
ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class);
verify(cache).put(argument.capture());
assertThat(argument.getValue().severity()).isEqualTo(Severity.INFO);
- assertThat(argument.getValue().creationDate()).isEqualTo(analysisDate);
+ assertThat(argument.getValue().creationDate()).isEqualTo(DateUtils.truncate(analysisDate, Calendar.SECOND));
}
@Test
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java b/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java
index 454dc26b6a1..28ce4e2c26c 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java
@@ -26,6 +26,7 @@ import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.time.DateUtils;
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
import org.sonar.api.issue.ActionPlan;
@@ -38,6 +39,7 @@ import org.sonar.api.utils.Duration;
import javax.annotation.Nullable;
+import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
@@ -182,7 +184,8 @@ public class IssueUpdater implements BatchComponent, ServerComponent {
}
public void setCloseDate(DefaultIssue issue, @Nullable Date d, IssueChangeContext context) {
- if (!Objects.equal(d, issue.closeDate())) {
+ Date dateWithoutMilliseconds = d == null ? null : DateUtils.truncate(d, Calendar.SECOND);
+ if (!Objects.equal(dateWithoutMilliseconds, issue.closeDate())) {
issue.setCloseDate(d);
issue.setUpdateDate(context.date());
issue.setChanged(true);
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java
index 415f18eadb0..edac8a2dd84 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java
@@ -29,6 +29,7 @@ import org.sonar.api.utils.Duration;
import org.sonar.core.rule.RuleDto;
import java.util.Arrays;
+import java.util.Calendar;
import java.util.Date;
import static org.assertj.core.api.Assertions.assertThat;
@@ -105,9 +106,9 @@ public class IssueDtoTest {
assertThat(issue.assignee()).isEqualTo("perceval");
assertThat(issue.attribute("key")).isEqualTo("value");
assertThat(issue.authorLogin()).isEqualTo("pierre");
- assertThat(issue.creationDate()).isEqualTo(createdAt);
- assertThat(issue.updateDate()).isEqualTo(updatedAt);
- assertThat(issue.closeDate()).isEqualTo(closedAt);
+ assertThat(issue.creationDate()).isEqualTo(DateUtils.truncate(createdAt, Calendar.SECOND));
+ assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(updatedAt, Calendar.SECOND));
+ assertThat(issue.closeDate()).isEqualTo(DateUtils.truncate(closedAt, Calendar.SECOND));
assertThat(issue.isNew()).isFalse();
}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/workflow/IssueWorkflowTest.java b/sonar-core/src/test/java/org/sonar/core/issue/workflow/IssueWorkflowTest.java
index 7b73af28bc0..1eb2430420a 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/workflow/IssueWorkflowTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/workflow/IssueWorkflowTest.java
@@ -21,6 +21,7 @@ package org.sonar.core.issue.workflow;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
+import org.apache.commons.lang.time.DateUtils;
import org.junit.Test;
import org.sonar.api.issue.DefaultTransitions;
import org.sonar.api.issue.Issue;
@@ -31,6 +32,7 @@ import org.sonar.core.issue.IssueUpdater;
import javax.annotation.Nullable;
+import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;
@@ -137,6 +139,7 @@ public class IssueWorkflowTest {
}
}
+
@Test
public void do_automatic_transition() throws Exception {
workflow.start();
@@ -152,7 +155,7 @@ public class IssueWorkflowTest {
assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FIXED);
assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED);
assertThat(issue.closeDate()).isNotNull();
- assertThat(issue.updateDate()).isEqualTo(now);
+ assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(now, Calendar.SECOND));
}
@Test
@@ -170,7 +173,7 @@ public class IssueWorkflowTest {
assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FIXED);
assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED);
assertThat(issue.closeDate()).isNotNull();
- assertThat(issue.updateDate()).isEqualTo(now);
+ assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(now, Calendar.SECOND));
}
@Test
@@ -188,7 +191,7 @@ public class IssueWorkflowTest {
assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FIXED);
assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED);
assertThat(issue.closeDate()).isNotNull();
- assertThat(issue.updateDate()).isEqualTo(now);
+ assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(now, Calendar.SECOND));
}
@Test
@@ -206,9 +209,10 @@ public class IssueWorkflowTest {
assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FIXED);
assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED);
assertThat(issue.closeDate()).isNotNull();
- assertThat(issue.updateDate()).isEqualTo(now);
+ assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(now, Calendar.SECOND));
}
+
@Test
public void fail_if_unknown_status_on_automatic_trans() throws Exception {
workflow.start();
@@ -279,7 +283,7 @@ public class IssueWorkflowTest {
Transition.create("resolve", "OPEN", "RESOLVED"),
Transition.create("falsepositive", "OPEN", "RESOLVED"),
Transition.create("wontfix", "OPEN", "RESOLVED")
- );
+ );
workflow.doTransition(issue, "resolve", mock(IssueChangeContext.class));
assertThat(issue.resolution()).isEqualTo("FIXED");
@@ -287,7 +291,7 @@ public class IssueWorkflowTest {
assertThat(workflow.outTransitions(issue)).containsOnly(
Transition.create("reopen", "RESOLVED", "REOPENED")
- );
+ );
workflow.doAutomaticTransition(issue, mock(IssueChangeContext.class));
assertThat(issue.resolution()).isEqualTo("FIXED");
@@ -310,7 +314,7 @@ public class IssueWorkflowTest {
Transition.create("resolve", "OPEN", "RESOLVED"),
Transition.create("falsepositive", "OPEN", "RESOLVED"),
Transition.create("wontfix", "OPEN", "RESOLVED")
- );
+ );
workflow.doTransition(issue, "confirm", mock(IssueChangeContext.class));
assertThat(issue.resolution()).isNull();
@@ -321,7 +325,7 @@ public class IssueWorkflowTest {
Transition.create("resolve", "CONFIRMED", "RESOLVED"),
Transition.create("falsepositive", "CONFIRMED", "RESOLVED"),
Transition.create("wontfix", "CONFIRMED", "RESOLVED")
- );
+ );
// keep confirmed and unresolved
workflow.doAutomaticTransition(issue, mock(IssueChangeContext.class));
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/DefaultIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/DefaultIssue.java
index 04051ae4527..05d5d0fc5bd 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/DefaultIssue.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/DefaultIssue.java
@@ -29,6 +29,7 @@ import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
+import org.apache.commons.lang.time.DateUtils;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.IssueComment;
import org.sonar.api.rule.RuleKey;
@@ -333,7 +334,8 @@ public class DefaultIssue implements Issue {
}
public DefaultIssue setCreationDate(Date d) {
- this.creationDate = d;
+ // d is not marked as Nullable but we still allow null parameter for unit testing.
+ this.creationDate = (d != null ? DateUtils.truncate(d, Calendar.SECOND) : null);
return this;
}
@@ -344,7 +346,7 @@ public class DefaultIssue implements Issue {
}
public DefaultIssue setUpdateDate(@Nullable Date d) {
- this.updateDate = d;
+ this.updateDate = (d != null ? DateUtils.truncate(d, Calendar.SECOND) : null);
return this;
}
@@ -355,7 +357,7 @@ public class DefaultIssue implements Issue {
}
public DefaultIssue setCloseDate(@Nullable Date d) {
- this.closeDate = d;
+ this.closeDate = (d != null ? DateUtils.truncate(d, Calendar.SECOND) : null);
return this;
}