TokenList extends AbstractList<String> { @Override public String toString() { final StringBuilder str = new StringBuilder(); final Iterator<String> iterator = iterator(); while (iterator.hasNext()) { final String token = iterator.next(); str.append(token); if (iterator.hasNext()) { str.append(' '); } } return str.toString(); } TokenList();  TokenList(final String stringlist); @Override String get(final int index); @Override int size(); @Override String toString(); @Override boolean add(final String o);  }
@Test public void testToString() { final TokenList list1 = new TokenList(); list1.add(TOKEN1); list1.add(TOKEN2); list1.add(TOKEN3); Assert.assertEquals(TOKEN_LIST, list1.toString()); final TokenList list2 = new TokenList(TOKEN_LIST); Assert.assertEquals(TOKEN_LIST, list2.toString()); }