View Javadoc
1 /* 2 * Scope: a generic MVC framework. 3 * Copyright (c) 2000-2002, The Scope team 4 * All rights reserved. 5 * 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * Neither the name "Scope" nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 * 36 * $Id: TestWeakSet.java,v 1.4 2002/09/12 19:09:36 ludovicc Exp $ 37 */ 38 package test.util; 39 40 import java.util.*; 41 import junit.framework.TestCase; 42 43 import org.scopemvc.util.*; 44 45 /*** 46 * <P> 47 * 48 * </P> 49 * 50 * @author <A HREF="mailto:haruki_zaemon@users.sourceforge.net">Simon Harris</A> 51 * @created 05 September 2002 52 * @version $Revision: 1.4 $ 53 */ 54 public final class TestWeakSet extends TestCase { 55 56 /*** 57 * Constructor for the TestWeakSet object 58 * 59 * @param inName Name of the test 60 */ 61 public TestWeakSet(String inName) { 62 super(inName); 63 } 64 65 66 /*** 67 * A unit test for JUnit 68 */ 69 public void testEmpty() { 70 Set set = new WeakSet(); 71 assertTrue("New set not empty", set.isEmpty()); 72 } 73 74 /*** 75 * A unit test for JUnit 76 */ 77 public void testAddLots() { 78 Set set = new WeakSet(); 79 Integer[] refHolder = new Integer[20]; 80 for (int i = 0; i < 20; i++) { 81 refHolder[i] = new Integer(i); 82 set.add(refHolder[i]); 83 } 84 for (int i = 0; i < 20; i++) { 85 assertTrue("Entry not found: " + i, set.contains(new Integer(i))); 86 } 87 } 88 89 /*** 90 * A unit test for JUnit 91 */ 92 public void testAddRemove() { 93 Set set = new WeakSet(); 94 Integer[] refHolder = new Integer[20]; 95 for (int i = 0; i < 20; i++) { 96 refHolder[i] = new Integer(i); 97 set.add(refHolder[i]); 98 } 99 100 assertTrue("size not correct", set.size() == 20); 101 102 for (int i = 0; i < 20; i++) { 103 assertTrue("Entry not found" + i, set.remove(new Integer(i))); 104 } 105 assertTrue("remove failed", set.isEmpty()); 106 } 107 108 /*** 109 * A unit test for JUnit 110 */ 111 public void testClear() { 112 Set set = new WeakSet(); 113 Integer[] refHolder = new Integer[20]; 114 for (int i = 0; i < 20; i++) { 115 refHolder[i] = new Integer(i); 116 set.add(refHolder[i]); 117 } 118 set.clear(); 119 assertTrue("set not cleared", set.isEmpty()); 120 } 121 122 /*** 123 * A unit test for JUnit 124 */ 125 public void testGC() { 126 Set set = new WeakSet(); 127 List list = new LinkedList(); 128 129 Integer[] refHolder = new Integer[20]; 130 for (int i = 0; i < 10; i++) { 131 refHolder[i] = new Integer(i); 132 set.add(refHolder[i]); 133 } 134 135 for (int i = 10; i < 20; i++) { 136 Integer integer = new Integer(i); 137 set.add(integer); 138 list.add(integer); 139 } 140 assertTrue("size not correct before gc", set.size() == 20); 141 142 refHolder = null; 143 System.gc(); 144 assertTrue("size not correct after gc", set.size() == 10); 145 146 list.clear(); 147 System.gc(); 148 assertTrue("size not correct after gc", set.size() == 0); 149 } 150 151 /*** 152 * A unit test for JUnit 153 */ 154 public void testIterator() { 155 Set set = new WeakSet(); 156 List list = new LinkedList(); 157 for (int i = 0; i < 20; i++) { 158 Integer integer = new Integer(i); 159 set.add(integer); 160 list.add(integer); 161 } 162 163 int found = 0; 164 for (Iterator i = set.iterator(); i.hasNext(); ) { 165 Object o = i.next(); 166 assertTrue("entry was null", o != null); 167 found++; 168 list.remove(1); 169 System.gc(); 170 } 171 assertTrue("iterator incorrect", found == 11); 172 } 173 174 /*** 175 * The JUnit setup method 176 */ 177 protected void setUp() { } 178 }

This page was automatically generated by Maven