### Question:
ElementCardinalityEvaluationHandler implements RuleEvaluationHandler<Occurrences, ElementCardinalityContext> { @Override @SuppressWarnings("unchecked") public boolean accepts(final Occurrences rule, final ElementCardinalityContext context) { final Collection<Element<? extends View<?>>> candidates = context.getCandidates(); return candidates.isEmpty() || candidates.stream().anyMatch(candidate -> accepts(rule, context, candidate)); } protected  ElementCardinalityEvaluationHandler(); @Inject  ElementCardinalityEvaluationHandler(final DefinitionManager definitionManager,
                                               final CardinalityEvaluationHandler cardinalityEvaluationHandler); @Override Class<Occurrences> getRuleType(); @Override Class<ElementCardinalityContext> getContextType(); @Override @SuppressWarnings("unchecked") boolean accepts(final Occurrences rule,
                           final ElementCardinalityContext context); @Override @SuppressWarnings("unchecked") RuleViolations evaluate(final Occurrences rule,
                                   final ElementCardinalityContext context);  }### Answer:
@Test @SuppressWarnings("unchecked") public void testAcceptsNoOp() { when(context.getCandidates()).thenReturn(Collections.emptyList()); assertTrue(tested.accepts(RULE_NO_LIMIT, context)); }
@Test @SuppressWarnings("unchecked") public void testAccepts() { when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.ADD)); when(context.getCandidates()).thenReturn(candidates); assertTrue(tested.accepts(RULE_NO_LIMIT, context)); when(context.getCandidates()).thenReturn(Collections.singleton(parent)); assertFalse(tested.accepts(RULE_NO_LIMIT, context)); }