@Test public void testCheckConstraint_WithErrors() { ConstraintValidator validator = mock(ConstraintValidator.class); Path path = mock(Path.class); when(path.nAnys()).thenReturn(0); RequiredConstraint constraint = new RequiredConstraint(); constraint.setValue(true); JsonDoc doc = mock(JsonDoc.class); when(doc.get(path)).thenReturn(null); new RequiredChecker().checkConstraint(validator, null, path, constraint, doc); verify(validator, times(1)).addDocError(any(Error.class)); }
@Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, JsonDoc doc) { if (((RequiredConstraint) constraint).getValue()) { List<Path> errors = getMissingFields(fieldMetadataPath, doc); for (Path x : errors) { validator.addDocError(Error.get(CrudConstants.ERR_REQUIRED, x.toString())); } } }
RequiredChecker implements FieldConstraintDocChecker { @Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, JsonDoc doc) { if (((RequiredConstraint) constraint).getValue()) { List<Path> errors = getMissingFields(fieldMetadataPath, doc); for (Path x : errors) { validator.addDocError(Error.get(CrudConstants.ERR_REQUIRED, x.toString())); } } } }
RequiredChecker implements FieldConstraintDocChecker { @Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, JsonDoc doc) { if (((RequiredConstraint) constraint).getValue()) { List<Path> errors = getMissingFields(fieldMetadataPath, doc); for (Path x : errors) { validator.addDocError(Error.get(CrudConstants.ERR_REQUIRED, x.toString())); } } }  }
RequiredChecker implements FieldConstraintDocChecker { @Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, JsonDoc doc) { if (((RequiredConstraint) constraint).getValue()) { List<Path> errors = getMissingFields(fieldMetadataPath, doc); for (Path x : errors) { validator.addDocError(Error.get(CrudConstants.ERR_REQUIRED, x.toString())); } } }  @Override void checkConstraint(ConstraintValidator validator,
                                FieldTreeNode fieldMetadata,
                                Path fieldMetadataPath,
                                FieldConstraint constraint,
                                JsonDoc doc); static List<Path> getMissingFields(Path fieldMetadataPath,
                                              JsonDoc doc); }
RequiredChecker implements FieldConstraintDocChecker { @Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, JsonDoc doc) { if (((RequiredConstraint) constraint).getValue()) { List<Path> errors = getMissingFields(fieldMetadataPath, doc); for (Path x : errors) { validator.addDocError(Error.get(CrudConstants.ERR_REQUIRED, x.toString())); } } }  @Override void checkConstraint(ConstraintValidator validator,
                                FieldTreeNode fieldMetadata,
                                Path fieldMetadataPath,
                                FieldConstraint constraint,
                                JsonDoc doc); static List<Path> getMissingFields(Path fieldMetadataPath,
                                              JsonDoc doc);  }