Strings { static String toString(Object obj) { if (obj == null) { return "null"; } if (obj instanceof CharSequence) { return '"' + printableToString(obj.toString()) + '"'; } if (obj instanceof Collection) { return collectionToString((Collection) obj); } Class<?> cls = obj.getClass(); if (Byte.class == cls) { return byteToString((Byte) obj); } if (cls.isArray()) { return arrayToString(cls.getComponentType(), obj); } return obj.toString(); } private  Strings();   }
@Test public void testLargeCollectionToString() { List<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < 1000; i++) { list.add(123456); } String result = Strings.toString(list); String expectedTail = "] (126:1000)"; assertThat(result.endsWith(expectedTail), is(true)); assertThat(result.length(), lessThan(Strings.LOG_CONTENT_MAX_LENGTH + 20)); }
@Test public void testLargeObjectArrayToString() { Integer[] list = new Integer[1000]; for (int i = 0; i < 1000; i++) { list[i] = 123456; } String result = Strings.toString(list); String expectedTail = "] (126:1000)"; assertThat(result.endsWith(expectedTail), is(true)); assertThat(result.length(), lessThan(Strings.LOG_CONTENT_MAX_LENGTH + 20)); }
@Test public void testLargePrimitiveArrayToString() { int[] list = new int[1000]; for (int i = 0; i < 1000; i++) { list[i] = 123456; } String result = Strings.toString(list); String expectedTail = "] (126:1000)"; assertThat(result.endsWith(expectedTail), is(true)); assertThat(result.length(), lessThan(Strings.LOG_CONTENT_MAX_LENGTH + 20)); }