### Question:
RandomStringUtils { public static String generateHex(int length) { return generateString(length, HEX_MAX_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 shouldGenerateRandomHexString() { int[] lengths = {0, 1, 21, 160, 1784}; Pattern badChars = Pattern.compile(".*[^0-9a-f].*"); for (int length : lengths) { String result = RandomStringUtils.generateHex(length); assertThat("Result '" + result + "' should have length " + length, result.length(), equalTo(length)); assertThat("Result '" + result + "' should only have characters a-f, 0-9", badChars.matcher(result).matches(), equalTo(false)); } }