### Question:
StrUtil { public static String compressMiddle(String s, int headLength, int tailLength) { Validate.notNull(s, "Input string must not be null"); Validate.isTrue(headLength > 0, "Head length must be larger than 0"); Validate.isTrue(tailLength > 0, "Tail length must be larger than 0"); if(headLength + tailLength >= s.length()) { return s; } return s.substring(0, headLength) + "..." + s.substring(s.length() - tailLength); } private  StrUtil(); static String stringify(long byteNumber); static String replaceVariable(final String param); static String compressMiddle(String s, int headLength, int tailLength);  }### Answer:
@Test public void testCompressMiddle() { assertEquals("3", compressMiddle("3", 1, 9)); assertEquals("a...c", compressMiddle("a,b,c", 1, 1)); }
@Test public void testCompressMiddle() throws Exception { assertEquals(StrUtil.compressMiddle("0123456789", 2, 2), "01...89"); assertEquals(StrUtil.compressMiddle("0123456789", 5, 5), "0123456789"); assertEquals(StrUtil.compressMiddle("0123456789", 6, 7), "0123456789"); assertEquals(StrUtil.compressMiddle("0123456789", 10, 1), "0123456789"); assertEquals(StrUtil.compressMiddle("0123456789", 20, 2), "0123456789"); assertEquals(StrUtil.compressMiddle("0123456789", 2, 20), "0123456789"); }
@Test public void testCompressMiddleFailed() throws Exception { ex.expect(NullPointerException.class); StrUtil.compressMiddle(null, 2, 20); }
@Test public void testCompressMiddleFailed2() throws Exception { ex.expect(IllegalArgumentException.class); StrUtil.compressMiddle("sssss", 0, 20); }
@Test public void testCompressMiddleFailed3() throws Exception { ex.expect(IllegalArgumentException.class); StrUtil.compressMiddle("sfsdfsd", 2, -1); }