*
* @since 3.6
*/
-@DependsUpon(DecoratorBarriers.END_OF_VIOLATION_TRACKING)
+@DependsUpon(DecoratorBarriers.ISSUES_TRACKED)
public class CountUnresolvedIssuesDecorator implements Decorator {
private final ResourcePerspectives perspectives;
}
private boolean isAfter(Issue issue, @Nullable Date date) {
- return date == null || (issue.creationDate() != null && issue.creationDate().after(date));
+ return date == null || (issue.creationDate() != null && DateUtils.truncatedCompareTo(issue.creationDate(), date, Calendar.SECOND)>0);
}
private boolean shouldSaveNewMetrics(DecoratorContext context) {
import org.sonar.batch.components.PastSnapshot;
import org.sonar.batch.components.TimeMachineConfiguration;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
Date rightNow;
Date tenDaysAgo;
Date fiveDaysAgo;
+ Date sameSecond;
@Before
public void before() {
rightNow = new Date();
tenDaysAgo = DateUtils.addDays(rightNow, -10);
fiveDaysAgo = DateUtils.addDays(rightNow, -5);
+ sameSecond = DateUtils.truncate(rightNow, Calendar.SECOND);
PastSnapshot pastSnapshot = mock(PastSnapshot.class);
when(pastSnapshot.getIndex()).thenReturn(1);
assertThat(decorator.countIssuesAfterDate(null, fiveDaysAgo)).isEqualTo(0);
assertThat(decorator.countIssuesAfterDate(issues, fiveDaysAgo)).isEqualTo(1); // 1 rightNow
assertThat(decorator.countIssuesAfterDate(issues, tenDaysAgo)).isEqualTo(3); // 1 rightNow + 2 fiveDaysAgo
+ assertThat(decorator.countIssuesAfterDate(issues, sameSecond)).isEqualTo(0); // 0
}
@Test
*/
package org.sonar.batch.issue;
+import org.apache.commons.lang.time.DateUtils;
+import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.rules.Violation;
+import java.util.Calendar;
import java.util.Date;
import static org.fest.assertions.Assertions.assertThat;
IssueFilters filters = mock(IssueFilters.class);
ScanIssues scanIssues = new ScanIssues(qProfile, cache, project, filters);
+ @Before
+ public void setUp() {
+ when(project.getAnalysisDate()).thenReturn(new Date());
+ }
@Test
public void should_ignore_null_active_rule() throws Exception {
when(qProfile.getActiveRule(anyString(), anyString())).thenReturn(null);
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
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
import com.google.common.base.Objects;
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.internal.DefaultIssue;
import javax.annotation.Nullable;
+import java.util.Calendar;
import java.util.Date;
/**
}
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);
</foreach>
</if>
<if test="query.createdAfter() != null">
- and i.issue_creation_date >= #{query.createdAfter}
+ and i.issue_creation_date > #{query.createdAfter}
</if>
<if test="query.createdBefore() != null">
and i.issue_creation_date < #{query.createdBefore}
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
+import java.util.Calendar;
import java.util.Date;
import static org.fest.assertions.Assertions.assertThat;
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();
}
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;
import javax.annotation.Nullable;
+import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;
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
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
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
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));
}
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;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.io.Serializable;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
* PLUGINS MUST NOT BE USED THIS CLASS, EXCEPT FOR UNIT TESTING.
}
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;
}
}
public DefaultIssue setUpdateDate(@Nullable Date d) {
- this.updateDate = d;
+ this.updateDate = (d != null ? DateUtils.truncate(d, Calendar.SECOND) : null);
return this;
}
}
public DefaultIssue setCloseDate(@Nullable Date d) {
- this.closeDate = d;
+ this.closeDate = (d != null ? DateUtils.truncate(d, Calendar.SECOND) : null);
return this;
}