Exemple #1
0
  /** {@inheritDoc} */
  @Override
  public List<Violation> getViolations(ViolationQuery violationQuery) {
    Resource resource = violationQuery.getResource();
    if (resource == null) {
      throw new IllegalArgumentException(
          "A resource must be set on the ViolationQuery in order to search for violations.");
    }

    if (!Scopes.isHigherThanOrEquals(resource, Scopes.FILE)) {
      return Collections.emptyList();
    }

    Bucket bucket = buckets.get(resource);
    if (bucket == null) {
      return Collections.emptyList();
    }

    List<Violation> violations = deprecatedViolations.get(bucket.getResource().getEffectiveKey());
    if (violationQuery.getSwitchMode() == ViolationQuery.SwitchMode.BOTH) {
      return violations;
    }

    List<Violation> filteredViolations = Lists.newArrayList();
    for (Violation violation : violations) {
      if (isFiltered(violation, violationQuery.getSwitchMode())) {
        filteredViolations.add(violation);
      }
    }
    return filteredViolations;
  }
Exemple #2
0
  @Test
  public void testGetViolationsWithQuery() {
    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(ViolationQuery.create().forResource(file).setSwitchedOff(true)).size(),
        is(2));
  }
Exemple #3
0
 @Test(expected = IllegalArgumentException.class)
 public void testGetViolationsWithQueryWithNoResource() {
   index.getViolations(ViolationQuery.create());
 }