### Question:
RecoveryCodeGenerator { public String[] generateCodes(int amount) { if (amount < 1) { throw new InvalidParameterException("Amount must be at least 1."); } String[] codes = new String[amount]; Arrays.setAll(codes, i -> generateCode()); return codes; }  String[] generateCodes(int amount);  }### Answer:
@Test public void testCorrectAmountGenerated() { RecoveryCodeGenerator generator = new RecoveryCodeGenerator(); String[] codes = generator.generateCodes(16); assertEquals(16, codes.length); for (String code : codes) { assertNotNull(code); } }
@Test public void testCodesMatchFormat() { RecoveryCodeGenerator generator = new RecoveryCodeGenerator(); String[] codes = generator.generateCodes(16); for (String code : codes) { assertTrue(code.matches("[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}"), code); } }
@Test public void testCodesAreUnique() { RecoveryCodeGenerator generator = new RecoveryCodeGenerator(); String[] codes = generator.generateCodes(25); Set<String> uniqueCodes = new HashSet<>(Arrays.asList(codes)); assertEquals(25, uniqueCodes.size()); }
@Test public void testInvalidNumberThrowsException() { RecoveryCodeGenerator generator = new RecoveryCodeGenerator(); assertThrows(InvalidParameterException.class, () -> { generator.generateCodes(-1); }); }