Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
test: add test for composite Faker expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ro4052 committed Jul 14, 2020
1 parent aee2d2d commit ba7c05e
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -74,4 +75,21 @@ void generateRandomValuesRestrictedMax() {

assertTrue(results.allMatch(str -> str.length() <= length));
}

@Test
void generateWithCompositeExpression() {
String jobTitleRegex = "^[A-Za-z]+ [A-Za-z]+$";
StringRestrictions restrictions = StringRestrictionsFactory.forStringMatching(
Pattern.compile(jobTitleRegex), false
);
RegexStringGenerator regex = (RegexStringGenerator) restrictions.createGenerator();
FakerGenerator generator = new FakerGenerator(regex, "job.title");

final int size = 10;

Stream<String> results = generator.generateRandomValues(new JavaUtilRandomNumberGenerator())
.limit(size);

assertTrue(results.allMatch(str -> str.matches(jobTitleRegex)));
}
}

0 comments on commit ba7c05e

Please sign in to comment.