Search in sources :

Example 1 with ScmInfoImpl

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

the class ScmLineReaderTest method set_scm_with_minim_fields.

@Test
public void set_scm_with_minim_fields() {
    ScmInfo scmInfo = new ScmInfoImpl(newArrayList(Changeset.newChangesetBuilder().setDate(123456789L).setRevision("rev-1").build()));
    ScmLineReader lineScm = new ScmLineReader(scmInfo);
    DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1);
    lineScm.read(lineBuilder);
    assertThat(lineBuilder.hasScmAuthor()).isFalse();
    assertThat(lineBuilder.getScmDate()).isEqualTo(123456789L);
    assertThat(lineBuilder.getScmRevision()).isEqualTo("rev-1");
}
Also used : ScmInfoImpl(org.sonar.server.computation.task.projectanalysis.scm.ScmInfoImpl) ScmInfo(org.sonar.server.computation.task.projectanalysis.scm.ScmInfo) Test(org.junit.Test)

Example 2 with ScmInfoImpl

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

the class ScmLineReaderTest method set_scm.

@Test
public void set_scm() {
    ScmInfo scmInfo = new ScmInfoImpl(newArrayList(Changeset.newChangesetBuilder().setAuthor("john").setDate(123456789L).setRevision("rev-1").build()));
    ScmLineReader lineScm = new ScmLineReader(scmInfo);
    DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1);
    lineScm.read(lineBuilder);
    assertThat(lineBuilder.getScmAuthor()).isEqualTo("john");
    assertThat(lineBuilder.getScmDate()).isEqualTo(123456789L);
    assertThat(lineBuilder.getScmRevision()).isEqualTo("rev-1");
}
Also used : ScmInfoImpl(org.sonar.server.computation.task.projectanalysis.scm.ScmInfoImpl) ScmInfo(org.sonar.server.computation.task.projectanalysis.scm.ScmInfo) Test(org.junit.Test)

Example 3 with ScmInfoImpl

use of org.sonar.server.computation.task.projectanalysis.scm.ScmInfoImpl 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

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