Search in sources :

Example 11 with Period

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

the class NewIssueClassifierTest method isNew_returns_true_for_issue_which_was_new_and_is_still_located_on_changed_lines.

@Test
public void isNew_returns_true_for_issue_which_was_new_and_is_still_located_on_changed_lines() {
    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(2).setStartOffset(1).setEndLine(2).setEndOffset(2).build()).build());
    when(issue.isNewCodeReferenceIssue()).thenReturn(true);
    assertThat(newIssueClassifier.isNew(file, issue)).isTrue();
    assertThat(newIssueClassifier.isOnBranchUsingReferenceBranch()).isTrue();
    assertThat(newIssueClassifier.hasAtLeastOneLocationOnChangedLines(file, issue)).isTrue();
}
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 12 with Period

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

the class NewIssueClassifierTest method isNew_returns_false_if_period_without_date.

@Test
public void isNew_returns_false_if_period_without_date() {
    periodHolder.setPeriod(new Period(NewCodePeriodType.NUMBER_OF_DAYS.name(), "10", null));
    assertThat(newIssueClassifier.isNew(mock(Component.class), mock(DefaultIssue.class))).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 13 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_not_located_on_changed_lines.

@Test
public void isNew_returns_false_for_issue_not_located_on_changed_lines() {
    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());
    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 14 with Period

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

the class NewIssueClassifierTest method isNew_returns_true_for_issue_located_on_changed_lines.

@Test
public void isNew_returns_true_for_issue_located_on_changed_lines() {
    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(2).setStartOffset(1).setEndLine(2).setEndOffset(2).build()).build());
    assertThat(newIssueClassifier.isNew(file, issue)).isTrue();
    assertThat(newIssueClassifier.isOnBranchUsingReferenceBranch()).isTrue();
    assertThat(newIssueClassifier.hasAtLeastOneLocationOnChangedLines(file, issue)).isTrue();
}
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 15 with Period

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

the class NewLinesRepositoryTest method load_new_lines_from_report_when_available_and_using_reference_branch.

@Test
public void load_new_lines_from_report_when_available_and_using_reference_branch() {
    periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), null, null));
    createChangedLinesInReport(1, 2, 5);
    Optional<Set<Integer>> newLines = repository.getNewLines(FILE);
    assertThat(newLines).isPresent();
    assertThat(newLines.get()).containsOnly(1, 2, 5);
    assertThat(repository.newLinesAvailable()).isTrue();
}
Also used : Set(java.util.Set) Period(org.sonar.ce.task.projectanalysis.period.Period) 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