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

Comparing jsr166/src/test/tck/ConcurrentHashMapTest.java (file contents):
Revision 1.6 by dl, Fri Nov 28 12:38:08 2003 UTC vs.
Revision 1.12 by dl, Fri May 20 14:31:06 2005 UTC

# Line 1 | Line 1
1   /*
2 < * Written by members of JCP JSR-166 Expert Group and released to the
3 < * public domain. Use, modify, and redistribute this code in any way
4 < * without acknowledgement. Other contributors include Andrew Wright,
5 < * Jeffrey Hayes, Pat Fischer, Mike Judd.
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
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9   import junit.framework.*;
# Line 80 | Line 81 | public class ConcurrentHashMapTest exten
81       */
82      public void testContainsValue() {
83          ConcurrentHashMap map = map5();
84 <        assertTrue(map.contains("A"));
85 <        assertFalse(map.contains("Z"));
84 >        assertTrue(map.containsValue("A"));
85 >        assertFalse(map.containsValue("Z"));
86      }
87  
88      /**
# Line 100 | Line 101 | public class ConcurrentHashMapTest exten
101      }
102  
103      /**
103     *   Clone creates an equal map
104     */
105    public void testClone() {
106        ConcurrentHashMap map = map5();
107        ConcurrentHashMap m2 = (ConcurrentHashMap)(map.clone());
108        assertEquals(map, m2);
109    }
110
111    /**
104       *  get returns the correct element at the given key,
105       *  or null if not present
106       */
# Line 210 | Line 202 | public class ConcurrentHashMapTest exten
202       */
203      public void testPutIfAbsent() {
204          ConcurrentHashMap map = map5();
205 <        map.putIfAbsent(new Integer(6), "Z");
206 <        assertTrue(map.containsKey(new Integer(6)));
205 >        map.putIfAbsent(six, "Z");
206 >        assertTrue(map.containsKey(six));
207      }
208  
209      /**
# Line 223 | Line 215 | public class ConcurrentHashMapTest exten
215      }
216  
217      /**
218 +     *   replace fails when the given key is not present
219 +     */
220 +    public void testReplace() {
221 +        ConcurrentHashMap map = map5();
222 +        assertNull(map.replace(six, "Z"));
223 +        assertFalse(map.containsKey(six));
224 +    }
225 +
226 +    /**
227 +     *   replace succeeds if the key is already present
228 +     */
229 +    public void testReplace2() {
230 +        ConcurrentHashMap map = map5();
231 +        assertNotNull(map.replace(one, "Z"));
232 +        assertEquals("Z", map.get(one));
233 +    }
234 +
235 +
236 +    /**
237 +     * replace value fails when the given key not mapped to expected value
238 +     */
239 +    public void testReplaceValue() {
240 +        ConcurrentHashMap map = map5();
241 +        assertEquals("A", map.get(one));
242 +        assertFalse(map.replace(one, "Z", "Z"));
243 +        assertEquals("A", map.get(one));
244 +    }
245 +
246 +    /**
247 +     * replace value succeeds when the given key mapped to expected value
248 +     */
249 +    public void testReplaceValue2() {
250 +        ConcurrentHashMap map = map5();
251 +        assertEquals("A", map.get(one));
252 +        assertTrue(map.replace(one, "A", "Z"));
253 +        assertEquals("Z", map.get(one));
254 +    }
255 +
256 +
257 +    /**
258       *   remove removes the correct key-value pair from the map
259       */
260      public void testRemove() {
# Line 377 | Line 409 | public class ConcurrentHashMapTest exten
409      }
410  
411      /**
412 +     * replace(null, x) throws NPE
413 +     */
414 +    public void testReplace_NullPointerException() {
415 +        try {
416 +            ConcurrentHashMap c = new ConcurrentHashMap(5);
417 +            c.replace(null, "whatever");
418 +            shouldThrow();
419 +        } catch(NullPointerException e){}
420 +    }
421 +
422 +    /**
423 +     * replace(null, x, y) throws NPE
424 +     */
425 +    public void testReplaceValue_NullPointerException() {
426 +        try {
427 +            ConcurrentHashMap c = new ConcurrentHashMap(5);
428 +            c.replace(null, one, "whatever");
429 +            shouldThrow();
430 +        } catch(NullPointerException e){}
431 +    }
432 +
433 +    /**
434       * putIfAbsent(x, null) throws NPE
435       */
436      public void testPutIfAbsent2_NullPointerException() {
# Line 389 | Line 443 | public class ConcurrentHashMapTest exten
443  
444  
445      /**
446 +     * replace(x, null) throws NPE
447 +     */
448 +    public void testReplace2_NullPointerException() {
449 +        try {
450 +            ConcurrentHashMap c = new ConcurrentHashMap(5);
451 +            c.replace("whatever", null);
452 +            shouldThrow();
453 +        } catch(NullPointerException e){}
454 +    }
455 +
456 +    /**
457 +     * replace(x, null, y) throws NPE
458 +     */
459 +    public void testReplaceValue2_NullPointerException() {
460 +        try {
461 +            ConcurrentHashMap c = new ConcurrentHashMap(5);
462 +            c.replace("whatever", null, "A");
463 +            shouldThrow();
464 +        } catch(NullPointerException e){}
465 +    }
466 +
467 +    /**
468 +     * replace(x, y, null) throws NPE
469 +     */
470 +    public void testReplaceValue3_NullPointerException() {
471 +        try {
472 +            ConcurrentHashMap c = new ConcurrentHashMap(5);
473 +            c.replace("whatever", one, null);
474 +            shouldThrow();
475 +        } catch(NullPointerException e){}
476 +    }
477 +
478 +
479 +    /**
480       * remove(null) throws NPE
481       */
482      public void testRemove1_NullPointerException() {
# Line 413 | Line 501 | public class ConcurrentHashMapTest exten
501      }
502  
503      /**
504 +     * remove(x, null) returns false
505 +     */
506 +    public void testRemove3() {
507 +        try {
508 +            ConcurrentHashMap c = new ConcurrentHashMap(5);
509 +            c.put("sadsdf", "asdads");
510 +            assertFalse(c.remove("sadsdf", null));
511 +        } catch(NullPointerException e){
512 +            fail();
513 +        }
514 +    }
515 +
516 +    /**
517       * A deserialized map equals original
518       */
519      public void testSerialization() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines