11 |
|
|
12 |
|
public class ConcurrentSkipListMapTest extends JSR166TestCase { |
13 |
|
public static void main(String[] args) { |
14 |
< |
junit.textui.TestRunner.run (suite()); |
14 |
> |
junit.textui.TestRunner.run (suite()); |
15 |
|
} |
16 |
|
public static Test suite() { |
17 |
|
return new TestSuite(ConcurrentSkipListMapTest.class); |
20 |
|
/** |
21 |
|
* Create a map from Integers 1-5 to Strings "A"-"E". |
22 |
|
*/ |
23 |
< |
private static ConcurrentSkipListMap map5() { |
23 |
> |
private static ConcurrentSkipListMap map5() { |
24 |
|
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
25 |
|
assertTrue(map.isEmpty()); |
26 |
|
map.put(one, "A"); |
43 |
|
} |
44 |
|
|
45 |
|
/** |
46 |
< |
* |
46 |
> |
* |
47 |
|
*/ |
48 |
|
public void testConstructFromSorted() { |
49 |
|
ConcurrentSkipListMap map = map5(); |
276 |
|
Iterator it = s.iterator(); |
277 |
|
while (it.hasNext()) { |
278 |
|
Map.Entry e = (Map.Entry) it.next(); |
279 |
< |
assertTrue( |
279 |
> |
assertTrue( |
280 |
|
(e.getKey().equals(one) && e.getValue().equals("A")) || |
281 |
|
(e.getKey().equals(two) && e.getValue().equals("B")) || |
282 |
|
(e.getKey().equals(three) && e.getValue().equals("C")) || |
295 |
|
Iterator it = s.iterator(); |
296 |
|
while (it.hasNext()) { |
297 |
|
Map.Entry e = (Map.Entry) it.next(); |
298 |
< |
assertTrue( |
298 |
> |
assertTrue( |
299 |
|
(e.getKey().equals(one) && e.getValue().equals("A")) || |
300 |
|
(e.getKey().equals(two) && e.getValue().equals("B")) || |
301 |
|
(e.getKey().equals(three) && e.getValue().equals("C")) || |
517 |
|
try { |
518 |
|
e.setValue("X"); |
519 |
|
fail(); |
520 |
< |
} catch(UnsupportedOperationException success) {} |
520 |
> |
} catch (UnsupportedOperationException success) {} |
521 |
|
e = map.higherEntry(zero); |
522 |
|
assertEquals(one, e.getKey()); |
523 |
|
try { |
524 |
|
e.setValue("X"); |
525 |
|
fail(); |
526 |
< |
} catch(UnsupportedOperationException success) {} |
526 |
> |
} catch (UnsupportedOperationException success) {} |
527 |
|
e = map.floorEntry(one); |
528 |
|
assertEquals(one, e.getKey()); |
529 |
|
try { |
530 |
|
e.setValue("X"); |
531 |
|
fail(); |
532 |
< |
} catch(UnsupportedOperationException success) {} |
532 |
> |
} catch (UnsupportedOperationException success) {} |
533 |
|
e = map.ceilingEntry(five); |
534 |
|
assertEquals(five, e.getKey()); |
535 |
|
try { |
536 |
|
e.setValue("X"); |
537 |
|
fail(); |
538 |
< |
} catch(UnsupportedOperationException success) {} |
538 |
> |
} catch (UnsupportedOperationException success) {} |
539 |
|
} |
540 |
|
|
541 |
|
|
691 |
|
for (int i = 1; i <= 5; ++i) { |
692 |
|
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
693 |
|
} |
694 |
< |
} |
694 |
> |
} |
695 |
|
|
696 |
|
// Exception tests |
697 |
|
|
703 |
|
ConcurrentSkipListMap c = map5(); |
704 |
|
c.get(null); |
705 |
|
shouldThrow(); |
706 |
< |
} catch(NullPointerException e){} |
706 |
> |
} catch (NullPointerException e) {} |
707 |
|
} |
708 |
|
|
709 |
|
/** |
714 |
|
ConcurrentSkipListMap c = map5(); |
715 |
|
c.containsKey(null); |
716 |
|
shouldThrow(); |
717 |
< |
} catch(NullPointerException e){} |
717 |
> |
} catch (NullPointerException e) {} |
718 |
|
} |
719 |
|
|
720 |
|
/** |
725 |
|
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
726 |
|
c.containsValue(null); |
727 |
|
shouldThrow(); |
728 |
< |
} catch(NullPointerException e){} |
728 |
> |
} catch (NullPointerException e) {} |
729 |
|
} |
730 |
|
|
731 |
|
|
737 |
|
ConcurrentSkipListMap c = map5(); |
738 |
|
c.put(null, "whatever"); |
739 |
|
shouldThrow(); |
740 |
< |
} catch(NullPointerException e){} |
740 |
> |
} catch (NullPointerException e) {} |
741 |
|
} |
742 |
|
|
743 |
|
/** |
748 |
|
ConcurrentSkipListMap c = map5(); |
749 |
|
c.putIfAbsent(null, "whatever"); |
750 |
|
shouldThrow(); |
751 |
< |
} catch(NullPointerException e){} |
751 |
> |
} catch (NullPointerException e) {} |
752 |
|
} |
753 |
|
|
754 |
|
/** |
759 |
|
ConcurrentSkipListMap c = map5(); |
760 |
|
c.replace(null, "whatever"); |
761 |
|
shouldThrow(); |
762 |
< |
} catch(NullPointerException e){} |
762 |
> |
} catch (NullPointerException e) {} |
763 |
|
} |
764 |
|
|
765 |
|
/** |
770 |
|
ConcurrentSkipListMap c = map5(); |
771 |
|
c.replace(null, one, "whatever"); |
772 |
|
shouldThrow(); |
773 |
< |
} catch(NullPointerException e){} |
773 |
> |
} catch (NullPointerException e) {} |
774 |
|
} |
775 |
|
|
776 |
|
/** |
782 |
|
c.put("sadsdf", "asdads"); |
783 |
|
c.remove(null); |
784 |
|
shouldThrow(); |
785 |
< |
} catch(NullPointerException e){} |
785 |
> |
} catch (NullPointerException e) {} |
786 |
|
} |
787 |
|
|
788 |
|
/** |
794 |
|
c.put("sadsdf", "asdads"); |
795 |
|
c.remove(null, "whatever"); |
796 |
|
shouldThrow(); |
797 |
< |
} catch(NullPointerException e){} |
797 |
> |
} catch (NullPointerException e) {} |
798 |
|
} |
799 |
|
|
800 |
|
/** |
805 |
|
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
806 |
|
c.put("sadsdf", "asdads"); |
807 |
|
assertFalse(c.remove("sadsdf", null)); |
808 |
< |
} catch(NullPointerException e){ |
808 |
> |
} catch (NullPointerException e) { |
809 |
|
fail(); |
810 |
|
} |
811 |
|
} |
828 |
|
assertEquals(q.size(), r.size()); |
829 |
|
assertTrue(q.equals(r)); |
830 |
|
assertTrue(r.equals(q)); |
831 |
< |
} catch(Exception e){ |
831 |
> |
} catch (Exception e) { |
832 |
|
e.printStackTrace(); |
833 |
|
unexpectedException(); |
834 |
|
} |
863 |
|
k = (Integer)(r.next()); |
864 |
|
assertEquals(two, k); |
865 |
|
assertFalse(r.hasNext()); |
866 |
< |
|
866 |
> |
|
867 |
|
Iterator j = sm.keySet().iterator(); |
868 |
|
j.next(); |
869 |
|
j.remove(); |
897 |
|
k = (Integer)(r.next()); |
898 |
|
assertEquals(two, k); |
899 |
|
assertFalse(r.hasNext()); |
900 |
< |
|
900 |
> |
|
901 |
|
Iterator j = sm.keySet().iterator(); |
902 |
|
j.next(); |
903 |
|
j.remove(); |
1021 |
|
NavigableMap<Integer, Integer> result = null; |
1022 |
|
try { |
1023 |
|
result = (NavigableMap<Integer, Integer>) cl.newInstance(); |
1024 |
< |
} catch(Exception e) { |
1024 |
> |
} catch (Exception e) { |
1025 |
|
fail(); |
1026 |
|
} |
1027 |
|
assertEquals(result.size(), 0); |
1046 |
|
} |
1047 |
|
|
1048 |
|
// Remove a bunch of entries with iterator |
1049 |
< |
for(Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { |
1049 |
> |
for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { |
1050 |
|
if (rnd.nextBoolean()) { |
1051 |
|
bs.clear(it.next()); |
1052 |
|
it.remove(); |
1071 |
|
} |
1072 |
|
|
1073 |
|
// Remove a bunch of entries with iterator |
1074 |
< |
for(Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { |
1074 |
> |
for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { |
1075 |
|
if (rnd.nextBoolean()) { |
1076 |
|
bs.clear(it.next()); |
1077 |
|
it.remove(); |
1087 |
|
try { |
1088 |
|
map.put(key, 2 * key); |
1089 |
|
fail(); |
1090 |
< |
} catch(IllegalArgumentException e) { |
1090 |
> |
} catch (IllegalArgumentException e) { |
1091 |
|
// expected |
1092 |
|
} |
1093 |
|
} |
1285 |
|
try { |
1286 |
|
map.firstKey(); |
1287 |
|
fail(); |
1288 |
< |
} catch(NoSuchElementException e) { |
1288 |
> |
} catch (NoSuchElementException e) { |
1289 |
|
// expected |
1290 |
|
} |
1291 |
|
try { |
1292 |
|
map.lastKey(); |
1293 |
|
fail(); |
1294 |
< |
} catch(NoSuchElementException e) { |
1294 |
> |
} catch (NoSuchElementException e) { |
1295 |
|
// expected |
1296 |
|
} |
1297 |
|
} |
1307 |
|
static boolean eq(Integer i, int j) { |
1308 |
|
return i == null ? j == -1 : i == j; |
1309 |
|
} |
1310 |
< |
|
1310 |
> |
|
1311 |
|
} |