AlternativeViolationPredicate { public static Predicate<Violation> firstAlternativeViolation() { Set<Node> coveredNodes = new HashSet<>(); return violation -> { Set<Node> mappedTargetNodes = violation.getOverlap().getMappedTargetNodes().stream() .filter(node -> node instanceof MethodCallNode) .collect(Collectors.toSet()); if (mappedTargetNodes.stream().anyMatch(coveredNodes::contains)) { return false; } else { coveredNodes.addAll(mappedTargetNodes); return true; } }; }  static Predicate<Violation> firstAlternativeViolation();  }
@Test public void keepsIndependentViolations() { Violation violation1 = someViolation(buildOverlap(buildAUG().withActionNode("m()")).withNode("m()")); Violation violation2 = someViolation(buildOverlap(buildAUG().withActionNode("f()")).withNode("f()")); assertThat(Stream.of(violation1, violation2).filter(firstAlternativeViolation()).count(), is(2L)); }
@Test public void filtersSubsequentAlternativeViolations() { TestAUGBuilder commonPart = buildAUG().withActionNode("m()"); Violation violation1 = someViolation(buildOverlap(extend(commonPart).withActionNode("n()")).withNodes("m()", "n()")); Violation violation2 = someViolation(buildOverlap(extend(commonPart).withActionNode("f()")).withNodes("m()", "f()")); Violation violation3 = someViolation(buildOverlap(extend(commonPart).withActionNode("x()")).withNodes("m()", "x()")); assertThat(Stream.of(violation1, violation2, violation3).filter(firstAlternativeViolation()).count(), is(1L)); }