1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package tests.support; 19 20import java.util.Collection; 21import java.util.TreeSet; 22 23/** 24 * @tests java.util.Collection 25 */ 26public class Support_CollectionTest extends junit.framework.TestCase { 27 28 Collection<Integer> col; // must contain the Integers 0 to 99 29 30 public Support_CollectionTest(String p1) { 31 super(p1); 32 } 33 34 public Support_CollectionTest(String p1, Collection<Integer> c) { 35 super(p1); 36 col = c; 37 } 38 39 @Override 40 public void runTest() { 41 new Support_UnmodifiableCollectionTest("", col).runTest(); 42 43 // setup 44 Collection<Integer> myCollection = new TreeSet<Integer>(); 45 myCollection.add(new Integer(101)); 46 myCollection.add(new Integer(102)); 47 myCollection.add(new Integer(103)); 48 49 // add 50 assertTrue("CollectionTest - a) add did not work", col.add(new Integer( 51 101))); 52 assertTrue("CollectionTest - b) add did not work", col 53 .contains(new Integer(101))); 54 55 // remove 56 assertTrue("CollectionTest - a) remove did not work", col 57 .remove(new Integer(101))); 58 assertTrue("CollectionTest - b) remove did not work", !col 59 .contains(new Integer(101))); 60 61 // addAll 62 assertTrue("CollectionTest - a) addAll failed", col 63 .addAll(myCollection)); 64 assertTrue("CollectionTest - b) addAll failed", col 65 .containsAll(myCollection)); 66 67 // containsAll 68 assertTrue("CollectionTest - a) containsAll failed", col 69 .containsAll(myCollection)); 70 col.remove(new Integer(101)); 71 assertTrue("CollectionTest - b) containsAll failed", !col 72 .containsAll(myCollection)); 73 74 // removeAll 75 assertTrue("CollectionTest - a) removeAll failed", col 76 .removeAll(myCollection)); 77 assertTrue("CollectionTest - b) removeAll failed", !col 78 .removeAll(myCollection)); // should not change the colletion 79 // the 2nd time around 80 assertTrue("CollectionTest - c) removeAll failed", !col 81 .contains(new Integer(102))); 82 assertTrue("CollectionTest - d) removeAll failed", !col 83 .contains(new Integer(103))); 84 85 // retianAll 86 col.addAll(myCollection); 87 assertTrue("CollectionTest - a) retainAll failed", col 88 .retainAll(myCollection)); 89 assertTrue("CollectionTest - b) retainAll failed", !col 90 .retainAll(myCollection)); // should not change the colletion 91 // the 2nd time around 92 assertTrue("CollectionTest - c) retainAll failed", col 93 .containsAll(myCollection)); 94 assertTrue("CollectionTest - d) retainAll failed", !col 95 .contains(new Integer(0))); 96 assertTrue("CollectionTest - e) retainAll failed", !col 97 .contains(new Integer(50))); 98 99 // clear 100 col.clear(); 101 assertTrue("CollectionTest - a) clear failed", col.isEmpty()); 102 assertTrue("CollectionTest - b) clear failed", !col 103 .contains(new Integer(101))); 104 105 } 106 107} 108