use of org.sonar.ce.task.projectanalysis.source.linereader.LineReader in project sonarqube by SonarSource.
the class LineReadersImplTest method close_closes_all_closeables.
@Test
public void close_closes_all_closeables() {
LineReader r1 = mock(LineReader.class);
LineReader r2 = mock(LineReader.class);
CloseableIterator<Object> c1 = newCloseableIteratorMock();
CloseableIterator<Object> c2 = newCloseableIteratorMock();
SourceLineReadersFactory.LineReaders lineReaders = new SourceLineReadersFactory.LineReadersImpl(asList(r1, r2), null, asList(c1, c2));
lineReaders.close();
verify(c1).close();
verify(c2).close();
verifyNoMoreInteractions(c1, c2);
verifyZeroInteractions(r1, r2);
}
use of org.sonar.ce.task.projectanalysis.source.linereader.LineReader in project sonarqube by SonarSource.
the class LineReadersImplTest method read_calls_all_readers.
@Test
public void read_calls_all_readers() {
LineReader r1 = mock(LineReader.class);
LineReader r2 = mock(LineReader.class);
CloseableIterator<Object> c1 = newCloseableIteratorMock();
CloseableIterator<Object> c2 = newCloseableIteratorMock();
SourceLineReadersFactory.LineReadersImpl lineReaders = new SourceLineReadersFactory.LineReadersImpl(asList(r1, r2), null, asList(c1, c2));
DbFileSources.Line.Builder builder = DbFileSources.Line.newBuilder();
lineReaders.read(builder, NOOP_READ_ERROR_CONSUMER);
verify(r1).read(builder);
verify(r2).read(builder);
verifyNoMoreInteractions(r1, r2);
verifyZeroInteractions(c1, c2);
}
use of org.sonar.ce.task.projectanalysis.source.linereader.LineReader in project sonarqube by SonarSource.
the class LineReadersImplTest method read_calls_ReaderError_consumer_with_each_read_error_returned_by_all_readers.
@Test
public void read_calls_ReaderError_consumer_with_each_read_error_returned_by_all_readers() {
int readErrorCount = 2 + 2 * new Random().nextInt(10);
int halfCount = readErrorCount / 2;
ReadError[] expectedReadErrors = IntStream.range(0, readErrorCount).mapToObj(i -> new ReadError(LineReader.Data.SYMBOLS, i)).toArray(ReadError[]::new);
LineReader[] lineReaders = IntStream.range(0, halfCount).mapToObj(i -> {
LineReader lineReader = mock(LineReader.class);
when(lineReader.read(any())).thenReturn(Optional.of(expectedReadErrors[i])).thenReturn(Optional.of(expectedReadErrors[i + halfCount])).thenReturn(Optional.empty());
return lineReader;
}).toArray(LineReader[]::new);
DbFileSources.Line.Builder builder = DbFileSources.Line.newBuilder();
SourceLineReadersFactory.LineReadersImpl underTest = new SourceLineReadersFactory.LineReadersImpl(stream(lineReaders).collect(toList()), null, Collections.emptyList());
List<ReadError> readErrors = new ArrayList<>();
// calls first mocked result of each Reader mock => we get first half read errors
underTest.read(builder, readErrors::add);
assertThat(readErrors).contains(stream(expectedReadErrors).limit(halfCount).toArray(ReadError[]::new));
// calls first mocked result of each Reader mock => we get second half read errors
readErrors.clear();
underTest.read(builder, readErrors::add);
assertThat(readErrors).contains(stream(expectedReadErrors).skip(halfCount).toArray(ReadError[]::new));
// calls third mocked result of each Reader mock (empty) => consumer is never called => empty list
readErrors.clear();
underTest.read(builder, readErrors::add);
assertThat(readErrors).isEmpty();
}
use of org.sonar.ce.task.projectanalysis.source.linereader.LineReader in project sonarqube by SonarSource.
the class SourceLineReadersFactory method getLineReaders.
public LineReaders getLineReaders(Component component) {
List<LineReader> readers = new ArrayList<>();
List<CloseableIterator<?>> closeables = new ArrayList<>();
ScmLineReader scmLineReader = null;
int componentRef = component.getReportAttributes().getRef();
CloseableIterator<ScannerReport.LineCoverage> coverageIt = reportReader.readComponentCoverage(componentRef);
closeables.add(coverageIt);
readers.add(new CoverageLineReader(coverageIt));
Optional<ScmInfo> scmInfoOptional = scmInfoRepository.getScmInfo(component);
if (scmInfoOptional.isPresent()) {
scmLineReader = new ScmLineReader(scmInfoOptional.get());
readers.add(scmLineReader);
}
RangeOffsetConverter rangeOffsetConverter = new RangeOffsetConverter();
CloseableIterator<ScannerReport.SyntaxHighlightingRule> highlightingIt = reportReader.readComponentSyntaxHighlighting(componentRef);
closeables.add(highlightingIt);
readers.add(new HighlightingLineReader(component, highlightingIt, rangeOffsetConverter));
CloseableIterator<ScannerReport.Symbol> symbolsIt = reportReader.readComponentSymbols(componentRef);
closeables.add(symbolsIt);
readers.add(new SymbolsLineReader(component, symbolsIt, rangeOffsetConverter));
readers.add(new DuplicationLineReader(duplicationRepository.getDuplications(component)));
readers.add(new IsNewLineReader(newLinesRepository, component));
return new LineReadersImpl(readers, scmLineReader, closeables);
}
Aggregations