### Question:
RecoveryCodeGenerator { public String[] generateCodes(int numCodes, CodeGeneratorSource alphabet, boolean allowDuplicates) throws CodeException { return generateCodes(numCodes, alphabet, DEFAULT_LENGTH, allowDuplicates); } RecoveryCodeGenerator(SecureRandom secureRandom, int retryMaximum); @Inject  RecoveryCodeGenerator(SecureRandom secureRandom); String generateCode(CodeGeneratorSource alphabet, int length); String generateDelimitedCode(CodeGeneratorSource alphabet, char delimiter, int... groups); String generateDelimitedCodeWithSpecifics(CodeGeneratorSource alphabet, char delimiter,
                                                       Map<Integer, Character> specifics, int... groups); String[] generateCodes(int numCodes, CodeGeneratorSource alphabet, boolean allowDuplicates); String[] generateCodes(int numCodes, CodeGeneratorSource alphabet, int length, boolean allowDuplicates); String[] generateDelimitedCodes(int numCodes, CodeGeneratorSource alphabet,
                                           char delimiter, boolean allowDuplicates, int... groups); String[] generateDelimitedCodesWithSpecifics(int numCodes, CodeGeneratorSource alphabet,
                                                        char delimiter, Map<Integer, Character> specifics,
                                                        boolean allowDuplicates, int... groups); final static int DEFAULT_LENGTH; final static int DEFAULT_RETRIES; }### Answer:
@Test public void shouldGenerateAlphanumericRandomCode() throws CodeException { String[] codes = recoveryCodeGenerator.generateCodes(100, Alphabet.ALPHANUMERIC, false); for (String code : codes) { assertThat(ALPHANUMERIC.matcher(code).matches()).isTrue(); } }
@Test public void shouldGenerateHexRandomCode() throws CodeException { String[] codes = recoveryCodeGenerator.generateCodes(100, Alphabet.HEX_DIGITS, true); for (String code : codes) { assertThat(HEX.matcher(code).matches()).isTrue(); } }
@Test (expectedExceptions = CodeException.class) public void shouldErrorGeneratingDuplicateCodes3() throws CodeException { recoveryCodeGenerator.generateCodes(2, new TestAlphabet(), false); }
@Test (expectedExceptions = IllegalArgumentException.class) public void shouldErrorRequestedSizeTooSmall3() throws CodeException { recoveryCodeGenerator.generateCodes(0, new TestAlphabet(), true); }
@Test (expectedExceptions = IllegalArgumentException.class) public void shouldErrorRequestedSizeTooSmall4() throws CodeException { recoveryCodeGenerator.generateCodes(0, new TestAlphabet(), 10, true); }
@Test (expectedExceptions = IllegalArgumentException.class) public void shouldErrorRequestedLengthTooSmall() throws CodeException { recoveryCodeGenerator.generateCodes(10, new TestAlphabet(), 0, true); }
@Test (expectedExceptions = NullPointerException.class) public void shouldErrorNullAlphabet3() throws CodeException { recoveryCodeGenerator.generateCodes(10, null, true); }