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.12 by dl, Sun Jul 21 22:24:18 2013 UTC vs.
Revision 1.17 by dl, Sun Dec 1 12:19:59 2013 UTC

# Line 6 | Line 6
6  
7   import junit.framework.*;
8   import java.util.*;
9 + import static java.util.Spliterator.*;
10   import java.util.function.*;
11   import java.util.concurrent.atomic.LongAdder;
12   import java.util.concurrent.ConcurrentHashMap;
# Line 54 | Line 55 | public class ConcurrentHashMap8Test exte
55      }
56  
57      /**
58 <     * computeIfAbsent does not replace  if the key is already present
58 >     * computeIfAbsent does not replace if the key is already present
59       */
60      public void testComputeIfAbsent2() {
61          ConcurrentHashMap map = map5();
# Line 71 | Line 72 | public class ConcurrentHashMap8Test exte
72      }
73  
74      /**
75 <     * computeIfPresent does not replace  if the key is already present
75 >     * computeIfPresent does not replace if the key is already present
76       */
77      public void testComputeIfPresent() {
78          ConcurrentHashMap map = map5();
# Line 88 | Line 89 | public class ConcurrentHashMap8Test exte
89      }
90  
91      /**
92 <     * compute does not replace  if the function returns null
92 >     * compute does not replace if the function returns null
93       */
94      public void testCompute() {
95          ConcurrentHashMap map = map5();
# Line 255 | Line 256 | public class ConcurrentHashMap8Test exte
256          assertTrue(full.contains(three));
257      }
258  
259 +    /**
260 +     * keySet.add throws UnsupportedOperationException if no default
261 +     * mapped value
262 +     */
263 +    public void testAdd4() {
264 +        Set full = map5().keySet();
265 +        try {
266 +            full.add(three);
267 +            shouldThrow();
268 +        } catch (UnsupportedOperationException e){}
269 +    }
270  
271 <      /**
272 <      * keySet.add throws UnsupportedOperationException if no default
273 <      * mapped value
274 <      */
275 <     public void testAdd4() {
276 <         Set full = map5().keySet();
277 <         try {
278 <             full.add(three);
279 <             shouldThrow();
280 <         } catch (UnsupportedOperationException e){}
281 <     }
282 <    
283 <     /**
284 <      * keySet.add throws NullPointerException if the specified key is
285 <      * null
286 <      */
287 <     public void testAdd5() {
288 <         Set full = populatedSet(3);
289 <         try {
290 <             full.add(null);
291 <             shouldThrow();
292 <         } catch (NullPointerException e){}
293 <     }
294 <    
295 <     /**
296 <      * KeySetView.getMappedValue returns the map's mapped value
297 <      */
298 <     public void testGetMappedValue() {
299 <         ConcurrentHashMap map = map5();
300 <         assertNull(map.keySet().getMappedValue());
301 <         try {
302 <             map.keySet(null);
303 <             shouldThrow();
304 <         } catch (NullPointerException e) {}
305 <         KeySetView set = map.keySet(one);
306 <         set.add(one);
307 <         set.add(six);
308 <         set.add(seven);
309 <         assertTrue(set.getMappedValue() == one);
310 <         assertTrue(map.get(one) != one);
311 <         assertTrue(map.get(six) == one);
312 <         assertTrue(map.get(seven) == one);
313 <     }
314 <    
315 <     /**
316 <      * KeySetView.spliterator returns spliterator over the elements in this set
317 <      */
318 <     public void testKeySetSpliterator() {
319 <         LongAdder adder = new LongAdder();
320 <         ConcurrentHashMap map = map5();
321 <         Set set = map.keySet();
322 <         Spliterator<Integer> sp = set.spliterator();
323 <         assertEquals(sp.estimateSize(), map.size());
324 <         Spliterator<Integer> sp2 = sp.trySplit();
325 <         sp.forEachRemaining((Integer x) -> adder.add(x.longValue()));
314 <         long v = adder.sumThenReset();
315 <         sp2.forEachRemaining((Integer x) -> adder.add(x.longValue()));
316 <         long v2 = adder.sum();
317 <         assertEquals(v + v2, 15);
318 <     }
319 <
271 >    /**
272 >     * keySet.add throws NullPointerException if the specified key is
273 >     * null
274 >     */
275 >    public void testAdd5() {
276 >        Set full = populatedSet(3);
277 >        try {
278 >            full.add(null);
279 >            shouldThrow();
280 >        } catch (NullPointerException e){}
281 >    }
282 >
283 >    /**
284 >     * KeySetView.getMappedValue returns the map's mapped value
285 >     */
286 >    public void testGetMappedValue() {
287 >        ConcurrentHashMap map = map5();
288 >        assertNull(map.keySet().getMappedValue());
289 >        try {
290 >            map.keySet(null);
291 >            shouldThrow();
292 >        } catch (NullPointerException e) {}
293 >        KeySetView set = map.keySet(one);
294 >        set.add(one);
295 >        set.add(six);
296 >        set.add(seven);
297 >        assertTrue(set.getMappedValue() == one);
298 >        assertTrue(map.get(one) != one);
299 >        assertTrue(map.get(six) == one);
300 >        assertTrue(map.get(seven) == one);
301 >    }
302 >
303 >    void checkSpliteratorCharacteristics(Spliterator<?> sp,
304 >                                         int requiredCharacteristics) {
305 >        assertEquals(requiredCharacteristics,
306 >                     requiredCharacteristics & sp.characteristics());
307 >    }
308 >
309 >    /**
310 >     * KeySetView.spliterator returns spliterator over the elements in this set
311 >     */
312 >    public void testKeySetSpliterator() {
313 >        LongAdder adder = new LongAdder();
314 >        ConcurrentHashMap map = map5();
315 >        Set set = map.keySet();
316 >        Spliterator<Integer> sp = set.spliterator();
317 >        checkSpliteratorCharacteristics(sp, CONCURRENT | DISTINCT | NONNULL);
318 >        assertEquals(sp.estimateSize(), map.size());
319 >        Spliterator<Integer> sp2 = sp.trySplit();
320 >        sp.forEachRemaining((Integer x) -> adder.add(x.longValue()));
321 >        long v = adder.sumThenReset();
322 >        sp2.forEachRemaining((Integer x) -> adder.add(x.longValue()));
323 >        long v2 = adder.sum();
324 >        assertEquals(v + v2, 15);
325 >    }
326  
327      /**
328       * keyset.clear removes all elements from the set
# Line 533 | Line 539 | public class ConcurrentHashMap8Test exte
539  
540          assertNotSame(x, y);
541          assertEquals(x.size(), y.size());
536        assertEquals(x.toString(), y.toString());
537        assertTrue(Arrays.equals(x.toArray(), y.toArray()));
542          assertEquals(x, y);
543          assertEquals(y, x);
544      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines