Forum Discussion
Hi Lisa Marie,
I understand your problem with updating enums in Cucumber 7.0.0. Instead of hardcoding them, you can generate the enum values automatically. This way, you won't have to change the strings manually every time.
You can use Java reflection to get all the enum values and create the pattern. Here's an example:
@ParameterType(name = "animal_type", value = AnimalType.REGEX)
public Animal defineAnimalType(final String animalType) {
return Animal.fromString(animalType);
}
public enum AnimalType {
CAT, HORSE, DOG, DONKEY, PIG;
public static final String REGEX = Arrays.stream(values())
.map(Enum::name)
.collect(Collectors.joining("|"));
}
This way, any changes to the enum are automatically included in the pattern.
For more details, visit: https://minicow.us/.
Related Content
- 2 years ago