Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 40718 invoked from network); 11 Dec 2004 08:06:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 11 Dec 2004 08:06:22 -0000 Received: (qmail 73618 invoked by uid 500); 11 Dec 2004 08:06:21 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 73271 invoked by uid 500); 11 Dec 2004 08:06:20 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 94712 invoked by uid 500); 11 Dec 2004 06:24:11 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Date: 11 Dec 2004 06:24:10 -0000 Message-ID: <20041211062410.15199.qmail@minotaur.apache.org> From: neilotoole@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestListUtils.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N neilotoole 2004/12/10 22:24:10 Modified: collections/src/test/org/apache/commons/collections TestListUtils.java Log: Added test cases for new methods in ListUtils #retainAll(Collection, Collection) #removeAll(Collection, Collection) #unmodifiableListCopy(Collection) Revision Changes Path 1.20 +92 -3 jakarta-commons/collections/src/test/org/apache/commons/collections/TestListUtils.java Index: TestListUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestListUtils.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- TestListUtils.java 2 Jun 2004 22:12:14 -0000 1.19 +++ TestListUtils.java 11 Dec 2004 06:24:10 -0000 1.20 @@ -35,7 +35,17 @@ */ public class TestListUtils extends BulkTest { - public TestListUtils(String name) { + private static final String a = "a"; + private static final String b = "b"; + private static final String c = "c"; + private static final String d = "d"; + private static final String e = "e"; + private static final String x = "x"; + + private String[] fullArray; + private List fullList; + + public TestListUtils(String name) { super(name); } @@ -43,6 +53,12 @@ return BulkTest.makeSuite(TestListUtils.class); } + public void setUp() { + fullArray = new String[]{a, b, c, d, e}; + fullList = new ArrayList(Arrays.asList(fullArray)); + } + + public void testNothing() { } @@ -118,6 +134,79 @@ a.clear(); assertEquals(false, ListUtils.hashCodeForList(a) == ListUtils.hashCodeForList(b)); assertEquals(0, ListUtils.hashCodeForList(null)); - } + } + + public void testUnmodifiableListCopy() { + List list = new ArrayList(); + list.add("a"); + List copy = ListUtils.unmodifiableListCopy(list); + + assertTrue(copy instanceof Unmodifiable); + assertTrue(list.equals(copy)); + list.clear(); + assertTrue(copy.isEmpty() == false); + + try + { + copy.clear(); + fail("should be unmodifiable."); + } + catch (UnsupportedOperationException uoe) + { + // this is what we want + } + + try + { + list = ListUtils.unmodifiableListCopy(null); + fail("expecting IllegalArgumentException"); + } + catch (IllegalArgumentException iae) + { + // this is what we want + } + } + + public void testRetainAll() { + List sub = new ArrayList(); + sub.add(a); + sub.add(b); + sub.add(x); + + List retained = ListUtils.retainAll(fullList, sub); + assertTrue(retained.size() == 2); + sub.remove(x); + assertTrue(retained.equals(sub)); + fullList.retainAll(sub); + assertTrue(retained.equals(fullList)); + + try + { + List list = ListUtils.retainAll(null, null); + fail("expecting NullPointerException"); + } + catch(NullPointerException npe) + {} // this is what we want + } + + public void testRemoveAll() { + List sub = new ArrayList(); + sub.add(a); + sub.add(b); + sub.add(x); + + List remainder = ListUtils.removeAll(fullList, sub); + assertTrue(remainder.size() == 3); + fullList.removeAll(sub); + assertTrue(remainder.equals(fullList)); + + try + { + List list = ListUtils.removeAll(null, null); + fail("expecting NullPointerException"); + } + catch(NullPointerException npe) + {} // this is what we want + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org