### Question:
ContainmentEvaluationHandler implements RuleEvaluationHandler<CanContain, ContainmentContext> { @Override public RuleViolations evaluate(final CanContain rule, final ContainmentContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final boolean present = context.getCandidateRoles() .stream() .filter(cr -> rule.getAllowedRoles().contains(cr)) .findAny() .isPresent(); if (!present) { results.addViolation(new ContainmentRuleViolation(rule.getRole(), context.getCandidateRoles().toString())); } return results; }  @Override Class<CanContain> getRuleType(); @Override Class<ContainmentContext> getContextType(); @Override boolean accepts(final CanContain rule,
                           final ContainmentContext context); @Override RuleViolations evaluate(final CanContain rule,
                                   final ContainmentContext context);  }### Answer:
@Test public void testEvaluateSuccess() { final Set<String> candidateRoles = new HashSet<String>(1) {{ add("role2"); }}; when(context.getParentRoles()).thenReturn(PARENT_ROLES); when(context.getCandidateRoles()).thenReturn(candidateRoles); final RuleViolations violations = tested.evaluate(RULE, context); assertNotNull(violations); assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }
@Test public void testEvaluateFailed() { final Set<String> candidateRoles = new HashSet<String>(1) {{ add("role4"); }}; when(context.getParentRoles()).thenReturn(PARENT_ROLES); when(context.getCandidateRoles()).thenReturn(candidateRoles); final RuleViolations violations = tested.evaluate(RULE, context); assertNotNull(violations); assertTrue(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }