### Question:
StringFormatUtil { public static String truncateText(String text, int length) { return truncateText(text, length, DEFAULT_LAST_WORD_ALLOWANCE); } private  StringFormatUtil(); static String formatFilesize(String filesize, int decimalPlaces); static String formatFilesize(long filesize, int decimalPlaces); static String truncateText(String text, int length); static String urlEncode(String value); static String removeQueryParameter(String query, String key); static String makeToken(String input, String replacement);  }### Answer:
@Test public void testTruncateText() { String text = StringUtils.repeat('1', 100); assertEquals(50, StringFormatUtil.truncateText(text, 50).length()); }
@Test(expected = IndexOutOfBoundsException.class) public void testTruncateTextNegativeIndex() { String text = StringUtils.repeat('1', 5); StringFormatUtil.truncateText(text, -1); }
@Test public void testTruncateTextGreaterThanLength() { String text = StringUtils.repeat('1', 5); assertEquals(5, StringFormatUtil.truncateText(text, 10).length()); }
@Test public void testTruncateTextNull() { assertNull(StringFormatUtil.truncateText(null, 10)); }
@Test public void testTruncateTextWordBoundry() { String text = StringUtils.repeat("word ", 10); assertEquals(39, StringFormatUtil.truncateText(text, 42).length()); }
@Test public void testTruncateTextWordBoundryOutOfRange() { String text = StringUtils.repeat("reallyreallylongword ", 5); assertEquals(80, StringFormatUtil.truncateText(text, 80).length()); }
@Test public void testTruncateTextCutOffBeforeWordLongerThanAllowance() { String text = StringUtils.repeat("reallyreallylongword ", 5); assertEquals(62, StringFormatUtil.truncateText(text, 68).length()); }