### Question:
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);  }### Answer:
@Test public void testCheckConstraint_TooLarge() { ConstraintValidator validator = mock(ConstraintValidator.class); ArraySizeConstraint constraint = new ArraySizeConstraint("Fake Type"); constraint.setValue(2); ArrayNode fieldValue = mock(ArrayNode.class); when(fieldValue.size()).thenReturn(3); new ArraySizeChecker().checkConstraint(validator, null, null, constraint, null, null, fieldValue); verify(validator, times(1)).addDocError(any(Error.class)); }
@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)); }
@Test public void testCheckConstraint_Min_TooSmall() { ConstraintValidator validator = mock(ConstraintValidator.class); ArraySizeConstraint constraint = new ArraySizeConstraint(ArraySizeConstraint.MIN); 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, times(1)).addDocError(any(Error.class)); }
@Test public void testCheckConstraint_Min_NoErrors() { ConstraintValidator validator = mock(ConstraintValidator.class); ArraySizeConstraint constraint = new ArraySizeConstraint(ArraySizeConstraint.MIN); constraint.setValue(2); ArrayNode fieldValue = mock(ArrayNode.class); when(fieldValue.size()).thenReturn(3); new ArraySizeChecker().checkConstraint(validator, null, null, constraint, null, null, fieldValue); verify(validator, never()).addDocError(any(Error.class)); }