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