@Test
  public void should_ignore_violation_on_unknown_resource() {
    when(projectFileSystem.getSourceDirs()).thenReturn(Arrays.asList(new File("/src")));
    when(pmdViolation.getFilename()).thenReturn("/src/UNKNOWN.java");

    PmdViolationToRuleViolation pmdViolationToRuleViolation =
        new PmdViolationToRuleViolation(projectFileSystem, ruleFinder);
    Violation violation = pmdViolationToRuleViolation.toViolation(pmdViolation, context);

    assertThat(violation).isNull();
  }
  @Test
  public void should_ignore_violation_on_unknown_rule() {
    when(projectFileSystem.getTestDirs()).thenReturn(Arrays.asList(new File("/test")));
    when(pmdViolation.getFilename()).thenReturn("/test/source.java");
    when(pmdViolation.getRule()).thenReturn(rule);
    when(rule.getName()).thenReturn("UNKNOWN");
    when(context.getResource(new JavaFile("[default].source")))
        .thenReturn(new JavaFile("[default].source"));

    PmdViolationToRuleViolation pmdViolationToRuleViolation =
        new PmdViolationToRuleViolation(projectFileSystem, ruleFinder);
    Violation violation = pmdViolationToRuleViolation.toViolation(pmdViolation, context);

    assertThat(violation).isNull();
  }
  @Test
  public void should_convert_pmd_violation_to_sonar_violation() {
    when(projectFileSystem.getSourceDirs()).thenReturn(Arrays.asList(new File("/src")));
    when(pmdViolation.getFilename()).thenReturn("/src/source.java");
    when(pmdViolation.getBeginLine()).thenReturn(42);
    when(pmdViolation.getDescription()).thenReturn("Description");
    when(pmdViolation.getRule()).thenReturn(rule);
    when(rule.getName()).thenReturn("RULE");
    when(context.getResource(new JavaFile("[default].source")))
        .thenReturn(new JavaFile("[default].source"));
    when(ruleFinder.findByKey("pmd", "RULE")).thenReturn(sonarRule);

    PmdViolationToRuleViolation pmdViolationToRuleViolation =
        new PmdViolationToRuleViolation(projectFileSystem, ruleFinder);
    Violation violation = pmdViolationToRuleViolation.toViolation(pmdViolation, context);

    assertThat(violation)
        .is(
            reflectionEqualTo(
                Violation.create(sonarRule, new JavaFile("[default].source"))
                    .setLineId(42)
                    .setMessage("Description")));
  }