### Question:
RandomStringUtils { public static String generate(int length) { return generateString(length, LOWER_ALPHANUMERIC_INDEX); } private  RandomStringUtils(); static String generate(int length); static String generateHex(int length); static String generateNum(int length); static String generateLowerUpper(int length);  }### Answer:
@Test public void shouldGenerateRandomStrings() { int[] lengths = {0, 1, 19, 142, 1872}; Pattern badChars = Pattern.compile(".*[^0-9a-z].*"); for (int length : lengths) { String result = RandomStringUtils.generate(length); assertThat("Result '" + result + "' should have length " + length, result.length(), equalTo(length)); assertThat("Result '" + result + "' should only have characters a-z, 0-9", badChars.matcher(result).matches(), equalTo(false)); } }
@Test(expected = IllegalArgumentException.class) public void shouldThrowForInvalidLength() { RandomStringUtils.generate(-3); }