You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ne...@apache.org on 2004/12/11 07:24:10 UTC

cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestListUtils.java

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