### Question:
FormValidator { public static ValidationResult isValid(Form form) { if (form == null) { throw new IllegalAddException("Arugment cannot be null"); } Class<? extends Object> type = form.getClass(); String key = type.getName(); ValidatorContianer contianer = cached.get(key); if (contianer == null) { contianer = new ValidatorContianer(); cached.put(key, contianer); } ValidationResult result = new ValidationResult(); for (Field filed : type.getDeclaredFields()) { validFiled(form, filed, contianer, result); } return result; }  static ValidationResult isValid(Form form); static ValidationResult isValid(String fieldKey, String displayName, Object value, String... validatorIds);  }### Answer:
@Test public void requiredTest() { Form form = new MockForm(); ValidationResult valid = FormValidator.isValid(form); System.out.println(valid); assertFalse(valid.isValid()); assertTrue(valid.isFieldError("email")); }
@Test public void LengthTest() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 129; i++) { sb.append("a"); } assertTrue(sb.length() == 129); MockForm form = new MockForm(); form.setEmail(sb.toString()); ValidationResult valid = FormValidator.isValid(form); System.out.println(valid); assertFalse(valid.isValid()); assertTrue(valid.isFieldError("email")); }
@Test public void email() { MockForm form = new MockForm(); form.setEmail("zxc"); ValidationResult valid = FormValidator.isValid(form); System.out.println(valid); assertFalse(valid.isValid()); assertTrue(valid.isFieldError("email")); }
@Test public void passwordregx() { MockForm form = new MockForm(); form.setEmail("zxc@msun.com"); form.setPassword("123456."); ValidationResult valid = FormValidator.isValid(form); System.out.println("只能数字字母" + valid); assertFalse(valid.isValid()); assertTrue(valid.isFieldError("password")); form.setPassword("12345"); valid = FormValidator.isValid(form); System.out.println("长度小了" + valid); assertFalse(valid.isValid()); assertTrue(valid.isFieldError("password")); form.setPassword("123456789012345678901"); valid = FormValidator.isValid(form); System.out.println("长度大了" + valid); assertFalse(valid.isValid()); assertTrue(valid.isFieldError("password")); form.setPassword("hello1234"); valid = FormValidator.isValid(form); System.out.println("正常" + valid); assertTrue(valid.isValid()); assertFalse(valid.isFieldError("password")); }
@Test public void normal() { MockForm form = new MockForm(); form.setEmail("zxc@msun.com"); form.setPassword("hello1234"); ValidationResult valid = FormValidator.isValid(form); System.out.println(valid); assertTrue(valid.isValid()); assertFalse(valid.isFieldError("email")); }