FileDocCategorySizeDatePackage
Support_CollectionTest.javaAPI DocAndroid 1.5 API4121Wed May 06 22:41:06 BST 2009tests.support

Support_CollectionTest

public class Support_CollectionTest extends TestCase
tests
java.util.Collection

Fields Summary
Collection
col
Constructors Summary
public Support_CollectionTest(String p1)

        super(p1);
    
public Support_CollectionTest(String p1, Collection c)

        super(p1);
        col = c;
    
Methods Summary
public voidrunTest()

        new Support_UnmodifiableCollectionTest("", col).runTest();

        // setup
        Collection<Integer> myCollection = new TreeSet<Integer>();
        myCollection.add(new Integer(101));
        myCollection.add(new Integer(102));
        myCollection.add(new Integer(103));

        // add
        assertTrue("CollectionTest - a) add did not work", col.add(new Integer(
                101)));
        assertTrue("CollectionTest - b) add did not work", col
                .contains(new Integer(101)));

        // remove
        assertTrue("CollectionTest - a) remove did not work", col
                .remove(new Integer(101)));
        assertTrue("CollectionTest - b) remove did not work", !col
                .contains(new Integer(101)));

        // addAll
        assertTrue("CollectionTest - a) addAll failed", col
                .addAll(myCollection));
        assertTrue("CollectionTest - b) addAll failed", col
                .containsAll(myCollection));

        // containsAll
        assertTrue("CollectionTest - a) containsAll failed", col
                .containsAll(myCollection));
        col.remove(new Integer(101));
        assertTrue("CollectionTest - b) containsAll failed", !col
                .containsAll(myCollection));

        // removeAll
        assertTrue("CollectionTest - a) removeAll failed", col
                .removeAll(myCollection));
        assertTrue("CollectionTest - b) removeAll failed", !col
                .removeAll(myCollection)); // should not change the colletion
                                            // the 2nd time around
        assertTrue("CollectionTest - c) removeAll failed", !col
                .contains(new Integer(102)));
        assertTrue("CollectionTest - d) removeAll failed", !col
                .contains(new Integer(103)));

        // retianAll
        col.addAll(myCollection);
        assertTrue("CollectionTest - a) retainAll failed", col
                .retainAll(myCollection));
        assertTrue("CollectionTest - b) retainAll failed", !col
                .retainAll(myCollection)); // should not change the colletion
                                            // the 2nd time around
        assertTrue("CollectionTest - c) retainAll failed", col
                .containsAll(myCollection));
        assertTrue("CollectionTest - d) retainAll failed", !col
                .contains(new Integer(0)));
        assertTrue("CollectionTest - e) retainAll failed", !col
                .contains(new Integer(50)));

        // clear
        col.clear();
        assertTrue("CollectionTest - a) clear failed", col.isEmpty());
        assertTrue("CollectionTest - b) clear failed", !col
                .contains(new Integer(101)));