ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CopyOnWriteArraySetTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CopyOnWriteArraySetTest.java (file contents):
Revision 1.15 by jsr166, Wed Aug 25 00:07:03 2010 UTC vs.
Revision 1.19 by jsr166, Tue May 31 16:16:23 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,
6   * Pat Fisher, Mike Judd.
7   */
8  
9   import junit.framework.*;
10 < import java.util.*;
11 < import java.util.concurrent.*;
12 < import java.io.*;
10 > import java.util.Arrays;
11 > import java.util.Iterator;
12 > import java.util.Set;
13 > import java.util.Vector;
14 > import java.util.concurrent.CopyOnWriteArraySet;
15  
16   public class CopyOnWriteArraySetTest extends JSR166TestCase {
17      public static void main(String[] args) {
# Line 49 | Line 51 | public class CopyOnWriteArraySetTest ext
51              assertTrue(a.contains(ints[i]));
52      }
53  
52
54      /**
55 <     *  addAll adds each element from the given collection
55 >     * addAll adds each element from the given collection
56       */
57      public void testAddAll() {
58          CopyOnWriteArraySet full = populatedSet(3);
# Line 64 | Line 65 | public class CopyOnWriteArraySetTest ext
65      }
66  
67      /**
68 <     *  addAll adds each element from the given collection that did not
69 <     *  already exist in the set
68 >     * addAll adds each element from the given collection that did not
69 >     * already exist in the set
70       */
71      public void testAddAll2() {
72          CopyOnWriteArraySet full = populatedSet(3);
# Line 78 | Line 79 | public class CopyOnWriteArraySetTest ext
79      }
80  
81      /**
82 <     *  add will not add the element if it already exists in the set
82 >     * add will not add the element if it already exists in the set
83       */
84      public void testAdd2() {
85          CopyOnWriteArraySet full = populatedSet(3);
# Line 87 | Line 88 | public class CopyOnWriteArraySetTest ext
88      }
89  
90      /**
91 <     *  add  adds the element when it does not exist
91 <     *  in the set
91 >     * add adds the element when it does not exist in the set
92       */
93      public void testAdd3() {
94          CopyOnWriteArraySet full = populatedSet(3);
# Line 97 | Line 97 | public class CopyOnWriteArraySetTest ext
97      }
98  
99      /**
100 <     *  clear removes all elements from the set
100 >     * clear removes all elements from the set
101       */
102      public void testClear() {
103          CopyOnWriteArraySet full = populatedSet(3);
# Line 106 | Line 106 | public class CopyOnWriteArraySetTest ext
106      }
107  
108      /**
109 <     *   contains returns true for added elements
109 >     * contains returns true for added elements
110       */
111      public void testContains() {
112          CopyOnWriteArraySet full = populatedSet(3);
# Line 132 | Line 132 | public class CopyOnWriteArraySetTest ext
132          assertEquals(a.hashCode(), b.hashCode());
133      }
134  
135
135      /**
136 <     *  containsAll returns true for collections with subset of elements
136 >     * containsAll returns true for collections with subset of elements
137       */
138      public void testContainsAll() {
139          CopyOnWriteArraySet full = populatedSet(3);
# Line 147 | Line 146 | public class CopyOnWriteArraySetTest ext
146      }
147  
148      /**
149 <     *  isEmpty is true when empty, else false
149 >     * isEmpty is true when empty, else false
150       */
151      public void testIsEmpty() {
152          CopyOnWriteArraySet empty = new CopyOnWriteArraySet();
# Line 157 | Line 156 | public class CopyOnWriteArraySetTest ext
156      }
157  
158      /**
159 <     *  iterator() returns an iterator containing the elements of the set
159 >     * iterator() returns an iterator containing the elements of the set
160       */
161      public void testIterator() {
162          CopyOnWriteArraySet full = populatedSet(3);
# Line 188 | Line 187 | public class CopyOnWriteArraySetTest ext
187          CopyOnWriteArraySet full = populatedSet(3);
188          String s = full.toString();
189          for (int i = 0; i < 3; ++i) {
190 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
190 >            assertTrue(s.contains(String.valueOf(i)));
191          }
192      }
193  
195
194      /**
195 <     *  removeAll  removes all elements from the given collection
195 >     * removeAll removes all elements from the given collection
196       */
197      public void testRemoveAll() {
198          CopyOnWriteArraySet full = populatedSet(3);
# Line 205 | Line 203 | public class CopyOnWriteArraySetTest ext
203          assertEquals(1, full.size());
204      }
205  
208
206      /**
207       * remove removes an element
208       */
# Line 217 | Line 214 | public class CopyOnWriteArraySetTest ext
214      }
215  
216      /**
217 <     *  size returns the number of elements
217 >     * size returns the number of elements
218       */
219      public void testSize() {
220          CopyOnWriteArraySet empty = new CopyOnWriteArraySet();
# Line 227 | Line 224 | public class CopyOnWriteArraySetTest ext
224      }
225  
226      /**
227 <     *  toArray returns an Object array containing all elements from the set
227 >     * toArray returns an Object array containing all elements from the set
228       */
229      public void testToArray() {
230          CopyOnWriteArraySet full = populatedSet(3);
# Line 239 | Line 236 | public class CopyOnWriteArraySetTest ext
236      }
237  
238      /**
239 <     *  toArray returns an Integer array containing all elements from
240 <     *  the set
239 >     * toArray returns an Integer array containing all elements from
240 >     * the set
241       */
242      public void testToArray2() {
243          CopyOnWriteArraySet full = populatedSet(3);
# Line 252 | Line 249 | public class CopyOnWriteArraySetTest ext
249          assertEquals(2, (int) i[2]);
250      }
251  
255
252      /**
253 <     *  toArray throws an ArrayStoreException when the given array can
254 <     *  not store the objects inside the set
253 >     * toArray throws an ArrayStoreException when the given array can
254 >     * not store the objects inside the set
255       */
256      public void testToArray_ArrayStoreException() {
257          try {
# Line 271 | Line 267 | public class CopyOnWriteArraySetTest ext
267       * A deserialized serialized set is equal
268       */
269      public void testSerialization() throws Exception {
270 <        CopyOnWriteArraySet q = populatedSet(SIZE);
270 >        Set x = populatedSet(SIZE);
271 >        Set y = serialClone(x);
272  
273 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
274 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
275 <        out.writeObject(q);
276 <        out.close();
280 <
281 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
282 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
283 <        CopyOnWriteArraySet r = (CopyOnWriteArraySet)in.readObject();
284 <        assertEquals(q.size(), r.size());
285 <        assertTrue(q.equals(r));
286 <        assertTrue(r.equals(q));
273 >        assertTrue(x != y);
274 >        assertEquals(x.size(), y.size());
275 >        assertEquals(x, y);
276 >        assertEquals(y, x);
277      }
278  
279   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines