public long calculate(
     DefaultIssue issue, Collection<IssueChangeDto> debtChangelog, Period period) {
   if (issue.creationDate().getTime() > period.getSnapshotDate() + 1000L) {
     return MoreObjects.firstNonNull(issue.effortInMinutes(), 0L);
   }
   return calculateFromChangelog(issue, debtChangelog, period.getSnapshotDate());
 }
Exemplo n.º 2
0
  @Test
  public void set_issue_fields() {
    Date createdAt = DateUtils.addDays(new Date(), -5);
    Date updatedAt = DateUtils.addDays(new Date(), -3);
    Date closedAt = DateUtils.addDays(new Date(), -1);

    IssueDto dto =
        new IssueDto()
            .setKee("100")
            .setType(RuleType.VULNERABILITY)
            .setRuleId(1)
            .setRuleKey("squid", "AvoidCycle")
            .setLanguage("xoo")
            .setComponentKey("org.sonar.sample:Sample")
            .setComponentUuid("CDEF")
            .setProjectUuid("GHIJ")
            .setModuleUuid("BCDE")
            .setModuleUuidPath("ABCD.BCDE.")
            .setProjectKey("org.sonar.sample")
            .setStatus(Issue.STATUS_CLOSED)
            .setResolution(Issue.RESOLUTION_FALSE_POSITIVE)
            .setGap(15.0)
            .setEffort(10L)
            .setLine(6)
            .setSeverity("BLOCKER")
            .setMessage("message")
            .setManualSeverity(true)
            .setAssignee("perceval")
            .setIssueAttributes("key=value")
            .setAuthorLogin("pierre")
            .setIssueCreationDate(createdAt)
            .setIssueUpdateDate(updatedAt)
            .setIssueCloseDate(closedAt);

    DefaultIssue issue = dto.toDefaultIssue();
    assertThat(issue.key()).isEqualTo("100");
    assertThat(issue.type()).isEqualTo(RuleType.VULNERABILITY);
    assertThat(issue.ruleKey().toString()).isEqualTo("squid:AvoidCycle");
    assertThat(issue.language()).isEqualTo("xoo");
    assertThat(issue.componentUuid()).isEqualTo("CDEF");
    assertThat(issue.projectUuid()).isEqualTo("GHIJ");
    assertThat(issue.componentKey()).isEqualTo("org.sonar.sample:Sample");
    assertThat(issue.moduleUuid()).isEqualTo("BCDE");
    assertThat(issue.moduleUuidPath()).isEqualTo("ABCD.BCDE.");
    assertThat(issue.projectKey()).isEqualTo("org.sonar.sample");
    assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED);
    assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FALSE_POSITIVE);
    assertThat(issue.gap()).isEqualTo(15.0);
    assertThat(issue.effort()).isEqualTo(Duration.create(10L));
    assertThat(issue.line()).isEqualTo(6);
    assertThat(issue.severity()).isEqualTo("BLOCKER");
    assertThat(issue.message()).isEqualTo("message");
    assertThat(issue.manualSeverity()).isTrue();
    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.isNew()).isFalse();
  }