TitleBuffer { public TitleBuffer truncate(final int noWords) { if (noWords < 1) { throw new IllegalArgumentException("Truncation must be to one or more words"); } int pos = 0; int spaces = 0; while (pos < title.length() && spaces < noWords) { if (title.charAt(pos) == ' ') { spaces++; } pos++; } if (pos < title.length()) { title.setLength(pos - 1); title.append("..."); } return this; } TitleBuffer();  TitleBuffer(final Object object);  TitleBuffer(final Object object, final String defaultTitle);  TitleBuffer(final String text); static boolean isEmpty(final Object object); static boolean isEmpty(final String text); TitleBuffer append(final int number); TitleBuffer append(final Object object); TitleBuffer append(final Object object, final String defaultValue); TitleBuffer append(final String text); TitleBuffer append(final String joiner, final Object object); TitleBuffer append(final String joiner, final Object object, final String defaultTitle); TitleBuffer append(final String joiner, final String text); TitleBuffer appendSpace(); final TitleBuffer concat(final Object object); final TitleBuffer concat(final Object object, final String defaultValue); final TitleBuffer concat(final String text); TitleBuffer concat(final String joiner, final String text); final TitleBuffer concat(final String joiner, final Object object); final TitleBuffer concat(final String joiner, final Object object, final String defaultValue); @Override String toString(); TitleBuffer truncate(final int noWords);  }
@Test public void testTruncateMustBeAUsableLength() { try { t3.truncate(0); fail("Exception expected"); } catch (final IllegalArgumentException ee) { } }