@Test public void testMinOneSuccess() { when(context.getCurrentCount()).thenReturn(0); when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.ADD)); RuleViolations violations = tested.evaluate(RULE_MIN_1, context); assertNotNull(violations); assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }
@Override public RuleViolations evaluate(final Occurrences rule, final CardinalityContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final int minOccurrences = rule.getMinOccurrences(); final int maxOccurrences = rule.getMaxOccurrences(); final int currentCount = context.getCurrentCount(); final int candidateCount = context.getCandidateCount(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final Violation.Type type = operation .filter(CardinalityContext.Operation.ADD::equals) .isPresent() ? Violation.Type.ERROR : Violation.Type.WARNING; final int count = !operation.isPresent() ? currentCount : (operation.get().equals(CardinalityContext.Operation.ADD) ? currentCount + candidateCount : currentCount - candidateCount); if (count < minOccurrences) { results.addViolation(new CardinalityMinRuleViolation(context.getRoles().toString(), minOccurrences, currentCount, type)); } else if (maxOccurrences > -1 && count > maxOccurrences) { results.addViolation(new CardinalityMaxRuleViolation(context.getRoles().toString(), maxOccurrences, currentCount, type)); } return results; }
CardinalityEvaluationHandler implements RuleEvaluationHandler<Occurrences, CardinalityContext> { @Override public RuleViolations evaluate(final Occurrences rule, final CardinalityContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final int minOccurrences = rule.getMinOccurrences(); final int maxOccurrences = rule.getMaxOccurrences(); final int currentCount = context.getCurrentCount(); final int candidateCount = context.getCandidateCount(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final Violation.Type type = operation .filter(CardinalityContext.Operation.ADD::equals) .isPresent() ? Violation.Type.ERROR : Violation.Type.WARNING; final int count = !operation.isPresent() ? currentCount : (operation.get().equals(CardinalityContext.Operation.ADD) ? currentCount + candidateCount : currentCount - candidateCount); if (count < minOccurrences) { results.addViolation(new CardinalityMinRuleViolation(context.getRoles().toString(), minOccurrences, currentCount, type)); } else if (maxOccurrences > -1 && count > maxOccurrences) { results.addViolation(new CardinalityMaxRuleViolation(context.getRoles().toString(), maxOccurrences, currentCount, type)); } return results; } }
CardinalityEvaluationHandler implements RuleEvaluationHandler<Occurrences, CardinalityContext> { @Override public RuleViolations evaluate(final Occurrences rule, final CardinalityContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final int minOccurrences = rule.getMinOccurrences(); final int maxOccurrences = rule.getMaxOccurrences(); final int currentCount = context.getCurrentCount(); final int candidateCount = context.getCandidateCount(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final Violation.Type type = operation .filter(CardinalityContext.Operation.ADD::equals) .isPresent() ? Violation.Type.ERROR : Violation.Type.WARNING; final int count = !operation.isPresent() ? currentCount : (operation.get().equals(CardinalityContext.Operation.ADD) ? currentCount + candidateCount : currentCount - candidateCount); if (count < minOccurrences) { results.addViolation(new CardinalityMinRuleViolation(context.getRoles().toString(), minOccurrences, currentCount, type)); } else if (maxOccurrences > -1 && count > maxOccurrences) { results.addViolation(new CardinalityMaxRuleViolation(context.getRoles().toString(), maxOccurrences, currentCount, type)); } return results; }  }
CardinalityEvaluationHandler implements RuleEvaluationHandler<Occurrences, CardinalityContext> { @Override public RuleViolations evaluate(final Occurrences rule, final CardinalityContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final int minOccurrences = rule.getMinOccurrences(); final int maxOccurrences = rule.getMaxOccurrences(); final int currentCount = context.getCurrentCount(); final int candidateCount = context.getCandidateCount(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final Violation.Type type = operation .filter(CardinalityContext.Operation.ADD::equals) .isPresent() ? Violation.Type.ERROR : Violation.Type.WARNING; final int count = !operation.isPresent() ? currentCount : (operation.get().equals(CardinalityContext.Operation.ADD) ? currentCount + candidateCount : currentCount - candidateCount); if (count < minOccurrences) { results.addViolation(new CardinalityMinRuleViolation(context.getRoles().toString(), minOccurrences, currentCount, type)); } else if (maxOccurrences > -1 && count > maxOccurrences) { results.addViolation(new CardinalityMaxRuleViolation(context.getRoles().toString(), maxOccurrences, currentCount, type)); } return results; }  @Override Class<Occurrences> getRuleType(); @Override Class<CardinalityContext> getContextType(); @Override boolean accepts(final Occurrences rule,
                           final CardinalityContext context); @Override RuleViolations evaluate(final Occurrences rule,
                                   final CardinalityContext context); }
CardinalityEvaluationHandler implements RuleEvaluationHandler<Occurrences, CardinalityContext> { @Override public RuleViolations evaluate(final Occurrences rule, final CardinalityContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final int minOccurrences = rule.getMinOccurrences(); final int maxOccurrences = rule.getMaxOccurrences(); final int currentCount = context.getCurrentCount(); final int candidateCount = context.getCandidateCount(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final Violation.Type type = operation .filter(CardinalityContext.Operation.ADD::equals) .isPresent() ? Violation.Type.ERROR : Violation.Type.WARNING; final int count = !operation.isPresent() ? currentCount : (operation.get().equals(CardinalityContext.Operation.ADD) ? currentCount + candidateCount : currentCount - candidateCount); if (count < minOccurrences) { results.addViolation(new CardinalityMinRuleViolation(context.getRoles().toString(), minOccurrences, currentCount, type)); } else if (maxOccurrences > -1 && count > maxOccurrences) { results.addViolation(new CardinalityMaxRuleViolation(context.getRoles().toString(), maxOccurrences, currentCount, type)); } return results; }  @Override Class<Occurrences> getRuleType(); @Override Class<CardinalityContext> getContextType(); @Override boolean accepts(final Occurrences rule,
                           final CardinalityContext context); @Override RuleViolations evaluate(final Occurrences rule,
                                   final CardinalityContext context);  }