Code example for Collection

Methods: addaddAllclearcontainscontainsAllisEmptyremoveremoveAllretainAll

        col = c;
    public void runTest() { 
        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(
        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
        assertTrue("CollectionTest - b) addAll failed", col
        // containsAll 
        assertTrue("CollectionTest - a) containsAll failed", col
        col.remove(new Integer(101));
        assertTrue("CollectionTest - b) containsAll failed", !col
        // removeAll 
        assertTrue("CollectionTest - a) removeAll failed", col
        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 
        assertTrue("CollectionTest - a) retainAll failed", col
        assertTrue("CollectionTest - b) retainAll failed", !col
                .retainAll(myCollection)); // should not change the colletion
                                            // the 2nd time around 
        assertTrue("CollectionTest - c) retainAll failed", col
        assertTrue("CollectionTest - d) retainAll failed", !col
                .contains(new Integer(0)));
        assertTrue("CollectionTest - e) retainAll failed", !col
                .contains(new Integer(50)));
        // clear 
        assertTrue("CollectionTest - a) clear failed", col.isEmpty());
        assertTrue("CollectionTest - b) clear failed", !col
                .contains(new Integer(101)));
Connect your IDE to all the code out there  Get Codota for Java