Search in sources :

Example 1 with SourceLineHashesComputer

use of org.sonar.core.hash.SourceLineHashesComputer in project sonarqube by SonarSource.

the class SourceLinesHashRepositoryImplTest method SignificantCodeLineHashesComputer_delegates_after_taking_ranges_into_account.

@Test
public void SignificantCodeLineHashesComputer_delegates_after_taking_ranges_into_account() {
    LineRange[] lineRanges = { new LineRange(0, 1), null, new LineRange(1, 5), new LineRange(2, 7), new LineRange(4, 5) };
    SourceLineHashesComputer lineHashComputer = mock(SourceLineHashesComputer.class);
    SignificantCodeLineHashesComputer computer = new SignificantCodeLineHashesComputer(lineHashComputer, lineRanges);
    computer.addLine("testline");
    computer.addLine("testline");
    computer.addLine("testline");
    computer.addLine("testline");
    computer.addLine("testline");
    computer.addLine("testline");
    verify(lineHashComputer).addLine("t");
    // there is an extra line at the end which will be ignored since there is no range for it
    verify(lineHashComputer, times(2)).addLine("");
    verify(lineHashComputer).addLine("estl");
    verify(lineHashComputer).addLine("stlin");
    verify(lineHashComputer).addLine("l");
    verifyNoMoreInteractions(lineHashComputer);
}
Also used : SourceLineHashesComputer(org.sonar.core.hash.SourceLineHashesComputer) LineRange(org.sonar.core.hash.LineRange) SignificantCodeLineHashesComputer(org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepositoryImpl.SignificantCodeLineHashesComputer) Test(org.junit.Test)

Example 2 with SourceLineHashesComputer

use of org.sonar.core.hash.SourceLineHashesComputer in project sonarqube by SonarSource.

the class SourceLinesHashRepositoryImplTest method assertLineHashes.

private void assertLineHashes(List<String> actualLines, String... lines) {
    assertThat(actualLines).hasSize(lines.length);
    SourceLineHashesComputer computer = new SourceLineHashesComputer();
    for (String line : lines) {
        computer.addLine(line);
    }
    List<String> expectedLines = computer.getLineHashes();
    for (int i = 0; i < expectedLines.size(); i++) {
        assertThat(actualLines.get(i)).withFailMessage("Line hash is different for line %d", i).isEqualTo(expectedLines.get(i));
    }
}
Also used : SourceLineHashesComputer(org.sonar.core.hash.SourceLineHashesComputer)

Example 3 with SourceLineHashesComputer

use of org.sonar.core.hash.SourceLineHashesComputer in project sonarqube by SonarSource.

the class FileMoveDetectionStepTest method setFileLineHashesInReport.

private void setFileLineHashesInReport(Component file, String[] content) {
    SourceLineHashesComputer computer = new SourceLineHashesComputer();
    for (String line : content) {
        computer.addLine(line);
    }
    when(sourceLinesHash.getLineHashesMatchingDBVersion(file)).thenReturn(computer.getLineHashes());
}
Also used : SourceLineHashesComputer(org.sonar.core.hash.SourceLineHashesComputer)

Aggregations

SourceLineHashesComputer (org.sonar.core.hash.SourceLineHashesComputer)3 Test (org.junit.Test)1 SignificantCodeLineHashesComputer (org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepositoryImpl.SignificantCodeLineHashesComputer)1 LineRange (org.sonar.core.hash.LineRange)1