### Question:
Utils { public static Pattern safePatternCompile(String pattern) { try { return Pattern.compile(pattern); } catch (Exception e) { ConsoleLogger.warning("Failed to compile pattern '" + pattern + "' - defaulting to allowing everything"); return Pattern.compile(".*?"); } } private  Utils(); static Pattern safePatternCompile(String pattern); static boolean isClassLoaded(String className); static void logAndSendMessage(CommandSender sender, String message); static void logAndSendWarning(CommandSender sender, String message); static boolean isCollectionEmpty(Collection<?> coll); static boolean isEmailEmpty(String email); static final long MILLIS_PER_MINUTE; static final long MILLIS_PER_HOUR; }### Answer:
@Test public void shouldCompilePattern() { String pattern = "gr(a|e)ys?"; Pattern result = Utils.safePatternCompile(pattern); assertThat(result.toString(), equalTo(pattern)); }
@Test public void shouldDefaultToAllAllowedPattern() { String invalidPattern = "gr(a|eys?"; Pattern result = Utils.safePatternCompile(invalidPattern); assertThat(result.toString(), equalTo(".*?")); }