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 * java.util.Collection 25 */ 26public class Support_CollectionTest extends junit.framework.TestCase { 27 Collection<Integer> col; // must contain the Integers 0 to 99 28 29 public Support_CollectionTest(String p1) { 30 super(p1); 31 } 32 33 public Support_CollectionTest(String p1, Collection<Integer> c) { 34 super(p1); 35 col = c; 36 } 37 38 @Override 39 public void runTest() { 40 new Support_UnmodifiableCollectionTest("", col).runTest(); 41 42 // setup 43 Collection<Integer> myCollection = new TreeSet<Integer>(); 44 myCollection.add(new Integer(101)); 45 myCollection.add(new Integer(102)); 46 myCollection.add(new Integer(103)); 47 48 // add 49 assertTrue("CollectionTest - a) add did not work", col.add(new Integer( 50 101))); 51 assertTrue("CollectionTest - b) add did not work", col 52 .contains(new Integer(101))); 53 54 // remove 55 assertTrue("CollectionTest - a) remove did not work", col 56 .remove(new Integer(101))); 57 assertTrue("CollectionTest - b) remove did not work", !col 58 .contains(new Integer(101))); 59 60 // addAll 61 assertTrue("CollectionTest - a) addAll failed", col 62 .addAll(myCollection)); 63 assertTrue("CollectionTest - b) addAll failed", col 64 .containsAll(myCollection)); 65 66 // containsAll 67 assertTrue("CollectionTest - a) containsAll failed", col 68 .containsAll(myCollection)); 69 col.remove(new Integer(101)); 70 assertTrue("CollectionTest - b) containsAll failed", !col 71 .containsAll(myCollection)); 72 73 // removeAll 74 assertTrue("CollectionTest - a) removeAll failed", col 75 .removeAll(myCollection)); 76 assertTrue("CollectionTest - b) removeAll failed", !col 77 .removeAll(myCollection)); // should not change the colletion 78 // the 2nd time around 79 assertTrue("CollectionTest - c) removeAll failed", !col 80 .contains(new Integer(102))); 81 assertTrue("CollectionTest - d) removeAll failed", !col 82 .contains(new Integer(103))); 83 84 // retianAll 85 col.addAll(myCollection); 86 assertTrue("CollectionTest - a) retainAll failed", col 87 .retainAll(myCollection)); 88 assertTrue("CollectionTest - b) retainAll failed", !col 89 .retainAll(myCollection)); // should not change the colletion 90 // the 2nd time around 91 assertTrue("CollectionTest - c) retainAll failed", col 92 .containsAll(myCollection)); 93 assertTrue("CollectionTest - d) retainAll failed", !col 94 .contains(new Integer(0))); 95 assertTrue("CollectionTest - e) retainAll failed", !col 96 .contains(new Integer(50))); 97 98 // clear 99 col.clear(); 100 assertTrue("CollectionTest - a) clear failed", col.isEmpty()); 101 assertTrue("CollectionTest - b) clear failed", !col 102 .contains(new Integer(101))); 103 104 } 105 106} 107