@Test void testGenerate() throws NoSuchAlgorithmException, NoSuchProviderException { SecureRandom randomGenerator = SecureRandom.getInstance("SHA1PRNG", "SUN"); randomGenerator.setSeed(69); CredentialsGenerator credentialsGenerator = new CredentialsGenerator(randomGenerator); assertEquals("r&k37&tl2*D[MK7C", credentialsGenerator.next(16)); assertEquals("dd*Qz99LI1CB49(*", credentialsGenerator.next(16)); assertEquals("4y(m4ZMfpcY8#g7ur74K@@vXmAAJ4s2(", credentialsGenerator.next(32)); }
public String next(int length) { StringBuilder credential = new StringBuilder(length); for (int i = 0; i < length; i++) { int randomIndex = randomGenerator.nextInt(LEGAL_CHARACTERS.length); credential.append(LEGAL_CHARACTERS[randomIndex]); } return credential.toString(); }
CredentialsGenerator { public String next(int length) { StringBuilder credential = new StringBuilder(length); for (int i = 0; i < length; i++) { int randomIndex = randomGenerator.nextInt(LEGAL_CHARACTERS.length); credential.append(LEGAL_CHARACTERS[randomIndex]); } return credential.toString(); } }
CredentialsGenerator { public String next(int length) { StringBuilder credential = new StringBuilder(length); for (int i = 0; i < length; i++) { int randomIndex = randomGenerator.nextInt(LEGAL_CHARACTERS.length); credential.append(LEGAL_CHARACTERS[randomIndex]); } return credential.toString(); } CredentialsGenerator(); protected  CredentialsGenerator(SecureRandom randomGenerator); }
CredentialsGenerator { public String next(int length) { StringBuilder credential = new StringBuilder(length); for (int i = 0; i < length; i++) { int randomIndex = randomGenerator.nextInt(LEGAL_CHARACTERS.length); credential.append(LEGAL_CHARACTERS[randomIndex]); } return credential.toString(); } CredentialsGenerator(); protected  CredentialsGenerator(SecureRandom randomGenerator); String next(int length); }
CredentialsGenerator { public String next(int length) { StringBuilder credential = new StringBuilder(length); for (int i = 0; i < length; i++) { int randomIndex = randomGenerator.nextInt(LEGAL_CHARACTERS.length); credential.append(LEGAL_CHARACTERS[randomIndex]); } return credential.toString(); } CredentialsGenerator(); protected  CredentialsGenerator(SecureRandom randomGenerator); String next(int length);  }