### Question:
ConstraintChecker { public Violations check(Environment env, Mutation m) { if (!env.getExtent().contains(new ComparableBytes(m.getRow()))) { Violations violations = new Violations(); ConstraintViolationSummary cvs = new ConstraintViolationSummary( SystemConstraint.class.getName(), (short) -1, "Mutation outside of tablet extent", 1); violations.add(cvs); return violations; } Violations violations = null; for (Constraint constraint : getConstraints()) { try { List<Short> violationCodes = constraint.check(env, m); if (violationCodes != null) { String className = constraint.getClass().getName(); for (Short vcode : violationCodes) { violations = addViolation(violations, new ConstraintViolationSummary(className, vcode, constraint.getViolationDescription(vcode), 1)); } } } catch (Throwable throwable) { log.warn("CONSTRAINT FAILED : {}", throwable.getMessage(), throwable); short vcode; String msg; if (throwable instanceof NullPointerException) { vcode = -1; msg = "threw NullPointerException"; } else if (throwable instanceof ArrayIndexOutOfBoundsException) { vcode = -2; msg = "threw ArrayIndexOutOfBoundsException"; } else if (throwable instanceof NumberFormatException) { vcode = -3; msg = "threw NumberFormatException"; } else if (throwable instanceof IOException) { vcode = -4; msg = "threw IOException (or subclass of)"; } else { vcode = -100; msg = "threw some Exception"; } violations = addViolation(violations, new ConstraintViolationSummary(constraint.getClass().getName(), vcode, "CONSTRAINT FAILED : " + msg, 1)); } } return violations; } ConstraintChecker(AccumuloConfiguration conf); Violations check(Environment env, Mutation m);  }### Answer:
@Test public void testCheckAllOK() { expect(extent.contains(anyObject(BinaryComparable.class))).andReturn(true); replayAll(); constraints.add(makeSuccessConstraint()); assertNull(cc.check(env, m)); }
@Test public void testCheckMutationOutsideKeyExtent() { expect(extent.contains(anyObject(BinaryComparable.class))).andReturn(false); replayAll(); ConstraintViolationSummary cvs = Iterables.getOnlyElement(cc.check(env, m).asList()); assertEquals(SystemConstraint.class.getName(), cvs.getConstrainClass()); }
@Test public void testCheckFailure() { expect(extent.contains(anyObject(BinaryComparable.class))).andReturn(true); replayAll(); constraints.add(makeFailureConstraint()); List<ConstraintViolationSummary> cvsList = cc.check(env, m).asList(); assertEquals(2, cvsList.size()); Set<String> violationDescs = new HashSet<>(); for (ConstraintViolationSummary cvs : cvsList) { violationDescs.add(cvs.getViolationDescription()); } assertEquals(Set.of("ViolationCode1", "ViolationCode2"), violationDescs); }
@Test public void testCheckException() { expect(extent.contains(anyObject(BinaryComparable.class))).andReturn(true); replayAll(); constraints.add(makeExceptionConstraint()); ConstraintViolationSummary cvs = Iterables.getOnlyElement(cc.check(env, m).asList()); assertEquals("CONSTRAINT FAILED : threw some Exception", cvs.getViolationDescription()); }