aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-03-16 14:19:55 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2015-03-16 14:28:41 +0100
commit46e1d76cc3814518f23b65132e5a8f083bb707a5 (patch)
tree515578f952a328da19a653d425850a5807d53464
parent008f29b5613739b2da1db8596bc92f103eca427e (diff)
downloadsonarqube-46e1d76cc3814518f23b65132e5a8f083bb707a5.tar.gz
sonarqube-46e1d76cc3814518f23b65132e5a8f083bb707a5.zip
Remove use of DateUtils.truncate since it is not efficient
-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, 17 insertions, 29 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 7ffa9905721..5ac780e3883 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,7 +19,6 @@
*/
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;
@@ -40,7 +39,6 @@ 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;
@@ -154,7 +152,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(DateUtils.truncate(analysisDate, Calendar.SECOND));
+ assertThat(argument.getValue().creationDate()).isEqualTo(analysisDate);
}
@Test
@@ -173,7 +171,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(DateUtils.truncate(analysisDate, Calendar.SECOND));
+ assertThat(argument.getValue().creationDate()).isEqualTo(analysisDate);
}
@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 28ce4e2c26c..454dc26b6a1 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,7 +26,6 @@ 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;
@@ -39,7 +38,6 @@ import org.sonar.api.utils.Duration;
import javax.annotation.Nullable;
-import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
@@ -184,8 +182,7 @@ public class IssueUpdater implements BatchComponent, ServerComponent {
}
public void setCloseDate(DefaultIssue issue, @Nullable Date d, IssueChangeContext context) {
- Date dateWithoutMilliseconds = d == null ? null : DateUtils.truncate(d, Calendar.SECOND);
- if (!Objects.equal(dateWithoutMilliseconds, issue.closeDate())) {
+ if (!Objects.equal(d, 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 edac8a2dd84..415f18eadb0 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,7 +29,6 @@ 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;
@@ -106,9 +105,9 @@ public class IssueDtoTest {
assertThat(issue.assignee()).isEqualTo("perceval");
assertThat(issue.attribute("key")).isEqualTo("value");
assertThat(issue.authorLogin()).isEqualTo("pierre");
- 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.creationDate()).isEqualTo(createdAt);
+ assertThat(issue.updateDate()).isEqualTo(updatedAt);
+ assertThat(issue.closeDate()).isEqualTo(closedAt);
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 1eb2430420a..7b73af28bc0 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,7 +21,6 @@ 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;
@@ -32,7 +31,6 @@ 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;
@@ -139,7 +137,6 @@ public class IssueWorkflowTest {
}
}
-
@Test
public void do_automatic_transition() throws Exception {
workflow.start();
@@ -155,7 +152,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(DateUtils.truncate(now, Calendar.SECOND));
+ assertThat(issue.updateDate()).isEqualTo(now);
}
@Test
@@ -173,7 +170,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(DateUtils.truncate(now, Calendar.SECOND));
+ assertThat(issue.updateDate()).isEqualTo(now);
}
@Test
@@ -191,7 +188,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(DateUtils.truncate(now, Calendar.SECOND));
+ assertThat(issue.updateDate()).isEqualTo(now);
}
@Test
@@ -209,10 +206,9 @@ 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(DateUtils.truncate(now, Calendar.SECOND));
+ assertThat(issue.updateDate()).isEqualTo(now);
}
-
@Test
public void fail_if_unknown_status_on_automatic_trans() throws Exception {
workflow.start();
@@ -283,7 +279,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");
@@ -291,7 +287,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");
@@ -314,7 +310,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();
@@ -325,7 +321,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 05d5d0fc5bd..04051ae4527 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,7 +29,6 @@ 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;
@@ -334,8 +333,7 @@ public class DefaultIssue implements Issue {
}
public DefaultIssue setCreationDate(Date 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);
+ this.creationDate = d;
return this;
}
@@ -346,7 +344,7 @@ public class DefaultIssue implements Issue {
}
public DefaultIssue setUpdateDate(@Nullable Date d) {
- this.updateDate = (d != null ? DateUtils.truncate(d, Calendar.SECOND) : null);
+ this.updateDate = d;
return this;
}
@@ -357,7 +355,7 @@ public class DefaultIssue implements Issue {
}
public DefaultIssue setCloseDate(@Nullable Date d) {
- this.closeDate = (d != null ? DateUtils.truncate(d, Calendar.SECOND) : null);
+ this.closeDate = d;
return this;
}