### Question:
LengthValidator extends InputValidator { @Override public ValidationResult validate(String input) { ValidationResult result = new ValidationResult(true); int length = (input == null) ? 0 : input.length(); if (length < this.minLength || length > this.maxLength) result = new ValidationResult(false, Res.get("validation.length", this.minLength, this.maxLength)); return result; } LengthValidator();  LengthValidator(int min, int max); @Override ValidationResult validate(String input); void setMinLength(int minLength); void setMaxLength(int maxLength);  }### Answer:
@Test public void validate() throws Exception { LengthValidator validator = new LengthValidator(); assertTrue(validator.validate("").isValid); assertTrue(validator.validate(null).isValid); assertTrue(validator.validate("123456789").isValid); validator.setMinLength(2); validator.setMaxLength(5); assertTrue(validator.validate("12").isValid); assertTrue(validator.validate("12345").isValid); assertFalse(validator.validate("1").isValid); assertFalse(validator.validate("").isValid); assertFalse(validator.validate(null).isValid); assertFalse(validator.validate("123456789").isValid); LengthValidator validator2 = new LengthValidator(2, 5); assertTrue(validator2.validate("12").isValid); assertTrue(validator2.validate("12345").isValid); assertFalse(validator2.validate("1").isValid); assertFalse(validator2.validate("").isValid); assertFalse(validator2.validate(null).isValid); assertFalse(validator2.validate("123456789").isValid); }