@Test public void assertValidMinAndMaxLength() { int lengthExpected = 30; int minLengthActual = Integer.MAX_VALUE; int maxLengthActual = 0; for (int i = 0; i < 10000; ++i) { char[] password = PasswordUtil.createRandomPassword(lengthExpected); minLengthActual = Math.min(minLengthActual, password.length); maxLengthActual = Math.max(maxLengthActual, password.length); } assertThat(minLengthActual).isEqualTo(lengthExpected); assertThat(maxLengthActual).isEqualTo(lengthExpected); }
public static char[] createRandomPassword(int length) { if (length < 8) throw new IllegalArgumentException("length < 8"); char[] result = new char[length]; for (int i = 0; i < result.length; ++i) result[i] = PASSWORD_CHARS[random.nextInt(PASSWORD_CHARS.length)]; return result; }
PasswordUtil { public static char[] createRandomPassword(int length) { if (length < 8) throw new IllegalArgumentException("length < 8"); char[] result = new char[length]; for (int i = 0; i < result.length; ++i) result[i] = PASSWORD_CHARS[random.nextInt(PASSWORD_CHARS.length)]; return result; } }
PasswordUtil { public static char[] createRandomPassword(int length) { if (length < 8) throw new IllegalArgumentException("length < 8"); char[] result = new char[length]; for (int i = 0; i < result.length; ++i) result[i] = PASSWORD_CHARS[random.nextInt(PASSWORD_CHARS.length)]; return result; } private  PasswordUtil(); }
PasswordUtil { public static char[] createRandomPassword(int length) { if (length < 8) throw new IllegalArgumentException("length < 8"); char[] result = new char[length]; for (int i = 0; i < result.length; ++i) result[i] = PASSWORD_CHARS[random.nextInt(PASSWORD_CHARS.length)]; return result; } private  PasswordUtil(); static char[] createRandomPassword(int length); }
PasswordUtil { public static char[] createRandomPassword(int length) { if (length < 8) throw new IllegalArgumentException("length < 8"); char[] result = new char[length]; for (int i = 0; i < result.length; ++i) result[i] = PASSWORD_CHARS[random.nextInt(PASSWORD_CHARS.length)]; return result; } private  PasswordUtil(); static char[] createRandomPassword(int length);  }