### Question:
MinMaxChecker implements FieldConstraintValueChecker { @Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, Path valuePath, JsonDoc doc, JsonNode fieldValue) { Number value = ((MinMaxConstraint) constraint).getValue(); String type = ((MinMaxConstraint) constraint).getType(); if (!(fieldValue instanceof NullNode)) { int cmp = cmp(fieldValue, value); if (MinMaxConstraint.MIN.equals(type)) { if (cmp < 0) { validator.addDocError(Error.get(CrudConstants.ERR_VALUE_TOO_SMALL, fieldValue.asText())); } } else if (cmp > 0) { validator.addDocError(Error.get(CrudConstants.ERR_VALUE_TOO_LARGE, fieldValue.asText())); } } }  @Override void checkConstraint(ConstraintValidator validator,
                                FieldTreeNode fieldMetadata,
                                Path fieldMetadataPath,
                                FieldConstraint constraint,
                                Path valuePath,
                                JsonDoc doc,
                                JsonNode fieldValue);  }### Answer:
@Test public void testCheckConstraint_MIN_TooSmall() { ConstraintValidator validator = mock(ConstraintValidator.class); MinMaxConstraint constraint = new MinMaxConstraint(MinMaxConstraint.MIN); constraint.setValue(number); JsonNode fieldValue = mock(JsonNode.class); mockFieldValue(fieldValue, 0); new MinMaxChecker().checkConstraint(validator, null, null, constraint, null, null, fieldValue); verify(validator, times(1)).addDocError(any(Error.class)); }
@Test public void testCheckConstraint_MIN_Equal_Pass() { ConstraintValidator validator = mock(ConstraintValidator.class); MinMaxConstraint constraint = new MinMaxConstraint(MinMaxConstraint.MIN); constraint.setValue(number); JsonNode fieldValue = mock(JsonNode.class); mockFieldValue(fieldValue, 2); new MinMaxChecker().checkConstraint(validator, null, null, constraint, null, null, fieldValue); verify(validator, never()).addDocError(any(Error.class)); }
@Test public void testCheckConstraint_MIN_Pass() { ConstraintValidator validator = mock(ConstraintValidator.class); MinMaxConstraint constraint = new MinMaxConstraint(MinMaxConstraint.MIN); constraint.setValue(number); JsonNode fieldValue = mock(JsonNode.class); mockFieldValue(fieldValue, 2); new MinMaxChecker().checkConstraint(validator, null, null, constraint, null, null, fieldValue); verify(validator, never()).addDocError(any(Error.class)); }
@Test public void testCheckConstraint_MAX_TooLarge() { ConstraintValidator validator = mock(ConstraintValidator.class); MinMaxConstraint constraint = new MinMaxConstraint("Fake Type"); constraint.setValue(convertInt(0)); JsonNode fieldValue = mock(JsonNode.class); mockFieldValue(fieldValue, 2); new MinMaxChecker().checkConstraint(validator, null, null, constraint, null, null, fieldValue); verify(validator, times(1)).addDocError(any(Error.class)); }
@Test public void testCheckConstraint_MAX_Equal_Pass() { ConstraintValidator validator = mock(ConstraintValidator.class); MinMaxConstraint constraint = new MinMaxConstraint("Fake Type"); constraint.setValue(number); JsonNode fieldValue = mock(JsonNode.class); mockFieldValue(fieldValue, 2); new MinMaxChecker().checkConstraint(validator, null, null, constraint, null, null, fieldValue); verify(validator, never()).addDocError(any(Error.class)); }
@Test public void testCheckConstraint_MAX_Pass() { ConstraintValidator validator = mock(ConstraintValidator.class); MinMaxConstraint constraint = new MinMaxConstraint("Fake Type"); constraint.setValue(number); JsonNode fieldValue = mock(JsonNode.class); mockFieldValue(fieldValue, 0); new MinMaxChecker().checkConstraint(validator, null, null, constraint, null, null, fieldValue); verify(validator, never()).addDocError(any(Error.class)); }