added method to Options which returns a random value of the given enu… (#84)
* added method to Options which returns a random value of the given enumeration * fixed BeerTest#testName regex
This commit is contained in:
committed by
Ricky Yim
parent
0e77fd7a9e
commit
762d963480
@@ -12,4 +12,9 @@ public class Options {
|
||||
public String option(String... options) {
|
||||
return options[randomService.nextInt(options.length)];
|
||||
}
|
||||
|
||||
public <E extends Enum<E>> E option(Class<E> enumeration) {
|
||||
E[] enumConstants = enumeration.getEnumConstants();
|
||||
return enumConstants[randomService.nextInt(enumConstants.length)];
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public class BeerTest {
|
||||
|
||||
@Test
|
||||
public void testName() {
|
||||
assertThat(faker.beer().name(), matchesRegularExpression("[A-Za-z'() 0-9-’’]+"));
|
||||
assertThat(faker.beer().name(), matchesRegularExpression("[\\p{L}'()\\., 0-9-’’]+"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,4 +26,13 @@ public class OptionsTest {
|
||||
public void testOptionWithVarargs() {
|
||||
assertThat(faker.options().option("A", "B", "C"), isOneOf(options));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionWithEnum() {
|
||||
assertThat(faker.options().option(Day.class), isOneOf(Day.values()));
|
||||
}
|
||||
|
||||
public enum Day {
|
||||
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user