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.22 by jsr166, Tue Nov 29 05:23:56 2011 UTC vs.
Revision 1.26 by jsr166, Tue Apr 2 22:18:26 2013 UTC

# Line 7 | Line 7
7   */
8  
9   import junit.framework.*;
10 + import java.util.ArrayList;
11   import java.util.Arrays;
12   import java.util.Collection;
13   import java.util.Collections;
14   import java.util.Iterator;
15 + import java.util.NoSuchElementException;
16   import java.util.Set;
17   import java.util.Vector;
18   import java.util.concurrent.CopyOnWriteArraySet;
# Line 168 | Line 170 | public class CopyOnWriteArraySetTest ext
170      }
171  
172      /**
173 <     * iterator() returns an iterator containing the elements of the set
173 >     * iterator() returns an iterator containing the elements of the
174 >     * set in insertion order
175       */
176      public void testIterator() {
177 <        CopyOnWriteArraySet full = populatedSet(3);
178 <        Iterator i = full.iterator();
179 <        int j;
180 <        for (j = 0; i.hasNext(); j++)
181 <            assertEquals(j, i.next());
182 <        assertEquals(3, j);
177 >        Collection empty = new CopyOnWriteArraySet();
178 >        assertFalse(empty.iterator().hasNext());
179 >        try {
180 >            empty.iterator().next();
181 >            shouldThrow();
182 >        } catch (NoSuchElementException success) {}
183 >
184 >        Integer[] elements = new Integer[SIZE];
185 >        for (int i = 0; i < SIZE; i++)
186 >            elements[i] = i;
187 >        Collections.shuffle(Arrays.asList(elements));
188 >        Collection<Integer> full = populatedSet(elements);
189 >
190 >        Iterator it = full.iterator();
191 >        for (int j = 0; j < SIZE; j++) {
192 >            assertTrue(it.hasNext());
193 >            assertEquals(elements[j], it.next());
194 >        }
195 >        assertFalse(it.hasNext());
196 >        try {
197 >            it.next();
198 >            shouldThrow();
199 >        } catch (NoSuchElementException success) {}
200      }
201  
202      /**
# Line 196 | Line 216 | public class CopyOnWriteArraySetTest ext
216       * toString holds toString of elements
217       */
218      public void testToString() {
219 +        assertEquals("[]", new CopyOnWriteArraySet().toString());
220          CopyOnWriteArraySet full = populatedSet(3);
221          String s = full.toString();
222 <        for (int i = 0; i < 3; ++i) {
222 >        for (int i = 0; i < 3; ++i)
223              assertTrue(s.contains(String.valueOf(i)));
224 <        }
224 >        assertEquals(new ArrayList(full).toString(),
225 >                     full.toString());
226      }
227  
228      /**
# Line 321 | Line 343 | public class CopyOnWriteArraySetTest ext
343  
344          assertTrue(x != y);
345          assertEquals(x.size(), y.size());
346 +        assertEquals(x.toString(), y.toString());
347 +        assertTrue(Arrays.equals(x.toArray(), y.toArray()));
348 +        assertEquals(x, y);
349 +        assertEquals(y, x);
350 +    }
351 +
352 +    /**
353 +     * addAll is idempotent
354 +     */
355 +    public void testAddAll_idempotent() throws Exception {
356 +        Set x = populatedSet(SIZE);
357 +        Set y = new CopyOnWriteArraySet(x);
358 +        y.addAll(x);
359          assertEquals(x, y);
360          assertEquals(y, x);
361      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines