Search in sources :

Example 1 with LineRange

use of org.sonar.scanner.issue.ignore.pattern.LineRange in project sonarqube by SonarSource.

the class PatternMatcherTest method shouldReturnExtraPatternForLinesOfResource.

@Test
public void shouldReturnExtraPatternForLinesOfResource() {
    String file = "foo";
    Set<LineRange> lineRanges = Sets.newHashSet();
    lineRanges.add(new LineRange(25, 28));
    patternMatcher.addPatternToExcludeLines(file, lineRanges);
    IssuePattern extraPattern = patternMatcher.getPatternsForComponent(file).iterator().next();
    assertThat(extraPattern.matchResource(file)).isTrue();
    assertThat(extraPattern.getAllLines()).isEqualTo(Sets.newHashSet(25, 26, 27, 28));
}
Also used : IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) LineRange(org.sonar.scanner.issue.ignore.pattern.LineRange) Test(org.junit.Test)

Example 2 with LineRange

use of org.sonar.scanner.issue.ignore.pattern.LineRange in project sonarqube by SonarSource.

the class IssueExclusionsRegexpScannerTest method shouldAddPatternToExcludeLines.

@Test
public void shouldAddPatternToExcludeLines() throws Exception {
    regexpScanner.scan(javaFile, new File(Resources.getResource("org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp.txt").toURI()), UTF_8);
    Set<LineRange> lineRanges = Sets.newHashSet();
    lineRanges.add(new LineRange(21, 25));
    verify(patternsInitializer).getPatternMatcher();
    verify(patternMatcher, times(1)).addPatternToExcludeLines(javaFile, lineRanges);
    verifyNoMoreInteractions(patternsInitializer);
}
Also used : File(java.io.File) LineRange(org.sonar.scanner.issue.ignore.pattern.LineRange) Test(org.junit.Test)

Example 3 with LineRange

use of org.sonar.scanner.issue.ignore.pattern.LineRange in project sonarqube by SonarSource.

the class LineRangeTest method shouldTestInclusionInRangeOfLines.

@Test
public void shouldTestInclusionInRangeOfLines() {
    LineRange range = new LineRange(12, 15);
    assertThat(range.in(3)).isFalse();
    assertThat(range.in(12)).isTrue();
    assertThat(range.in(13)).isTrue();
    assertThat(range.in(14)).isTrue();
    assertThat(range.in(15)).isTrue();
    assertThat(range.in(16)).isFalse();
}
Also used : LineRange(org.sonar.scanner.issue.ignore.pattern.LineRange) Test(org.junit.Test)

Example 4 with LineRange

use of org.sonar.scanner.issue.ignore.pattern.LineRange in project sonarqube by SonarSource.

the class LineRangeTest method testEquals.

@Test
public void testEquals() throws Exception {
    LineRange range = new LineRange(12, 15);
    assertThat(range).isEqualTo(range);
    assertThat(range).isEqualTo(new LineRange(12, 15));
    assertThat(range).isNotEqualTo(new LineRange(12, 2000));
    assertThat(range).isNotEqualTo(new LineRange(1000, 2000));
    assertThat(range).isNotEqualTo(null);
    assertThat(range).isNotEqualTo(new StringBuffer());
}
Also used : LineRange(org.sonar.scanner.issue.ignore.pattern.LineRange) Test(org.junit.Test)

Example 5 with LineRange

use of org.sonar.scanner.issue.ignore.pattern.LineRange in project sonarqube by SonarSource.

the class LineRangeTest method shouldConvertLineRangeToLines.

@Test
public void shouldConvertLineRangeToLines() {
    LineRange range = new LineRange(12, 15);
    assertThat(range.toLines()).containsOnly(12, 13, 14, 15);
}
Also used : LineRange(org.sonar.scanner.issue.ignore.pattern.LineRange) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 LineRange (org.sonar.scanner.issue.ignore.pattern.LineRange)5 File (java.io.File)1 IssuePattern (org.sonar.scanner.issue.ignore.pattern.IssuePattern)1