BasePrintWorker { protected static String truncate(String string, int width) { int len = string.length(); if (len <= width) { return string; } if (width <= 2) { return ".."; } int offset = width / 2 - 1; int startOffset = offset + width % 2; int endOffset = len - offset; return string.substring(0, startOffset) + ".." + string.substring(endOffset); } BasePrintWorker(StringBuilder out, int maxDisplayRows, int maxDisplayColumnWidth);   }
@Test public void testTruncate() { assertEquals("..", BasePrintWorker.truncate("abc", 1)); assertEquals("..", BasePrintWorker.truncate("abc", 2)); assertEquals("abc", BasePrintWorker.truncate("abc", 3)); assertEquals("a..", BasePrintWorker.truncate("abcd", 3)); assertEquals("abc", BasePrintWorker.truncate("abc", 4)); assertEquals("abcd", BasePrintWorker.truncate("abcd", 4)); assertEquals("a..e", BasePrintWorker.truncate("abcde", 4)); assertEquals("a..f", BasePrintWorker.truncate("abcdef", 4)); assertEquals("ab..g", BasePrintWorker.truncate("abcdefg", 5)); assertEquals("ab..h", BasePrintWorker.truncate("abcdefgh", 5)); }