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);
}
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));
}
}
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());
}
Aggregations