StringTools { public static String formatFileSize(long fileSize) { String returnSize; if (fileSize < KB) { returnSize = fileSize + " Bytes"; } else { String appendText; long divider; if (fileSize < MB) { appendText = " KB"; divider = KB; } else if (fileSize < GB) { appendText = " MB"; divider = MB; } else { appendText = " GB"; divider = GB; } DecimalFormat df; long checker = (fileSize / divider); if (checker < 10) { df = FILESIZE_FORMAT_2; } else if (checker < 100) { df = FILESIZE_FORMAT_1; } else { df = FILESIZE_FORMAT_0; } returnSize = df.format(((float) fileSize / (float) divider)) + appendText; } return returnSize; } private  StringTools(); static String characterMapReplacement(Character charToReplace); static String stringMapReplacement(String stringToReplace); static String appendToPath(final String basePath, final String additionalPath); static String cleanString(String sourceString); static String formatFileSize(long fileSize); static boolean isNotValidString(String testString); static boolean isValidString(String testString); static String trimToLength(String sourceString, int requiredLength); static String trimToLength(String sourceString, int requiredLength, boolean trimToWord, String endingSuffix); static List<T> castList(Class<? extends T> objClass, Collection<?> c); static List<String> splitList(String stringToSplit, String regexDelim); static String[] tokenizeToArray(String sourceString, String delimiter); static String processMpaaCertification(String mpaaCertification); static String processMpaaCertification(String mpaaRated, String mpaaCertification); static String replaceQuotes(String original); static int parseRating(String rating); static int parseRating(float rating); static String getWords(final String sentanceToTrim, int numOfWords);  }
@Test public void testFormatFileSize() { LOG.info("formatFileSize"); long fileSize; String result; fileSize = 900L; result = StringTools.formatFileSize(fileSize); assertEquals("Failed Bytes Test", "900 Bytes", result); fileSize = 900000L; result = StringTools.formatFileSize(fileSize); assertEquals("Failed KB Test", "879 KB", result); fileSize = 900000000L; result = StringTools.formatFileSize(fileSize); assertEquals("Failed MB Test", "858 MB", result); fileSize = 900000000000L; result = StringTools.formatFileSize(fileSize); assertEquals("Failed GB Test", "838 GB", result); }