Length implements Validation { public static Validation min(final int minLength) { if (minLength <= 0) { throw new IllegalArgumentException("minLength must be positive"); } return new Length(minLength, -1); } private  Length(final int minLength, final int maxLength); static Validation min(final int minLength); static Validation max(final int maxLength); static Validation range(final int minLength, final int maxLength); @Override String getErrorMessage(final Context context); @Override boolean isValid(final String text);  }
@Test public void testMin() throws Exception { final Validation validation = Length.min(2); assertFalse(validation.isValid("a")); assertTrue(validation.isValid("ab")); }
@Test(expected = IllegalArgumentException.class) public void testNegativeMinValueIsNotPossible() throws Exception { Length.min(-1); }