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

Comparing jsr166/src/test/tck/ConcurrentHashMap8Test.java (file contents):
Revision 1.18 by jsr166, Wed Dec 31 19:05:42 2014 UTC vs.
Revision 1.24 by jsr166, Fri Feb 27 21:03:10 2015 UTC

# Line 17 | Line 17 | import java.util.Map;
17   import java.util.NoSuchElementException;
18   import java.util.Set;
19   import java.util.Spliterator;
20 import java.util.Vector;
20   import java.util.concurrent.ConcurrentHashMap;
21   import java.util.concurrent.atomic.LongAdder;
22   import java.util.function.BiFunction;
# Line 165 | Line 164 | public class ConcurrentHashMap8Test exte
164          assertTrue(a.isEmpty());
165          for (int i = 0; i < n; i++)
166              a.add(i);
167 <        assertFalse(a.isEmpty());
167 >        assertEquals(n == 0, a.isEmpty());
168          assertEquals(n, a.size());
169          return a;
170      }
# Line 180 | Line 179 | public class ConcurrentHashMap8Test exte
179          return a;
180      }
181  
182 <    /*
182 >    /**
183       * replaceAll replaces all matching values.
184       */
185      public void testReplaceAll() {
186          ConcurrentHashMap<Integer, String> map = map5();
187 <        map.replaceAll((x, y) -> {return x > 3 ? "Z" : y;});
187 >        map.replaceAll((x, y) -> { return x > 3 ? "Z" : y; });
188          assertEquals("A", map.get(one));
189          assertEquals("B", map.get(two));
190          assertEquals("C", map.get(three));
# Line 223 | Line 222 | public class ConcurrentHashMap8Test exte
222          assertFalse(set2.contains(six));
223      }
224  
226
225      /**
226       * keySet.addAll adds each element from the given collection
227       */
228      public void testAddAll() {
229          Set full = populatedSet(3);
230 <        Vector v = new Vector();
231 <        v.add(three);
232 <        v.add(four);
235 <        v.add(five);
236 <        full.addAll(v);
230 >        assertTrue(full.addAll(Arrays.asList(three, four, five)));
231 >        assertEquals(6, full.size());
232 >        assertFalse(full.addAll(Arrays.asList(three, four, five)));
233          assertEquals(6, full.size());
234      }
235  
# Line 243 | Line 239 | public class ConcurrentHashMap8Test exte
239       */
240      public void testAddAll2() {
241          Set full = populatedSet(3);
242 <        Vector v = new Vector();
243 <        v.add(three);
244 <        v.add(four);
245 <        v.add(one); // will not add this element
250 <        full.addAll(v);
242 >        // "one" is duplicate and will not be added
243 >        assertTrue(full.addAll(Arrays.asList(three, four, one)));
244 >        assertEquals(5, full.size());
245 >        assertFalse(full.addAll(Arrays.asList(three, four, one)));
246          assertEquals(5, full.size());
247      }
248  
# Line 256 | Line 251 | public class ConcurrentHashMap8Test exte
251       */
252      public void testAdd2() {
253          Set full = populatedSet(3);
254 <        full.add(one);
254 >        assertFalse(full.add(one));
255          assertEquals(3, full.size());
256      }
257  
# Line 265 | Line 260 | public class ConcurrentHashMap8Test exte
260       */
261      public void testAdd3() {
262          Set full = populatedSet(3);
263 <        full.add(three);
263 >        assertTrue(full.add(three));
264 >        assertTrue(full.contains(three));
265 >        assertFalse(full.add(three));
266          assertTrue(full.contains(three));
267      }
268  
# Line 377 | Line 374 | public class ConcurrentHashMap8Test exte
374       * KeySet.containsAll returns true for collections with subset of elements
375       */
376      public void testContainsAll() {
377 <        Set full = populatedSet(3);
378 <        Vector v = new Vector();
379 <        v.add(one);
380 <        v.add(two);
381 <        assertTrue(full.containsAll(v));
382 <        v.add(six);
386 <        assertFalse(full.containsAll(v));
377 >        Collection full = populatedSet(3);
378 >        assertTrue(full.containsAll(Arrays.asList()));
379 >        assertTrue(full.containsAll(Arrays.asList(one)));
380 >        assertTrue(full.containsAll(Arrays.asList(one, two)));
381 >        assertFalse(full.containsAll(Arrays.asList(one, two, six)));
382 >        assertFalse(full.containsAll(Arrays.asList(six)));
383      }
384  
385      /**
386       * KeySet.isEmpty is true when empty, else false
387       */
388      public void testIsEmpty() {
389 <        Set empty = ConcurrentHashMap.newKeySet();
390 <        Set full = populatedSet(3);
395 <        assertTrue(empty.isEmpty());
396 <        assertFalse(full.isEmpty());
389 >        assertTrue(populatedSet(0).isEmpty());
390 >        assertFalse(populatedSet(3).isEmpty());
391      }
392  
393      /**
# Line 420 | Line 414 | public class ConcurrentHashMap8Test exte
414              assertTrue(it.hasNext());
415              it.next();
416          }
417 <        assertFalse(it.hasNext());
418 <        try {
419 <            it.next();
420 <            shouldThrow();
421 <        } catch (NoSuchElementException success) {}
417 >        assertIteratorExhausted(it);
418 >    }
419 >
420 >    /**
421 >     * iterator of empty collections has no elements
422 >     */
423 >    public void testEmptyIterator() {
424 >        assertIteratorExhausted(ConcurrentHashMap.newKeySet().iterator());
425 >        assertIteratorExhausted(new ConcurrentHashMap().entrySet().iterator());
426 >        assertIteratorExhausted(new ConcurrentHashMap().values().iterator());
427 >        assertIteratorExhausted(new ConcurrentHashMap().keySet().iterator());
428      }
429  
430      /**
# Line 458 | Line 458 | public class ConcurrentHashMap8Test exte
458       */
459      public void testRemoveAll() {
460          Set full = populatedSet(3);
461 <        Vector v = new Vector();
462 <        v.add(one);
463 <        v.add(two);
464 <        full.removeAll(v);
461 >        assertTrue(full.removeAll(Arrays.asList(one, two)));
462 >        assertEquals(1, full.size());
463 >        assertFalse(full.removeAll(Arrays.asList(one, two)));
464          assertEquals(1, full.size());
465      }
466  
# Line 1003 | Line 1002 | public class ConcurrentHashMap8Test exte
1002      public void testSearchValuesSequentially() {
1003          ConcurrentHashMap<Long, Long> m = longMap();
1004          Long r;
1005 <        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
1005 >        r = m.searchValues(Long.MAX_VALUE,
1006 >            (Long x) -> (x.longValue() == (long)(SIZE/2)) ? x : null);
1007          assertEquals((long)r, (long)(SIZE/2));
1008 <        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
1008 >        r = m.searchValues(Long.MAX_VALUE,
1009 >            (Long x) -> (x.longValue() < 0L) ? x : null);
1010          assertNull(r);
1011      }
1012  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines