### Question:
FormValidatorImpl implements FormValidator { @Override public boolean validate(Form form, Object model) { form.getFields().forEach(FormField::clearError); boolean isModelValid = modelValidator.validate(form.getFields(), model); boolean isFieldStateValid = fieldStateValidator.validate(form.getFields()); return isFieldStateValid && isModelValid; } @Inject  FormValidatorImpl(ModelValidator modelValidator,
                             FieldStateValidator fieldStateValidator); @Override boolean validate(Form form, Object model); @Override boolean validate(FormField formField,
                            Object model); ModelValidator getModelValidator(); void setModelValidator(ModelValidator modelValidator);  }### Answer:
@Test public void testFullModelSuccesfulValidation() { assertTrue(formValidator.validate(form, model)); checkClearedFields(getAllFields()); checkValidFields(getAllFields()); }
@Test public void testModelStateFailedValidation() { when(fieldStateValidator.validate(anyCollection())).thenReturn(false); assertFalse(formValidator.validate(form, model)); }
@Test public void testFullModelFailedValidation() { model.setValue(600); model.getUser().setName(null); model.getUser().setLastName(""); assertFalse(formValidator.validate(form, model)); checkClearedFields(); checkWrongFields(valueField, nameField, lastNameField); checkValidFields(birthdayField, marriedField); }
@Test public void testpropertySuccesfullValidation() { assertTrue(formValidator.validate(valueField, model)); checkClearedFields(valueField); checkValidFields(valueField); assertTrue(formValidator.validate(nameField, model)); checkClearedFields(nameField); checkValidFields(nameField); assertTrue(formValidator.validate(addressField, model)); checkClearedFields(addressField); checkValidFields(addressField); }
@Test public void testPropertyFailedValidation() { model.setValue(70); model.getUser().setName(""); model.getUser().setLastName("abc"); assertFalse(formValidator.validate(valueField, model)); checkClearedFields(valueField); checkWrongFields(valueField); assertFalse(formValidator.validate(nameField, model)); checkClearedFields(nameField); checkWrongFields(nameField); assertFalse(formValidator.validate(lastNameField, model)); checkClearedFields(lastNameField); checkWrongFields(lastNameField); }
@Test public void testPropertyStateFailedValidation() { when(fieldStateValidator.validate(any(FormField.class))).thenReturn(false); assertFalse(formValidator.validate(valueField, model)); assertFalse(formValidator.validate(nameField, model)); assertFalse(formValidator.validate(lastNameField, model)); }