Check { public static String validIdentifier(String value, int maxLen, String name) { Check.notEmpty(value, name); if (value.length() > maxLen) { throw new IllegalArgumentException(MessageFormat .format("[{0}] = [{1}] exceeds max len [{2}]", name, value, maxLen)); } if (!IDENTIFIER_PATTERN.matcher(value).find()) { throw new IllegalArgumentException(MessageFormat .format("[{0}] = [{1}] must be '{2}'", name, value, IDENTIFIER_PATTERN_STR)); } return value; }  static T notNull(T obj, String name); static List<T> notNullElements(List<T> list, String name); static String notEmpty(String str, String name); static List<String> notEmptyElements(List<String> list, String name); static String validIdentifier(String value, int maxLen, String name); static int gt0(int value, String name); static long gt0(long value, String name); static int ge0(int value, String name); static long ge0(long value, String name);  }
@Test public void validIdentifierValid() throws Exception { assertEquals(Check.validIdentifier("a", 1, ""), "a"); assertEquals(Check.validIdentifier("a1", 2, ""), "a1"); assertEquals(Check.validIdentifier("a_", 3, ""), "a_"); assertEquals(Check.validIdentifier("_", 1, ""), "_"); }
@Test(expected = IllegalArgumentException.class) public void validIdentifierInvalid1() throws Exception { Check.validIdentifier("!", 1, ""); }
@Test(expected = IllegalArgumentException.class) public void validIdentifierInvalid2() throws Exception { Check.validIdentifier("a1", 1, ""); }
@Test(expected = IllegalArgumentException.class) public void validIdentifierInvalid3() throws Exception { Check.validIdentifier("1", 1, ""); }