### Question:
FakerGenerator implements StringGenerator { @Override public Stream<String> generateRandomValues(RandomNumberGenerator randomNumberGenerator) { return Stream.generate(() -> getFakerValue(randomFaker)) .filter(underlyingRegexGenerator::validate); } FakerGenerator(StringGenerator underlyingRegexGenerator, String fakerSpec); @Override boolean matches(String string); @Override StringGenerator intersect(StringGenerator stringGenerator); @Override boolean validate(String string); @Override Stream<String> generateAllValues(); @Override Stream<String> generateRandomValues(RandomNumberGenerator randomNumberGenerator);  }### Answer:
@Test void generateRandomValuesUnrestricted() { StringRestrictions restrictions = StringRestrictionsFactory.forMaxLength(Defaults.MAX_STRING_LENGTH); RegexStringGenerator regex = (RegexStringGenerator) restrictions.createGenerator(); FakerGenerator generator = new FakerGenerator(regex, "name.firstName"); final int size = 10; List<String> results = generator.generateRandomValues(new JavaUtilRandomNumberGenerator()) .limit(size) .collect(Collectors.toList()); assertEquals(size, results.size()); }
@Test void generateRandomValuesRestrictedMin() { final int length = 9; StringRestrictions restrictions = StringRestrictionsFactory.forMinLength(length); RegexStringGenerator regex = (RegexStringGenerator) restrictions.createGenerator(); FakerGenerator generator = new FakerGenerator(regex, "name.firstName"); final int size = 10; Stream<String> results = generator.generateRandomValues(new JavaUtilRandomNumberGenerator()) .limit(size); assertTrue(results.allMatch(str -> str.length() >= length)); }
@Test void generateRandomValuesRestrictedMax() { final int length = 4; StringRestrictions restrictions = StringRestrictionsFactory.forMaxLength(length); RegexStringGenerator regex = (RegexStringGenerator) restrictions.createGenerator(); FakerGenerator generator = new FakerGenerator(regex, "name.firstName"); final int size = 10; Stream<String> results = generator.generateRandomValues(new JavaUtilRandomNumberGenerator()) .limit(size); assertTrue(results.allMatch(str -> str.length() <= length)); }