ConfigPropertyUtils { public static <T extends Enum<T>> Pattern createValidationPatternFromEnumType(Class<T> enumType) { String regEx = Stream.of(enumType.getEnumConstants()) .map(Enum::name) .collect(Collectors.joining("|", "(?i)", "")); regEx = regEx.replace("$", "\\$"); return Pattern.compile(regEx); }  static Pattern createValidationPatternFromEnumType(Class<T> enumType); static void checkNotNullAndNotEmpty(String value, String propertyName);  }
@Test public void testEnumWithPermittedCharacters() { Pattern actual = ConfigPropertyUtils.createValidationPatternFromEnumType(Scope.class); assertEquals("(?i)SCENARIO|FEATURE", actual.pattern()); }
@Test public void testEnumWithBadCharacters() { Pattern actual = ConfigPropertyUtils.createValidationPatternFromEnumType(BadBadEnum.class); assertEquals("(?i)This_Enum_Val_Cointains_Really_\\$_BAD_CHARS_£", actual.pattern()); assertTrue(actual.matcher(BadBadEnum.This_Enum_Val_Cointains_Really_$_BAD_CHARS_£.name()).matches()); }