Ejemplo n.º 1
0
  @Test
  public void testGetViolations() {
    File file = new File("org/foo/Bar.java");
    Violation violation1 = Violation.create(rule, file);
    index.addViolation(violation1);
    Violation violation2 = Violation.create(rule, file);
    violation2.setSwitchedOff(true);
    index.addViolation(violation2);
    Violation violation3 = Violation.create(rule, file);
    violation3.setSwitchedOff(true);
    index.addViolation(violation3);

    assertThat(index.getViolations(file).size(), is(1));
  }
Ejemplo n.º 2
0
  /** See http://jira.codehaus.org/browse/SONAR-2107 */
  @Test
  public void shouldNotFailWhenSavingViolationOnNullRule() {
    File file = new File("org/foo/Bar.java");
    Violation violation = Violation.create((Rule) null, file);
    index.addViolation(violation);

    assertThat(index.getViolations(file).size(), is(0));
  }
Ejemplo n.º 3
0
  /** See https://jira.codehaus.org/browse/SONAR-3583 */
  @Test
  public void should_ignore_violation_on_unknown_rules() {
    Rule ruleWithoutID = Rule.create("repoKey", "ruleKey", "Rule");

    File file = new File("org/foo/Bar.java");
    Violation violation = Violation.create(ruleWithoutID, file);
    index.addViolation(violation);

    assertThat(index.getViolations(file).size(), is(0));
  }
Ejemplo n.º 4
0
  /** See https://jira.codehaus.org/browse/SONAR-3583 */
  @Test
  public void should_support_violations_with_missing_rule_id() {
    Rule ruleWithoutId = Rule.create("repoKey", "ruleKey", "Rule");
    Rule ruleWithId = Rule.create("repoKey", "ruleKey", "Rule");
    ruleWithId.setId(123);
    when(ruleFinder.findByKey("repoKey", "ruleKey")).thenReturn(ruleWithId);

    File file = new File("org/foo/Bar.java");
    Violation violation = Violation.create(ruleWithoutId, file);
    index.addViolation(violation);

    List<Violation> violations = index.getViolations(file);
    assertThat(violations.size(), is(1));
    assertThat(violations.get(0).getRule().getId(), Matchers.is(123));
  }