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.13 by dl, Sat May 28 14:09:27 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 158 | Line 150 | public class ConcurrentHashMapTest exten
150      }
151  
152      /**
153 +     *  keySet.toArray returns contains all keys
154 +     */
155 +    public void testKeySetToArray() {
156 +        ConcurrentHashMap map = map5();
157 +        Set s = map.keySet();
158 +        Object[] ar = s.toArray();
159 +        assertTrue(s.containsAll(Arrays.asList(ar)));
160 +        assertEquals(5, ar.length);
161 +        ar[0] = m10;
162 +        assertFalse(s.containsAll(Arrays.asList(ar)));
163 +    }
164 +
165 +    /**
166 +     *  Values.toArray contains all values
167 +     */
168 +    public void testValuesToArray() {
169 +        ConcurrentHashMap map = map5();
170 +        Collection v = map.values();
171 +        Object[] ar = v.toArray();
172 +        ArrayList s = new ArrayList(Arrays.asList(ar));
173 +        assertEquals(5, ar.length);
174 +        assertTrue(s.contains("A"));
175 +        assertTrue(s.contains("B"));
176 +        assertTrue(s.contains("C"));
177 +        assertTrue(s.contains("D"));
178 +        assertTrue(s.contains("E"));
179 +    }
180 +
181 +    /**
182 +     *  entrySet.toArray contains all entries
183 +     */
184 +    public void testEntrySetToArray() {
185 +        ConcurrentHashMap map = map5();
186 +        Set s = map.entrySet();
187 +        Object[] ar = s.toArray();
188 +        assertEquals(5, ar.length);
189 +        for (int i = 0; i < 5; ++i) {
190 +            assertTrue(map.containsKey(((Map.Entry)(ar[i])).getKey()));
191 +            assertTrue(map.containsValue(((Map.Entry)(ar[i])).getValue()));
192 +        }
193 +    }
194 +
195 +    /**
196       * values collection contains all values
197       */
198      public void testValues() {
# Line 210 | Line 245 | public class ConcurrentHashMapTest exten
245       */
246      public void testPutIfAbsent() {
247          ConcurrentHashMap map = map5();
248 <        map.putIfAbsent(new Integer(6), "Z");
249 <        assertTrue(map.containsKey(new Integer(6)));
248 >        map.putIfAbsent(six, "Z");
249 >        assertTrue(map.containsKey(six));
250      }
251  
252      /**
# Line 223 | Line 258 | public class ConcurrentHashMapTest exten
258      }
259  
260      /**
261 +     *   replace fails when the given key is not present
262 +     */
263 +    public void testReplace() {
264 +        ConcurrentHashMap map = map5();
265 +        assertNull(map.replace(six, "Z"));
266 +        assertFalse(map.containsKey(six));
267 +    }
268 +
269 +    /**
270 +     *   replace succeeds if the key is already present
271 +     */
272 +    public void testReplace2() {
273 +        ConcurrentHashMap map = map5();
274 +        assertNotNull(map.replace(one, "Z"));
275 +        assertEquals("Z", map.get(one));
276 +    }
277 +
278 +
279 +    /**
280 +     * replace value fails when the given key not mapped to expected value
281 +     */
282 +    public void testReplaceValue() {
283 +        ConcurrentHashMap map = map5();
284 +        assertEquals("A", map.get(one));
285 +        assertFalse(map.replace(one, "Z", "Z"));
286 +        assertEquals("A", map.get(one));
287 +    }
288 +
289 +    /**
290 +     * replace value succeeds when the given key mapped to expected value
291 +     */
292 +    public void testReplaceValue2() {
293 +        ConcurrentHashMap map = map5();
294 +        assertEquals("A", map.get(one));
295 +        assertTrue(map.replace(one, "A", "Z"));
296 +        assertEquals("Z", map.get(one));
297 +    }
298 +
299 +
300 +    /**
301       *   remove removes the correct key-value pair from the map
302       */
303      public void testRemove() {
# Line 377 | Line 452 | public class ConcurrentHashMapTest exten
452      }
453  
454      /**
455 +     * replace(null, x) throws NPE
456 +     */
457 +    public void testReplace_NullPointerException() {
458 +        try {
459 +            ConcurrentHashMap c = new ConcurrentHashMap(5);
460 +            c.replace(null, "whatever");
461 +            shouldThrow();
462 +        } catch(NullPointerException e){}
463 +    }
464 +
465 +    /**
466 +     * replace(null, x, y) throws NPE
467 +     */
468 +    public void testReplaceValue_NullPointerException() {
469 +        try {
470 +            ConcurrentHashMap c = new ConcurrentHashMap(5);
471 +            c.replace(null, one, "whatever");
472 +            shouldThrow();
473 +        } catch(NullPointerException e){}
474 +    }
475 +
476 +    /**
477       * putIfAbsent(x, null) throws NPE
478       */
479      public void testPutIfAbsent2_NullPointerException() {
# Line 389 | Line 486 | public class ConcurrentHashMapTest exten
486  
487  
488      /**
489 +     * replace(x, null) throws NPE
490 +     */
491 +    public void testReplace2_NullPointerException() {
492 +        try {
493 +            ConcurrentHashMap c = new ConcurrentHashMap(5);
494 +            c.replace("whatever", null);
495 +            shouldThrow();
496 +        } catch(NullPointerException e){}
497 +    }
498 +
499 +    /**
500 +     * replace(x, null, y) throws NPE
501 +     */
502 +    public void testReplaceValue2_NullPointerException() {
503 +        try {
504 +            ConcurrentHashMap c = new ConcurrentHashMap(5);
505 +            c.replace("whatever", null, "A");
506 +            shouldThrow();
507 +        } catch(NullPointerException e){}
508 +    }
509 +
510 +    /**
511 +     * replace(x, y, null) throws NPE
512 +     */
513 +    public void testReplaceValue3_NullPointerException() {
514 +        try {
515 +            ConcurrentHashMap c = new ConcurrentHashMap(5);
516 +            c.replace("whatever", one, null);
517 +            shouldThrow();
518 +        } catch(NullPointerException e){}
519 +    }
520 +
521 +
522 +    /**
523       * remove(null) throws NPE
524       */
525      public void testRemove1_NullPointerException() {
# Line 413 | Line 544 | public class ConcurrentHashMapTest exten
544      }
545  
546      /**
547 +     * remove(x, null) returns false
548 +     */
549 +    public void testRemove3() {
550 +        try {
551 +            ConcurrentHashMap c = new ConcurrentHashMap(5);
552 +            c.put("sadsdf", "asdads");
553 +            assertFalse(c.remove("sadsdf", null));
554 +        } catch(NullPointerException e){
555 +            fail();
556 +        }
557 +    }
558 +
559 +    /**
560       * A deserialized map equals original
561       */
562      public void testSerialization() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines