StringTrimmer { public String removeTrailingAndLeading(String inputStr) { return removeTrailingAndLeading(inputStr, " "); }  String removeTrailingAndLeadingWhitespaces(final String inputStr); String removeTrailingAndLeading(String inputStr); String removeTrailingAndLeading(String inputStr, String removeStr); String removeTrailingAndLeading(String inputStr, Character removeCharacter); static final Set<Character> WHITESPACE_CHARS_SUPERIOR_ASCII_SPACE; }
@Test public void testRemoveTrailingAndLeading() { StringTrimmer stringTrimmer = new StringTrimmer(); assertEquals(expected, stringTrimmer.removeTrailingAndLeading(expected)); assertEquals(expected, stringTrimmer.removeTrailingAndLeading(" abc")); assertEquals(expected, stringTrimmer.removeTrailingAndLeading(" abc ")); assertEquals(expected, stringTrimmer.removeTrailingAndLeading(" abc ")); assertEquals(expected, stringTrimmer.removeTrailingAndLeading(" abc ")); assertEquals(expected, stringTrimmer.removeTrailingAndLeading(" abc ")); assertEquals("ab c", stringTrimmer.removeTrailingAndLeading(" ab c")); assertEquals("a b c", stringTrimmer.removeTrailingAndLeading(" a b c ")); assertEquals("", stringTrimmer.removeTrailingAndLeading("aaa", "a")); assertEquals("", stringTrimmer.removeTrailingAndLeading("\t", "\t")); assertEquals(expected, stringTrimmer.removeTrailingAndLeading("\t" + expected, "\t")); assertEquals(expected, stringTrimmer.removeTrailingAndLeading(expected + "\t", "\t")); assertEquals(expected, stringTrimmer.removeTrailingAndLeading('\u0009' + expected, "\t")); assertEquals(expected, stringTrimmer.removeTrailingAndLeading('\u0009' + expected, '\u0009' + "")); assertEquals(expected, stringTrimmer.removeTrailingAndLeading('\u0009' + expected + '\u0009' + '\u0009', "\t")); assertEquals("abc ", stringTrimmer.removeTrailingAndLeading("\t" + "abc ", "\t")); assertEquals("a" + "\t" + "bc", stringTrimmer.removeTrailingAndLeading("\t" + "a" + "\t" + "bc", "\t")); assertEquals("\t" + expected, stringTrimmer.removeTrailingAndLeading("\t" + "abc ")); assertEquals(expected, ("\t" + "abc ").trim()); assertEquals(expected, stringTrimmer.removeTrailingAndLeading("\n" + expected, "\n")); assertEquals("abc ", stringTrimmer.removeTrailingAndLeading("\n" + "abc ", "\n")); assertEquals(expected, stringTrimmer.removeTrailingAndLeading(expected, "\r")); assertEquals(expected, stringTrimmer.removeTrailingAndLeading("\r" + expected, "\r")); assertEquals(expected, stringTrimmer.removeTrailingAndLeading("\r" + expected + "\r", "\r")); assertEquals("abc ", stringTrimmer.removeTrailingAndLeading("\r" + "abc ", "\r")); assertEquals("abc ", stringTrimmer.removeTrailingAndLeading("\r" + "abc " + "\r", "\r")); assertEquals("bc", stringTrimmer.removeTrailingAndLeading(" abc", " a")); assertEquals(" a", stringTrimmer.removeTrailingAndLeading(" abc", "bc")); assertEquals("ab", stringTrimmer.removeTrailingAndLeading("cabc", "c")); assertEquals("𠀀𠀁b", stringTrimmer.removeTrailingAndLeading("a𠀀𠀁ba", "a")); assertEquals("a𠀁b", stringTrimmer.removeTrailingAndLeading("𠀀a𠀁b", "𠀀")); }