Search in sources :

Example 1 with DefaultTextRange

use of org.sonar.api.batch.fs.internal.DefaultTextRange in project sonarlint-core by SonarSource.

the class DefaultClientIssueTest method transformIssue.

@Test
public void transformIssue() {
    textRange = new DefaultTextRange(new DefaultTextPointer(1, 2), new DefaultTextPointer(2, 3));
    IssueLocation location1 = mock(IssueLocation.class);
    when(location1.textRange()).thenReturn(new DefaultTextRange(new DefaultTextPointer(4, 4), new DefaultTextPointer(5, 5)));
    when(location1.message()).thenReturn("location1");
    IssueLocation location2 = mock(IssueLocation.class);
    when(location2.textRange()).thenReturn(new DefaultTextRange(new DefaultTextPointer(6, 6), new DefaultTextPointer(7, 7)));
    when(location2.message()).thenReturn("location2");
    when(rule.name()).thenReturn("name");
    Flow flow1 = mock(Flow.class);
    when(flow1.locations()).thenReturn(Collections.singletonList(location1));
    Flow flow2 = mock(Flow.class);
    when(flow2.locations()).thenReturn(Arrays.asList(location1, location2));
    issue = new DefaultClientIssue("MAJOR", "BUG", activeRule, rule, "msg", textRange, clientInputFile, Arrays.asList(flow1, flow2));
    assertThat(issue.getStartLine()).isEqualTo(1);
    assertThat(issue.getStartLineOffset()).isEqualTo(2);
    assertThat(issue.getEndLine()).isEqualTo(2);
    assertThat(issue.getEndLineOffset()).isEqualTo(3);
    assertThat(issue.getMessage()).isEqualTo("msg");
    assertThat(issue.getSeverity()).isEqualTo("MAJOR");
    assertThat(issue.getInputFile()).isEqualTo(clientInputFile);
    assertThat(issue.getRuleName()).isEqualTo("name");
    assertThat(issue.flows()).hasSize(2);
    assertThat(issue.flows().get(0).locations()).hasSize(1);
    assertThat(issue.flows().get(0).locations().get(0)).extracting("startLine", "startLineOffset", "endLine", "endLineOffset", "message").containsExactly(4, 4, 5, 5, "location1");
    assertThat(issue.flows().get(1).locations()).hasSize(2);
    assertThat(issue.flows().get(1).locations().get(0)).extracting("startLine", "startLineOffset", "endLine", "endLineOffset", "message").containsExactly(4, 4, 5, 5, "location1");
    assertThat(issue.flows().get(1).locations().get(1)).extracting("startLine", "startLineOffset", "endLine", "endLineOffset", "message").containsExactly(6, 6, 7, 7, "location2");
}
Also used : DefaultTextRange(org.sonar.api.batch.fs.internal.DefaultTextRange) DefaultTextPointer(org.sonar.api.batch.fs.internal.DefaultTextPointer) IssueLocation(org.sonar.api.batch.sensor.issue.IssueLocation) Flow(org.sonar.api.batch.sensor.issue.Issue.Flow) Test(org.junit.Test)

Example 2 with DefaultTextRange

use of org.sonar.api.batch.fs.internal.DefaultTextRange in project sonarqube by SonarSource.

the class SymbolReferencesSensorTest method testExecution.

@Test
public void testExecution() throws IOException {
    File symbol = new File(baseDir, "src/foo.xoo.symbol");
    FileUtils.write(symbol, "1:1:1:4,1:7:1:10\n1:11:1:13,1:14:1:33\n\n#comment");
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").initMetadata("xoo file with some source code and length over 33").setLanguage(Xoo.KEY).setModuleBaseDir(baseDir.toPath()).build();
    context.fileSystem().add(inputFile);
    sensor.execute(context);
    assertThat(context.referencesForSymbolAt("foo:src/foo.xoo", 1, 2)).containsOnly(new DefaultTextRange(new DefaultTextPointer(1, 7), new DefaultTextPointer(1, 10)));
    assertThat(context.referencesForSymbolAt("foo:src/foo.xoo", 1, 12)).containsOnly(new DefaultTextRange(new DefaultTextPointer(1, 14), new DefaultTextPointer(1, 33)));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) DefaultTextRange(org.sonar.api.batch.fs.internal.DefaultTextRange) DefaultTextPointer(org.sonar.api.batch.fs.internal.DefaultTextPointer) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 DefaultTextPointer (org.sonar.api.batch.fs.internal.DefaultTextPointer)2 DefaultTextRange (org.sonar.api.batch.fs.internal.DefaultTextRange)2 File (java.io.File)1 InputFile (org.sonar.api.batch.fs.InputFile)1 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)1 Flow (org.sonar.api.batch.sensor.issue.Issue.Flow)1 IssueLocation (org.sonar.api.batch.sensor.issue.IssueLocation)1