### Question:
Utilities { public static String truncateNicely(String str, int lower, int upper, String appendToEnd) { String str2 = removeHTML(str, false); boolean diff = (str2.length() < str.length()); if (upper < lower) { upper = lower; } if (str2.length() > upper) { int loc; loc = str2.lastIndexOf(' ', upper); if (loc >= lower) { str2 = str2.substring(0, loc); } else { str2 = str2.substring(0, upper); loc = upper; } if (diff) { loc = str2.lastIndexOf(' ', loc); String str3 = str2.substring(loc + 1); loc = str.indexOf(str3, loc) + str3.length(); str2 = str.substring(0, loc); str3 = extractHTML(str.substring(loc)); str = str2 + appendToEnd + str3; } else { str = str2 + appendToEnd; } } return str; }  static String stripJsessionId(String url); static String escapeHTML(String s); static String escapeHTML(String s, boolean escapeAmpersand); static String unescapeHTML(String str); static String removeHTML(String str); static String removeHTML(String str, boolean addSpace); static String removeAndEscapeHTML(String s); static String autoformat(String s); static String addNofollow(String html); static String replaceNonAlphanumeric(String str); static String replaceNonAlphanumeric(String str, char subst); static String removeNonAlphanumeric(String str); static String stringArrayToString(String[] stringArray, String delim); static String stringListToString(List<String> stringList,
            String delim); static String[] stringToStringArray(String instr, String delim); static List<String> stringToStringList(String instr, String delim); static int[] stringToIntArray(String instr, String delim); static String intArrayToString(int[] intArray); static void copyFile(File from, File to); static String streamToString(InputStream is); static void copyInputToOutput(InputStream input,
            OutputStream output, long byteCount); static void copyInputToOutput(InputStream input, OutputStream output); static String encodePassword(String password, String algorithm); static String encodeString(String str); static String decodeString(String str); static String truncate(String str, int lower, int upper,
            String appendToEnd); static String truncateNicely(String str, int lower, int upper,
            String appendToEnd); static String truncateText(String str, int lower, int upper,
            String appendToEnd); static String extractHTML(String str); static String hexEncode(String str); static String encodeEmail(String str); static final String encode(String s); static final String decode(String s); static int stringToInt(String string); static String toBase64(byte[] aValue); static String stripInvalidTagCharacters(String tag); static String normalizeTag(String tag, Locale locale); static List<String> splitStringAsTags(String tags); static String transformToHTMLSubset(String s); static String getContentTypeFromFileName(String fileName); static boolean isValidEmailAddress(String aEmailAddress); static final String TAG_SPLIT_CHARS; }### Answer:
@Test public void testTruncateNicely1() { String test = "blah blah blah blah blah"; String expect = "blah blah blah"; String result = Utilities.truncateNicely(test, 11, 15, ""); assertEquals(expect, result); }
@Test public void testTruncateNicely2() { String test = "<p><b>blah1 blah2</b> <i>blah3 blah4 blah5</i></p>"; String expect = "<p><b>blah1 blah2</b> <i>blah3</i></p>"; String result = Utilities.truncateNicely(test, 15, 20, ""); assertEquals(expect, result); }