Search in sources :

Example 1 with HIGHLIGHTING

use of org.sonar.ce.task.projectanalysis.source.linereader.LineReader.Data.HIGHLIGHTING in project sonarqube by SonarSource.

the class FileSourceDataWarningsTest method create_highlighting_warning_when_any_number_of_read_error_for_one_file.

@Test
public void create_highlighting_warning_when_any_number_of_read_error_for_one_file() {
    ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setUuid("uuid").setName(path).build();
    LineReader.ReadError[] readErrors = IntStream.range(0, 1 + random.nextInt(10)).mapToObj(i -> new LineReader.ReadError(HIGHLIGHTING, line + i)).toArray(LineReader.ReadError[]::new);
    when(system2.now()).thenReturn(timeStamp);
    Arrays.stream(readErrors).forEach(readError -> underTest.addWarning(file, readError));
    verifyZeroInteractions(taskMessages);
    underTest.commitWarnings();
    verify(taskMessages, times(1)).add(new CeTaskMessages.Message("Inconsistent highlighting data detected on file '" + path + "'. " + "File source may have been modified while analysis was running.", timeStamp));
}
Also used : IntStream(java.util.stream.IntStream) Component(org.sonar.ce.task.projectanalysis.component.Component) Arrays(java.util.Arrays) System2(org.sonar.api.utils.System2) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) SYMBOLS(org.sonar.ce.task.projectanalysis.source.linereader.LineReader.Data.SYMBOLS) LineReader(org.sonar.ce.task.projectanalysis.source.linereader.LineReader) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) RunWith(org.junit.runner.RunWith) Random(java.util.Random) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) HIGHLIGHTING(org.sonar.ce.task.projectanalysis.source.linereader.LineReader.Data.HIGHLIGHTING) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) CeTaskMessages(org.sonar.ce.task.log.CeTaskMessages) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Mockito.mock(org.mockito.Mockito.mock) CeTaskMessages(org.sonar.ce.task.log.CeTaskMessages) LineReader(org.sonar.ce.task.projectanalysis.source.linereader.LineReader) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Aggregations

DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Arrays (java.util.Arrays)1 Random (java.util.Random)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 RandomStringUtils.randomAlphabetic (org.apache.commons.lang.RandomStringUtils.randomAlphabetic)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.verifyZeroInteractions (org.mockito.Mockito.verifyZeroInteractions)1 Mockito.when (org.mockito.Mockito.when)1 System2 (org.sonar.api.utils.System2)1 CeTaskMessages (org.sonar.ce.task.log.CeTaskMessages)1 Component (org.sonar.ce.task.projectanalysis.component.Component)1 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)1