@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)); }
@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())); } } }
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())); } } } }
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())); } } }  }
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); }
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);  }