Exemplo n.º 1
0
  @Test
  public void doNotIgnoreWhenNotFoundInSquid() {
    NoSonarFilter filter = new NoSonarFilter();
    JavaFile javaFile = new JavaFile("org.foo.Bar");

    assertThat(filter.isIgnored(new Violation(null, javaFile).setLineId(30)), is(false));
  }
Exemplo n.º 2
0
  @Test
  public void ignoreLinesCommentedWithNoSonar() {
    NoSonarFilter filter = new NoSonarFilter();
    JavaFile javaFile = new JavaFile("org.foo.Bar");

    Set<Integer> noSonarLines = new HashSet<Integer>();
    noSonarLines.add(31);
    noSonarLines.add(55);
    filter.addResource(javaFile, noSonarLines);

    // violation on class
    assertThat(filter.isIgnored(new Violation(null, javaFile)), is(false));

    // violation on lines
    assertThat(filter.isIgnored(new Violation(null, javaFile).setLineId(30)), is(false));
    assertThat(filter.isIgnored(new Violation(null, javaFile).setLineId(31)), is(true));
  }
Exemplo n.º 3
0
  @Test
  public void should_accept_issues_on_no_sonar_rules() {
    // The "No Sonar" rule logs violations on the lines that are flagged with "NOSONAR" !!
    FilterableIssue issue = mock(FilterableIssue.class);
    when(issue.componentKey()).thenReturn("struts:org.apache.Action");
    when(issue.ruleKey()).thenReturn(RuleKey.of("squid", "NoSonarCheck"));

    Set<Integer> noSonarLines = ImmutableSet.of(31, 55);
    filter.addComponent("struts:org.apache.Action", noSonarLines);

    when(issue.line()).thenReturn(31);
    assertThat(filter.accept(issue, chain)).isTrue();

    when(issue.line()).thenReturn(222);
    assertThat(filter.accept(issue, chain)).isTrue();

    verify(chain, times(2)).accept(issue);
  }
Exemplo n.º 4
0
  @Test
  public void should_ignore_lines_commented_with_nosonar() {
    FilterableIssue issue = mock(FilterableIssue.class);
    when(issue.componentKey()).thenReturn("struts:org.apache.Action");
    when(issue.ruleKey()).thenReturn(RuleKey.of("squid", "AvoidCycles"));

    Set<Integer> noSonarLines = ImmutableSet.of(31, 55);
    filter.addComponent("struts:org.apache.Action", noSonarLines);

    // issue on file
    when(issue.line()).thenReturn(null);
    assertThat(filter.accept(issue, chain)).isTrue();

    // issue on lines
    when(issue.line()).thenReturn(31);
    assertThat(filter.accept(issue, chain)).isFalse();

    when(issue.line()).thenReturn(222);
    assertThat(filter.accept(issue, chain)).isTrue();

    verify(chain, times(2)).accept(issue);
  }