Utils { public static String toStringWithLimit(Object parameter) { if (parameter == null) { return NULL_STR; } String value = parameter.toString(); try { if (value.length() > DEFAULT_ARG_STRING_MAX_LENGTH) { value = value.substring(0, DEFAULT_ARG_STRING_MAX_LENGTH) + DEFAULT_MAX_STRING_ENDING; } return value; } catch (Throwable e) { return UNKNOWN; } }  static Map<Throwable, AutomonExpirable> createExceptionMap(); static String getLabel(Throwable throwable); static String getLabel(JoinPoint.StaticPart jp); static String formatExceptionForToolsWithLimitedCharacterSet(String exceptionLabel); static List<String> getArgNameValuePairs(JoinPoint jp); static String argNameValuePairsToString(List<String> args); static String toStringWithLimit(Object parameter); static String getExceptionTrace(Throwable exception); static String[] tokenize(String string, String splitOn); static String stripFileScheme(String fileName); static AutomonMXBean getAutomonMxBean(Object aspect); static void registerWithJmx(Object aspect, AutomonMXBean mxBean); static void unregisterWithJmx(Object aspect); static boolean hasPackageName(String className); static T createFirst(String... classNames); static void removeClassNames(List<String> list); static final String LINE_SEPARATOR; }
@Test public void testToStringWithLimit() throws Exception { assertThat(Utils.toStringWithLimit(null)).isEqualTo(Utils.NULL_STR); assertThat(Utils.toStringWithLimit("hi")).describedAs("Normal length string").isEqualTo("hi"); StringBuilder sb = new StringBuilder(); int SIZE = 1000; for (int i = 0; i < SIZE; i++) { sb.append("A"); } assertThat(Utils.toStringWithLimit(sb.toString()).length()).describedAs("Long strings should be truncated").isLessThan(SIZE); assertThat(Utils.toStringWithLimit(sb.toString())).describedAs("String too long should be truncated").endsWith(Utils.DEFAULT_MAX_STRING_ENDING); }