Search in sources :

Example 1 with ScmInfoImpl

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

the class ScmLineReaderTest method set_scm.

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

Example 2 with ScmInfoImpl

use of org.sonar.ce.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(new Changeset[] { Changeset.newChangesetBuilder().setDate(123456789L).build() });
    ScmLineReader lineScm = new ScmLineReader(scmInfo);
    DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1);
    assertThat(lineScm.read(lineBuilder)).isEmpty();
    assertThat(lineBuilder.hasScmAuthor()).isFalse();
    assertThat(lineBuilder.getScmDate()).isEqualTo(123456789L);
    assertThat(lineBuilder.hasScmRevision()).isFalse();
}
Also used : ScmInfoImpl(org.sonar.ce.task.projectanalysis.scm.ScmInfoImpl) ScmInfo(org.sonar.ce.task.projectanalysis.scm.ScmInfo) Test(org.junit.Test)

Example 3 with ScmInfoImpl

use of org.sonar.ce.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 = 123_456_789L;
    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).build();
    ScmInfo scmInfo = new ScmInfoImpl(setup8LinesChangeset(changeset0, changeset1, changeset2));
    ScmLineReader lineScm = new ScmLineReader(scmInfo);
    // before any line is read, the latest changes are null
    assertThat(lineScm.getLatestChange()).isNull();
    assertThat(lineScm.getLatestChangeWithRevision()).isNull();
    // read line 1, only one changeset => 0
    readLineAndAssertLatestChanges(lineScm, 1, changeset0, changeset0);
    // read line 2, latest changeset is 1
    readLineAndAssertLatestChanges(lineScm, 2, changeset1, changeset1);
    // read line 3, latest changeset is still 1
    readLineAndAssertLatestChanges(lineScm, 3, changeset1, changeset1);
    // read line 4, latest changeset is now 2
    readLineAndAssertLatestChanges(lineScm, 4, changeset2, changeset1);
    // read line 5 to 8, there will never be any changeset more recent than 2
    readLineAndAssertLatestChanges(lineScm, 5, changeset2, changeset1);
    readLineAndAssertLatestChanges(lineScm, 6, changeset2, changeset1);
    readLineAndAssertLatestChanges(lineScm, 7, changeset2, changeset1);
    readLineAndAssertLatestChanges(lineScm, 8, changeset2, changeset1);
}
Also used : ScmInfoImpl(org.sonar.ce.task.projectanalysis.scm.ScmInfoImpl) ScmInfo(org.sonar.ce.task.projectanalysis.scm.ScmInfo) Changeset(org.sonar.ce.task.projectanalysis.scm.Changeset) Test(org.junit.Test)

Aggregations

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