### Question:
RegExHelper { public static Optional<Pattern> compileToPattern(String value) { if (value == null || value.isEmpty()) return Optional.empty(); try { return Optional.of(Pattern.compile(value)); } catch (NullPointerException |PatternSyntaxException e) { LOG.finest(()->"Could not parse as regular expression " + value + ":" +e.getMessage()); return Optional.empty(); } }  static Optional<Pattern> compileToPattern(String value);  }### Answer:
@Test void compileToPattern() { assertEquals(RegExHelper.compileToPattern(""), Optional.empty()); assertEquals(RegExHelper.compileToPattern(null), Optional.empty()); assertEquals(RegExHelper.compileToPattern("["), Optional.empty()); assertEquals(RegExHelper.compileToPattern("abc\\s+").map(Pattern::pattern), Optional.of(Pattern.compile("abc\\s+")).map(Pattern::pattern)); }