RegexModifier implements Modifier { @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("RegexModifier [\nfactory="); builder.append(factory); builder.append(", \nreplacement="); builder.append(matchProcessor); builder.append(", \nmatcher="); builder.append(matcher); builder.append(", \nnewNumberOfChars="); builder.append(newNumberOfChars); builder.append("]"); return builder.toString(); } protected  RegexModifier();  RegexModifier(String regex, int flags, String replacement);  RegexModifier(String regex, int flags, String replacement, int minimumLengthOfLookBehind,
            int newNumberOfChars);  RegexModifier(String regex, int flags, MatchProcessor matchProcessor, int minimumLengthOfLookBehind,
            int newNumberOfChars);  RegexModifier(OnStreamMatcher matcher, MatchProcessor matchProcessor, int minimumLengthOfLookBehind,
            int newNumberOfChars); @Override AfterModification modify(StringBuilder characterBuffer, int firstModifiableCharacterInBuffer,
            boolean endOfStreamHit); @Override String toString(); void setMatchProcessor(MatchProcessor matchProcessor);  }
@Test public void testExampleFromRegexModifierJavadoc_OwnMatchProcessor() throws Exception { String fakeErrorLog = "1 ERROR aa\n2 WARN bb\n3 ERROR cc"; Reader originalReader = new StringReader( fakeErrorLog); Modifier myModifier = new RegexModifier("^.*ERROR.*$", Pattern.MULTILINE, new MatchPrinter(), 0, 2048); Reader modifyingReader = new ModifyingReader(originalReader, myModifier); String output = IOUtils.toString(modifyingReader); assertEquals(fakeErrorLog, output); }
@Test public void testExampleFromHomepage_usage() throws Exception { Reader originalReader = new StringReader("edit stream"); Modifier myModifier = new RegexModifier("edit stream", 0, "modify stream"); Reader modifyingReader = new ModifyingReader(originalReader, myModifier); String output = IOUtils.toString(modifyingReader); assertEquals("modify stream", output); }
@Test public void testExampleFromHomepage_usage2() throws Exception { Reader originalReader = new StringReader("edit\n\nStream"); Modifier myModifier = new RegexModifier("edit(\\s+)stream", Pattern.CASE_INSENSITIVE, "modify$1stream"); Reader modifyingReader = new ModifyingReader(originalReader, myModifier); String output = IOUtils.toString(modifyingReader); assertEquals("modify\n\nstream", output); }