use of org.sonar.core.hash.LineRange in project sonarqube by SonarSource.
the class SourceLinesHashRepositoryImplTest method should_generate_to_persist_if_needed.
@Test
public void should_generate_to_persist_if_needed() {
List<String> lineHashes = Lists.newArrayList("line1", "line2", "line3");
LineRange[] lineRanges = { new LineRange(0, 1), null, new LineRange(1, 5) };
sourceLinesHashCache.computeIfAbsent(file, c -> lineHashes);
// DB has line hashes without significant code and significant code is available in the report, so we need to generate new line hashes
when(dbLineHashVersion.hasLineHashesWithoutSignificantCode(file)).thenReturn(true);
when(significantCodeRepository.getRangesPerLine(file)).thenReturn(Optional.of(lineRanges));
LineHashesComputer hashesComputer = underTest.getLineHashesComputerToPersist(file);
assertThat(hashesComputer).isInstanceOf(SignificantCodeLineHashesComputer.class);
}
use of org.sonar.core.hash.LineRange in project sonarqube by SonarSource.
the class SignificantCodeRepositoryTest method translate_offset_for_each_line.
@Test
public void translate_offset_for_each_line() {
Component component = createComponent(1);
List<ScannerReport.LineSgnificantCode> significantCode = new ArrayList<>();
significantCode.add(createLineSignificantCode(1, 1, 2));
reportReader.putSignificantCode(component.getReportAttributes().getRef(), significantCode);
assertThat(underTest.getRangesPerLine(component)).isNotEmpty();
LineRange[] lines = underTest.getRangesPerLine(component).get();
assertThat(lines).hasSize(1);
assertThat(lines[0].startOffset()).isOne();
assertThat(lines[0].endOffset()).isEqualTo(2);
}
use of org.sonar.core.hash.LineRange in project sonarqube by SonarSource.
the class SignificantCodeRepositoryTest method return_null_for_lines_without_information.
@Test
public void return_null_for_lines_without_information() {
Component component = createComponent(5);
List<ScannerReport.LineSgnificantCode> significantCode = new ArrayList<>();
// line 3 and 5 missing
significantCode.add(createLineSignificantCode(1, 1, 2));
significantCode.add(createLineSignificantCode(2, 1, 2));
significantCode.add(createLineSignificantCode(4, 1, 2));
reportReader.putSignificantCode(component.getReportAttributes().getRef(), significantCode);
assertThat(underTest.getRangesPerLine(component)).isNotEmpty();
LineRange[] lines = underTest.getRangesPerLine(component).get();
assertThat(lines).hasSize(5);
assertThat(lines[0]).isNotNull();
assertThat(lines[1]).isNotNull();
assertThat(lines[2]).isNull();
assertThat(lines[3]).isNotNull();
assertThat(lines[4]).isNull();
}
Aggregations