@Test public void betweenTest() { StringLengthValidator s = StringLengthValidator.between(10, 20, "test"); Assert.assertTrue(s.validate("abcdefghijklmno").getResult()); Assert.assertFalse(s.validate("abcde").getResult()); Assert.assertTrue(s.validate(" ").getResult()); Assert.assertTrue(s.validate("æ¢¢äöä1ö3ä±æ#¢æ±“{").getResult()); try { StringLengthValidator s2 = StringLengthValidator.between(-10, 2, "test"); fail(); } catch (IllegalArgumentException ignored) {} try { StringLengthValidator s3 = StringLengthValidator.between(0, 0, "test"); } catch (IllegalArgumentException e) { fail(); } try { StringLengthValidator s4 = StringLengthValidator.between(10, 1, "test"); fail(); } catch (IllegalArgumentException ignored) {} }
public static StringLengthValidator between(int min, int max, String errorMessage) { if (min < 0) { throw new IllegalArgumentException("Minimum string length cannot be negative."); } else if (min > max) { throw new IllegalArgumentException("Minimum must not be larger than maximum."); } return new StringLengthValidator(min, max, errorMessage); }
StringLengthValidator extends CustomValidator<String> { public static StringLengthValidator between(int min, int max, String errorMessage) { if (min < 0) { throw new IllegalArgumentException("Minimum string length cannot be negative."); } else if (min > max) { throw new IllegalArgumentException("Minimum must not be larger than maximum."); } return new StringLengthValidator(min, max, errorMessage); } }
StringLengthValidator extends CustomValidator<String> { public static StringLengthValidator between(int min, int max, String errorMessage) { if (min < 0) { throw new IllegalArgumentException("Minimum string length cannot be negative."); } else if (min > max) { throw new IllegalArgumentException("Minimum must not be larger than maximum."); } return new StringLengthValidator(min, max, errorMessage); } private  StringLengthValidator(int min, int max, String errorMessage); }
StringLengthValidator extends CustomValidator<String> { public static StringLengthValidator between(int min, int max, String errorMessage) { if (min < 0) { throw new IllegalArgumentException("Minimum string length cannot be negative."); } else if (min > max) { throw new IllegalArgumentException("Minimum must not be larger than maximum."); } return new StringLengthValidator(min, max, errorMessage); } private  StringLengthValidator(int min, int max, String errorMessage); static StringLengthValidator between(int min, int max, String errorMessage); static StringLengthValidator atLeast(int min, String errorMessage); static StringLengthValidator upTo(int max, String errorMessage); static StringLengthValidator exactly(int value, String errorMessage); }
StringLengthValidator extends CustomValidator<String> { public static StringLengthValidator between(int min, int max, String errorMessage) { if (min < 0) { throw new IllegalArgumentException("Minimum string length cannot be negative."); } else if (min > max) { throw new IllegalArgumentException("Minimum must not be larger than maximum."); } return new StringLengthValidator(min, max, errorMessage); } private  StringLengthValidator(int min, int max, String errorMessage); static StringLengthValidator between(int min, int max, String errorMessage); static StringLengthValidator atLeast(int min, String errorMessage); static StringLengthValidator upTo(int max, String errorMessage); static StringLengthValidator exactly(int value, String errorMessage);  }