--- jsr166/src/test/tck/CopyOnWriteArraySetTest.java 2003/09/20 18:20:07 1.4 +++ jsr166/src/test/tck/CopyOnWriteArraySetTest.java 2009/11/16 04:57:10 1.9 @@ -1,8 +1,9 @@ /* - * Written by members of JCP JSR-166 Expert Group and released to the - * public domain. Use, modify, and redistribute this code in any way - * without acknowledgement. Other contributors include Andrew Wright, - * Jeffrey Hayes, Pat Fischer, Mike Judd. + * Written by Doug Lea with assistance from members of JCP JSR-166 + * Expert Group and released to the public domain, as explained at + * http://creativecommons.org/licenses/publicdomain + * Other contributors include Andrew Wright, Jeffrey Hayes, + * Pat Fisher, Mike Judd. */ import junit.framework.*; @@ -11,11 +12,9 @@ import java.util.concurrent.*; import java.io.*; public class CopyOnWriteArraySetTest extends JSR166TestCase { - public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run (suite()); } - public static Test suite() { return new TestSuite(CopyOnWriteArraySetTest.class); } @@ -23,7 +22,7 @@ public class CopyOnWriteArraySetTest ext static CopyOnWriteArraySet populatedSet(int n){ CopyOnWriteArraySet a = new CopyOnWriteArraySet(); assertTrue(a.isEmpty()); - for (int i = 0; i < n; ++i) + for (int i = 0; i < n; ++i) a.add(new Integer(i)); assertFalse(a.isEmpty()); assertEquals(n, a.size()); @@ -39,20 +38,20 @@ public class CopyOnWriteArraySetTest ext } /** - * Collection-constructed list holds all of its elements + * Collection-constructed set holds all of its elements */ public void testConstructor3() { Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE-1; ++i) ints[i] = new Integer(i); CopyOnWriteArraySet a = new CopyOnWriteArraySet(Arrays.asList(ints)); - for (int i = 0; i < SIZE; ++i) + for (int i = 0; i < SIZE; ++i) assertTrue(a.contains(ints[i])); } - + /** - * addAll correctly adds each element from the given collection + * addAll adds each element from the given collection */ public void testAddAll() { CopyOnWriteArraySet full = populatedSet(3); @@ -65,8 +64,8 @@ public class CopyOnWriteArraySetTest ext } /** - * addAllAbsent adds each element from the given collection that did not - * already exist in the List + * addAll adds each element from the given collection that did not + * already exist in the set */ public void testAddAll2() { CopyOnWriteArraySet full = populatedSet(3); @@ -79,7 +78,7 @@ public class CopyOnWriteArraySetTest ext } /** - * addIfAbsent will not add the element if it already exists in the list + * add will not add the element if it already exists in the set */ public void testAdd2() { CopyOnWriteArraySet full = populatedSet(3); @@ -88,8 +87,8 @@ public class CopyOnWriteArraySetTest ext } /** - * addIfAbsent correctly adds the element when it does not exist - * in the list + * add adds the element when it does not exist + * in the set */ public void testAdd3() { CopyOnWriteArraySet full = populatedSet(3); @@ -98,7 +97,7 @@ public class CopyOnWriteArraySetTest ext } /** - * clear correctly removes all elements from the list + * clear removes all elements from the set */ public void testClear() { CopyOnWriteArraySet full = populatedSet(3); @@ -107,7 +106,7 @@ public class CopyOnWriteArraySetTest ext } /** - * contains returns the correct values + * contains returns true for added elements */ public void testContains() { CopyOnWriteArraySet full = populatedSet(3); @@ -133,9 +132,9 @@ public class CopyOnWriteArraySetTest ext assertEquals(a.hashCode(), b.hashCode()); } - + /** - * containsAll returns the correct values + * containsAll returns true for collections with subset of elements */ public void testContainsAll() { CopyOnWriteArraySet full = populatedSet(3); @@ -148,7 +147,7 @@ public class CopyOnWriteArraySetTest ext } /** - * isEmpty returns the correct values + * isEmpty is true when empty, else false */ public void testIsEmpty() { CopyOnWriteArraySet empty = new CopyOnWriteArraySet(); @@ -158,13 +157,13 @@ public class CopyOnWriteArraySetTest ext } /** - * iterator() returns an iterator containing the elements of the list + * iterator() returns an iterator containing the elements of the set */ public void testIterator() { CopyOnWriteArraySet full = populatedSet(3); Iterator i = full.iterator(); int j; - for(j = 0; i.hasNext(); j++) + for (j = 0; i.hasNext(); j++) assertEquals(j, ((Integer)i.next()).intValue()); assertEquals(3, j); } @@ -192,11 +191,11 @@ public class CopyOnWriteArraySetTest ext for (int i = 0; i < 3; ++i) { assertTrue(s.indexOf(String.valueOf(i)) >= 0); } - } + } /** - * removeAll correctly removes all elements from the given collection + * removeAll removes all elements from the given collection */ public void testRemoveAll() { CopyOnWriteArraySet full = populatedSet(3); @@ -219,7 +218,7 @@ public class CopyOnWriteArraySetTest ext } /** - * size returns the correct values + * size returns the number of elements */ public void testSize() { CopyOnWriteArraySet empty = new CopyOnWriteArraySet(); @@ -229,7 +228,7 @@ public class CopyOnWriteArraySetTest ext } /** - * toArray returns an Object array containing all elements from the list + * toArray returns an Object array containing all elements from the set */ public void testToArray() { CopyOnWriteArraySet full = populatedSet(3); @@ -242,7 +241,7 @@ public class CopyOnWriteArraySetTest ext /** * toArray returns an Integer array containing all elements from - * the list + * the set */ public void testToArray2() { CopyOnWriteArraySet full = populatedSet(3); @@ -257,7 +256,7 @@ public class CopyOnWriteArraySetTest ext /** * toArray throws an ArrayStoreException when the given array can - * not store the objects inside the list + * not store the objects inside the set */ public void testToArray_ArrayStoreException() { try { @@ -266,11 +265,11 @@ public class CopyOnWriteArraySetTest ext c.add("asdadasd"); c.toArray(new Long[5]); shouldThrow(); - } catch(ArrayStoreException e){} + } catch (ArrayStoreException e){} } /** - * + * A deserialized serialized set is equal */ public void testSerialization() { CopyOnWriteArraySet q = populatedSet(SIZE); @@ -287,7 +286,7 @@ public class CopyOnWriteArraySetTest ext assertEquals(q.size(), r.size()); assertTrue(q.equals(r)); assertTrue(r.equals(q)); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); } }