Text { public static String containingString(String str, String prefix, String suffix) { if(Strings.isNullOrEmpty(str)) return str; Preconditions.checkNotNull(prefix); Preconditions.checkNotNull(suffix); int prefixIdx = str.indexOf(prefix); int suffixIdx = str.indexOf(suffix, prefixIdx + 1); if(prefixIdx < 0 || suffixIdx < 0) return ""; return str.substring(prefixIdx + 1, suffixIdx); }  static String removeLast(String s); static String generateHash(String key); static String capitalize(String s); static String matchMax(String left, String right); static boolean containsEvilSpecialChar(String stringToCheck); static String containingString(String str, String prefix, String suffix);  }
@Test public void testContainingString() { assertThat(Text.containingString("xabcy", "x", "y"), is("abc")); assertThat(Text.containingString("xabc", "x", "y"), is("")); assertThat(Text.containingString("xabc", "x", "y"), is("")); assertThat(Text.containingString(null, "x", "y"), is(nullValue())); assertThat(Text.containingString("", "x", "y"), is("")); assertThat(Text.containingString("xy", "x", "y"), is("")); try { Text.containingString("xabcy", null, "y"); fail(); } catch(Exception ignored) {} try { Text.containingString("xabcy", "x", null); fail(); } catch(Exception ignored) {} }