Search in sources :

Example 6 with ScmInfo

use of org.sonar.server.computation.task.projectanalysis.scm.ScmInfo in project sonarqube by SonarSource.

the class ScmLineReaderTest method getLatestChange_returns_changeset_with_highest_date_of_read_lines.

@Test
public void getLatestChange_returns_changeset_with_highest_date_of_read_lines() {
    long refDate = 123456789L;
    Changeset changeset0 = Changeset.newChangesetBuilder().setDate(refDate - 636).setRevision("rev-1").build();
    Changeset changeset1 = Changeset.newChangesetBuilder().setDate(refDate + 1).setRevision("rev-2").build();
    Changeset changeset2 = Changeset.newChangesetBuilder().setDate(refDate + 2).setRevision("rev-3").build();
    ScmInfo scmInfo = new ScmInfoImpl(setup8LinesChangeset(changeset0, changeset1, changeset2));
    ScmLineReader lineScm = new ScmLineReader(scmInfo);
    // before any line is read, the latest change is null
    assertThat(lineScm.getLatestChange()).isNull();
    // read line 1, only one changeset => 0
    readLineAndAssertLatestChangeDate(lineScm, 1, changeset0);
    // read line 2, latest changeset is 1
    readLineAndAssertLatestChangeDate(lineScm, 2, changeset1);
    // read line 3, latest changeset is still 1
    readLineAndAssertLatestChangeDate(lineScm, 3, changeset1);
    // read line 4, latest changeset is now 2
    readLineAndAssertLatestChangeDate(lineScm, 4, changeset2);
    // read line 5 to 8, there will never be any changeset more recent than 2
    readLineAndAssertLatestChangeDate(lineScm, 5, changeset2);
    readLineAndAssertLatestChangeDate(lineScm, 6, changeset2);
    readLineAndAssertLatestChangeDate(lineScm, 7, changeset2);
    readLineAndAssertLatestChangeDate(lineScm, 8, changeset2);
}
Also used : ScmInfoImpl(org.sonar.server.computation.task.projectanalysis.scm.ScmInfoImpl) ScmInfo(org.sonar.server.computation.task.projectanalysis.scm.ScmInfo) Changeset(org.sonar.server.computation.task.projectanalysis.scm.Changeset) Test(org.junit.Test)

Aggregations

ScmInfo (org.sonar.server.computation.task.projectanalysis.scm.ScmInfo)6 Test (org.junit.Test)3 ScmInfoImpl (org.sonar.server.computation.task.projectanalysis.scm.ScmInfoImpl)3 Changeset (org.sonar.server.computation.task.projectanalysis.scm.Changeset)2 Measure (org.sonar.server.computation.task.projectanalysis.measure.Measure)1