@Test public void shouldTruncateStringLongerThanThreshold() { String result = StringTruncator.truncateWithoutWordSplit("abc def ghi", 6); assertEquals("abc def", result); }
public static String truncateWithoutWordSplit(String source, int length) { if (source.length() <= length) { return source; } BreakIterator atWordInstance = BreakIterator.getWordInstance(); atWordInstance.setText(source); return source.substring(0, atWordInstance.following(length)).trim(); }
StringTruncator { public static String truncateWithoutWordSplit(String source, int length) { if (source.length() <= length) { return source; } BreakIterator atWordInstance = BreakIterator.getWordInstance(); atWordInstance.setText(source); return source.substring(0, atWordInstance.following(length)).trim(); } }
StringTruncator { public static String truncateWithoutWordSplit(String source, int length) { if (source.length() <= length) { return source; } BreakIterator atWordInstance = BreakIterator.getWordInstance(); atWordInstance.setText(source); return source.substring(0, atWordInstance.following(length)).trim(); }  }
StringTruncator { public static String truncateWithoutWordSplit(String source, int length) { if (source.length() <= length) { return source; } BreakIterator atWordInstance = BreakIterator.getWordInstance(); atWordInstance.setText(source); return source.substring(0, atWordInstance.following(length)).trim(); }  static String truncateWithoutWordSplit(String source, int length); }
StringTruncator { public static String truncateWithoutWordSplit(String source, int length) { if (source.length() <= length) { return source; } BreakIterator atWordInstance = BreakIterator.getWordInstance(); atWordInstance.setText(source); return source.substring(0, atWordInstance.following(length)).trim(); }  static String truncateWithoutWordSplit(String source, int length);  }