### Question:
PortalPreferenceFormValidator implements Validator { @Override public void validate(Object target, Errors errors) { PortalPreferenceForm form = (PortalPreferenceForm) target; validateRequiredFields(errors); validatePageSize(form, errors); }  @Override boolean supports(Class<?> clazz); @Override void validate(Object target, Errors errors);  }### Answer:
@Test public void testValidate_Valid() throws Exception { Map<String, PortalPreference> preferenceMap = new HashMap<String, PortalPreference>(); preferenceMap.put(TITLE_SUFFIX, new PortalPreferenceImpl(TITLE_SUFFIX, "- Rave unit test")); preferenceMap.put(PAGE_SIZE, new PortalPreferenceImpl(PAGE_SIZE, "10")); PortalPreferenceForm form = new PortalPreferenceForm(preferenceMap); Errors errors = new BindException(form, "form"); validator.validate(form, errors); assertFalse(errors.hasErrors()); }
@Test public void testValidate_missingRequiredFields() throws Exception { Map<String, PortalPreference> preferenceMap = new HashMap<String, PortalPreference>(); PortalPreferenceForm form = new PortalPreferenceForm(preferenceMap); form.getPageSize().setValue(null); Errors errors = new BindException(form, "form"); validator.validate(form, errors); assertEquals(2, errors.getErrorCount()); assertNotNull(errors.getFieldError("pageSize.value")); }
@Test public void testValidate_InvalidPageSize() throws Exception { Map<String, PortalPreference> preferenceMap = new HashMap<String, PortalPreference>(); preferenceMap.put(PAGE_SIZE, new PortalPreferenceImpl(PAGE_SIZE, "10.5")); PortalPreferenceForm form = new PortalPreferenceForm(preferenceMap); Errors errors = new BindException(form, "form"); validator.validate(form, errors); assertEquals(1, errors.getErrorCount()); assertNotNull(errors.getFieldError("pageSize.value")); }