PatternExtractor { public List<ReplacingPattern> getPatternsFromString(String pattern) throws MailetException { String trimPattern = pattern.trim(); assertPatternSurroundedWithSlashes(trimPattern); ImmutableList.Builder<ReplacingPattern> patternList = ImmutableList.builder(); for (String aPatternArray : extractPatternParts(trimPattern)) { patternList.add(stripSurroundingSlashes(aPatternArray)); } return patternList.build(); }  List<ReplacingPattern> getPatternsFromString(String pattern); List<ReplacingPattern> getPatternsFromFileList(String filepar);  }
@Test void getPatternsFromStringShouldReturnValuesWhenMultiplePatterns() throws Exception { List<ReplacingPattern> patternsFromString = testee.getPatternsFromString("/test/TEST/i/,/a/e assertThat(patternsFromString).containsOnly( new ReplacingPattern(Pattern.compile("test"), false, "TEST"), new ReplacingPattern(Pattern.compile("a"), false, "e"), new ReplacingPattern(Pattern.compile("o"), true, "o")); }
@Test void getPatternsFromStringShouldThrowWhenPatternIsLessThanTwoCharacters() { assertThatThrownBy(() -> testee.getPatternsFromString("a")).isInstanceOf(MailetException.class); }
@Test void getPatternsFromStringShouldThrowWhenPatternDoesNotStartWithSlash() { assertThatThrownBy(() -> testee.getPatternsFromString("abc/")).isInstanceOf(MailetException.class); }
@Test void getPatternsFromStringShouldThrowWhenPatternDoesNotEndWithSlash() { assertThatThrownBy(() -> testee.getPatternsFromString("/abc")).isInstanceOf(MailetException.class); }
@Test void serviceShouldUnescapeCarriageReturn() throws Exception { List<ReplacingPattern> patternsFromString = testee.getPatternsFromString("/a/\\\\r/i/"); assertThat(patternsFromString).containsOnly(new ReplacingPattern(Pattern.compile("a"), false, "\\\r")); }
@Test void serviceShouldUnescapeLineBreak() throws Exception { List<ReplacingPattern> patternsFromString = testee.getPatternsFromString("/a/\\\\n/i/"); assertThat(patternsFromString).containsOnly(new ReplacingPattern(Pattern.compile("a"), false, "\\\n")); }
@Test void serviceShouldUnescapeTabReturn() throws Exception { List<ReplacingPattern> patternsFromString = testee.getPatternsFromString("/a/\\\\t/i/"); assertThat(patternsFromString).containsOnly(new ReplacingPattern(Pattern.compile("a"), false, "\\\t")); }