Search in sources :

Example 1 with Period

use of org.sonar.ce.task.projectanalysis.period.Period in project sonarqube by SonarSource.

the class NewLinesRepositoryTest method compute_new_lines_using_scm_info_for_period.

@Test
public void compute_new_lines_using_scm_info_for_period() {
    periodHolder.setPeriod(new Period("", null, 1000L));
    scmInfoRepository.setScmInfo(FILE.getReportAttributes().getRef(), createChangesets(1100L, 900L, 1000L, 800L));
    Optional<Set<Integer>> newLines = repository.getNewLines(FILE);
    assertThat(newLines).isPresent();
    assertThat(newLines.get()).containsOnly(1);
    assertThat(repository.newLinesAvailable()).isTrue();
}
Also used : Set(java.util.Set) Period(org.sonar.ce.task.projectanalysis.period.Period) Test(org.junit.Test)

Example 2 with Period

use of org.sonar.ce.task.projectanalysis.period.Period in project sonarqube by SonarSource.

the class NewIssueClassifierTest method isNew_returns_false_for_issue_which_was_new_but_it_is_not_located_on_changed_lines_anymore.

@Test
public void isNew_returns_false_for_issue_which_was_new_but_it_is_not_located_on_changed_lines_anymore() {
    periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "master", null));
    Component file = mock(Component.class);
    DefaultIssue issue = mock(DefaultIssue.class);
    when(file.getType()).thenReturn(Component.Type.FILE);
    when(file.getUuid()).thenReturn("fileUuid");
    when(newLinesRepository.getNewLines(file)).thenReturn(Optional.of(Set.of(2, 3)));
    when(issue.getLocations()).thenReturn(DbIssues.Locations.newBuilder().setTextRange(DbCommons.TextRange.newBuilder().setStartLine(10).setStartOffset(1).setEndLine(10).setEndOffset(2).build()).build());
    when(issue.isNewCodeReferenceIssue()).thenReturn(true);
    assertThat(newIssueClassifier.isNew(file, issue)).isFalse();
    assertThat(newIssueClassifier.isOnBranchUsingReferenceBranch()).isTrue();
    assertThat(newIssueClassifier.hasAtLeastOneLocationOnChangedLines(file, issue)).isFalse();
}
Also used : Period(org.sonar.ce.task.projectanalysis.period.Period) DefaultIssue(org.sonar.core.issue.DefaultIssue) Component(org.sonar.ce.task.projectanalysis.component.Component) Test(org.junit.Test)

Example 3 with Period

use of org.sonar.ce.task.projectanalysis.period.Period in project sonarqube by SonarSource.

the class NewIssueClassifierTest method isNew_returns_true_if_issue_is_on_period.

@Test
public void isNew_returns_true_if_issue_is_on_period() {
    periodHolder.setPeriod(new Period(NewCodePeriodType.NUMBER_OF_DAYS.name(), "10", 1000L));
    DefaultIssue issue = mock(DefaultIssue.class);
    when(issue.creationDate()).thenReturn(new Date(2000L));
    assertThat(newIssueClassifier.isNew(mock(Component.class), issue)).isTrue();
    verify(issue).creationDate();
    verifyNoMoreInteractions(issue);
}
Also used : Period(org.sonar.ce.task.projectanalysis.period.Period) DefaultIssue(org.sonar.core.issue.DefaultIssue) Component(org.sonar.ce.task.projectanalysis.component.Component) Date(java.util.Date) Test(org.junit.Test)

Example 4 with Period

use of org.sonar.ce.task.projectanalysis.period.Period in project sonarqube by SonarSource.

the class NewIssueClassifierTest method isEnabled_returns_true_when_reference_period_present.

@Test
public void isEnabled_returns_true_when_reference_period_present() {
    periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "master", null));
    assertThat(newIssueClassifier.isEnabled()).isTrue();
}
Also used : Period(org.sonar.ce.task.projectanalysis.period.Period) Test(org.junit.Test)

Example 5 with Period

use of org.sonar.ce.task.projectanalysis.period.Period in project sonarqube by SonarSource.

the class NewIssueClassifierTest method isNew_returns_false_if_issue_is_not_on_period.

@Test
public void isNew_returns_false_if_issue_is_not_on_period() {
    periodHolder.setPeriod(new Period(NewCodePeriodType.NUMBER_OF_DAYS.name(), "10", 1000L));
    DefaultIssue issue = mock(DefaultIssue.class);
    when(issue.creationDate()).thenReturn(new Date(500L));
    assertThat(newIssueClassifier.isNew(mock(Component.class), issue)).isFalse();
    verify(issue).creationDate();
    verifyNoMoreInteractions(issue);
}
Also used : Period(org.sonar.ce.task.projectanalysis.period.Period) DefaultIssue(org.sonar.core.issue.DefaultIssue) Component(org.sonar.ce.task.projectanalysis.component.Component) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Period (org.sonar.ce.task.projectanalysis.period.Period)17 Test (org.junit.Test)15 Component (org.sonar.ce.task.projectanalysis.component.Component)10 DefaultIssue (org.sonar.core.issue.DefaultIssue)7 Set (java.util.Set)3 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)3 ComponentDto (org.sonar.db.component.ComponentDto)3 SnapshotDto (org.sonar.db.component.SnapshotDto)3 Date (java.util.Date)2 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)2 ViewsComponent (org.sonar.ce.task.projectanalysis.component.ViewsComponent)1 DbSession (org.sonar.db.DbSession)1 NewCodePeriodDto (org.sonar.db.newcodeperiod.NewCodePeriodDto)1