@Test public void testCheckConstraint_NotMin_NoErrors() { ConstraintValidator validator = mock(ConstraintValidator.class); ArraySizeConstraint constraint = new ArraySizeConstraint("Fake Type"); constraint.setValue(2); ArrayNode fieldValue = mock(ArrayNode.class); when(fieldValue.size()).thenReturn(1); new ArraySizeChecker().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) { int value = ((ArraySizeConstraint) constraint).getValue(); String type = ((ArraySizeConstraint) constraint).getType(); if (fieldValue != null && !(fieldValue instanceof NullNode)) { if (ArraySizeConstraint.MIN.equals(type)) { if (((ArrayNode) fieldValue).size() < value) { validator.addDocError(Error.get(CrudConstants.ERR_ARRAY_TOO_SMALL, Integer.toString(((ArrayNode) fieldValue).size()))); } } else if (((ArrayNode) fieldValue).size() > value) { validator.addDocError(Error.get(CrudConstants.ERR_ARRAY_TOO_LARGE, Integer.toString(((ArrayNode) fieldValue).size()))); } } }
ArraySizeChecker implements FieldConstraintValueChecker { @Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, Path valuePath, JsonDoc doc, JsonNode fieldValue) { int value = ((ArraySizeConstraint) constraint).getValue(); String type = ((ArraySizeConstraint) constraint).getType(); if (fieldValue != null && !(fieldValue instanceof NullNode)) { if (ArraySizeConstraint.MIN.equals(type)) { if (((ArrayNode) fieldValue).size() < value) { validator.addDocError(Error.get(CrudConstants.ERR_ARRAY_TOO_SMALL, Integer.toString(((ArrayNode) fieldValue).size()))); } } else if (((ArrayNode) fieldValue).size() > value) { validator.addDocError(Error.get(CrudConstants.ERR_ARRAY_TOO_LARGE, Integer.toString(((ArrayNode) fieldValue).size()))); } } } }
ArraySizeChecker implements FieldConstraintValueChecker { @Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, Path valuePath, JsonDoc doc, JsonNode fieldValue) { int value = ((ArraySizeConstraint) constraint).getValue(); String type = ((ArraySizeConstraint) constraint).getType(); if (fieldValue != null && !(fieldValue instanceof NullNode)) { if (ArraySizeConstraint.MIN.equals(type)) { if (((ArrayNode) fieldValue).size() < value) { validator.addDocError(Error.get(CrudConstants.ERR_ARRAY_TOO_SMALL, Integer.toString(((ArrayNode) fieldValue).size()))); } } else if (((ArrayNode) fieldValue).size() > value) { validator.addDocError(Error.get(CrudConstants.ERR_ARRAY_TOO_LARGE, Integer.toString(((ArrayNode) fieldValue).size()))); } } }  }
ArraySizeChecker implements FieldConstraintValueChecker { @Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, Path valuePath, JsonDoc doc, JsonNode fieldValue) { int value = ((ArraySizeConstraint) constraint).getValue(); String type = ((ArraySizeConstraint) constraint).getType(); if (fieldValue != null && !(fieldValue instanceof NullNode)) { if (ArraySizeConstraint.MIN.equals(type)) { if (((ArrayNode) fieldValue).size() < value) { validator.addDocError(Error.get(CrudConstants.ERR_ARRAY_TOO_SMALL, Integer.toString(((ArrayNode) fieldValue).size()))); } } else if (((ArrayNode) fieldValue).size() > value) { validator.addDocError(Error.get(CrudConstants.ERR_ARRAY_TOO_LARGE, Integer.toString(((ArrayNode) fieldValue).size()))); } } }  @Override void checkConstraint(ConstraintValidator validator,
                                FieldTreeNode fieldMetadata,
                                Path fieldMetadataPath,
                                FieldConstraint constraint,
                                Path valuePath,
                                JsonDoc doc,
                                JsonNode fieldValue); }
ArraySizeChecker implements FieldConstraintValueChecker { @Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, Path valuePath, JsonDoc doc, JsonNode fieldValue) { int value = ((ArraySizeConstraint) constraint).getValue(); String type = ((ArraySizeConstraint) constraint).getType(); if (fieldValue != null && !(fieldValue instanceof NullNode)) { if (ArraySizeConstraint.MIN.equals(type)) { if (((ArrayNode) fieldValue).size() < value) { validator.addDocError(Error.get(CrudConstants.ERR_ARRAY_TOO_SMALL, Integer.toString(((ArrayNode) fieldValue).size()))); } } else if (((ArrayNode) fieldValue).size() > value) { validator.addDocError(Error.get(CrudConstants.ERR_ARRAY_TOO_LARGE, Integer.toString(((ArrayNode) fieldValue).size()))); } } }  @Override void checkConstraint(ConstraintValidator validator,
                                FieldTreeNode fieldMetadata,
                                Path fieldMetadataPath,
                                FieldConstraint constraint,
                                Path valuePath,
                                JsonDoc doc,
                                JsonNode fieldValue);  }