Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   package org.mapdb;/*
   /*
    * Written by Doug Lea with assistance from members of JCP JSR-166
    * Expert Group and released to the public domain, as explained at
    * http://creativecommons.org/publicdomain/zero/1.0/
    */
   
   import junit.framework.Test;
  
  import java.util.*;
  
  public class BTreeMapTest5 extends JSR166TestCase {
      public static void main(String[] args) {
          junit.textui.TestRunner.run(suite());
      }
      public static Test suite() {
          return new TestSuite(BTreeMapTest5.class);
      }

    
Returns a new map from Integers 1-5 to Strings "A"-"E".
  
      private static ConcurrentNavigableMap map5() {
          ConcurrentNavigableMap map = DBMaker.newMemoryDB().make().createTreeMap("test").make();
          assertTrue(map.isEmpty());
          map.put("Z");
          map.put("A");
          map.put("E");
          map.put("C");
          map.put("B");
          map.put("D");
          map.put("F");
          assertFalse(map.isEmpty());
          assertEquals(7, map.size());
          return map.subMap(truefalse);
      }

    
Returns a new map from Integers -5 to -1 to Strings "A"-"E".
  
      private static ConcurrentNavigableMap dmap5() {
          ConcurrentNavigableMap map = DBMaker.newMemoryDB().make().createTreeMap("test").make();
          assertTrue(map.isEmpty());
          map.put("A");
          map.put("E");
          map.put("C");
          map.put("B");
          map.put("D");
          assertFalse(map.isEmpty());
          assertEquals(5, map.size());
          return map.descendingMap();
      }
  
      private static ConcurrentNavigableMap map0() {
          ConcurrentNavigableMap map = DBMaker.newMemoryDB().make().createTreeMap("test").make();
          assertTrue(map.isEmpty());
          return map.tailMap(true);
      }
  
      private static ConcurrentNavigableMap dmap0() {
          ConcurrentNavigableMap map = DBMaker.newMemoryDB().make().createTreeMap("test").make();
          assertTrue(map.isEmpty());
          return map;
      }

    
clear removes all pairs
  
      public void testClear() {
          ConcurrentNavigableMap map = map5();
          map.clear();
          assertEquals(0, map.size());
      }

    
Maps with same contents are equal
  
      public void testEquals() {
          ConcurrentNavigableMap map1 = map5();
          ConcurrentNavigableMap map2 = map5();
          assertEquals(map1map2);
          assertEquals(map2map1);
          map1.clear();
          assertFalse(map1.equals(map2));
          assertFalse(map2.equals(map1));
      }

    
containsKey returns true for contained key
  
      public void testContainsKey() {
          ConcurrentNavigableMap map = map5();
          assertTrue(map.containsKey());
          assertFalse(map.containsKey());
      }

    
containsValue returns true for held values
 
     public void testContainsValue() {
         ConcurrentNavigableMap map = map5();
         assertTrue(map.containsValue("A"));
         assertFalse(map.containsValue("Z"));
     }

    
get returns the correct element at the given key, or null if not present
 
     public void testGet() {
         ConcurrentNavigableMap map = map5();
         assertEquals("A", (String)map.get());
         ConcurrentNavigableMap empty = map0();
         assertNull(empty.get());
     }

    
isEmpty is true of empty map and false for non-empty
 
     public void testIsEmpty() {
         ConcurrentNavigableMap empty = map0();
         ConcurrentNavigableMap map = map5();
         assertTrue(empty.isEmpty());
         assertFalse(map.isEmpty());
     }

    
firstKey returns first key
 
     public void testFirstKey() {
         ConcurrentNavigableMap map = map5();
         assertEquals(map.firstKey());
     }

    
lastKey returns last key
 
     public void testLastKey() {
         ConcurrentNavigableMap map = map5();
         assertEquals(map.lastKey());
     }

    
keySet returns a Set containing all the keys
 
     public void testKeySet() {
         ConcurrentNavigableMap map = map5();
         Set s = map.keySet();
         assertEquals(5, s.size());
         assertTrue(s.contains());
         assertTrue(s.contains());
         assertTrue(s.contains());
         assertTrue(s.contains());
         assertTrue(s.contains());
     }

    
keySet is ordered
 
     public void testKeySetOrder() {
         ConcurrentNavigableMap map = map5();
         Set s = map.keySet();
         Iterator i = s.iterator();
         Integer last = (Integer)i.next();
         assertEquals(last);
         while (i.hasNext()) {
             Integer k = (Integer)i.next();
             assertTrue(last.compareTo(k) < 0);
             last = k;
         }
     }

    
values collection contains all values
 
     public void testValues() {
         ConcurrentNavigableMap map = map5();
         Collection s = map.values();
         assertEquals(5, s.size());
         assertTrue(s.contains("A"));
         assertTrue(s.contains("B"));
         assertTrue(s.contains("C"));
         assertTrue(s.contains("D"));
         assertTrue(s.contains("E"));
     }

    
keySet.toArray returns contains all keys
 
     public void testKeySetToArray() {
         ConcurrentNavigableMap map = map5();
         Set s = map.keySet();
         Object[] ar = s.toArray();
         assertTrue(s.containsAll(Arrays.asList(ar)));
         assertEquals(5, ar.length);
         ar[0] = ;
         assertFalse(s.containsAll(Arrays.asList(ar)));
     }

    
descendingkeySet.toArray returns contains all keys
 
     public void testDescendingKeySetToArray() {
         ConcurrentNavigableMap map = map5();
         Set s = map.descendingKeySet();
         Object[] ar = s.toArray();
         assertEquals(5, ar.length);
         assertTrue(s.containsAll(Arrays.asList(ar)));
         ar[0] = ;
         assertFalse(s.containsAll(Arrays.asList(ar)));
     }

    
Values.toArray contains all values
 
     public void testValuesToArray() {
         ConcurrentNavigableMap map = map5();
         Collection v = map.values();
         Object[] ar = v.toArray();
         ArrayList s = new ArrayList(Arrays.asList(ar));
         assertEquals(5, ar.length);
         assertTrue(s.contains("A"));
         assertTrue(s.contains("B"));
         assertTrue(s.contains("C"));
         assertTrue(s.contains("D"));
         assertTrue(s.contains("E"));
     }

    
entrySet contains all pairs
 
     public void testEntrySet() {
         ConcurrentNavigableMap map = map5();
         Set s = map.entrySet();
         assertEquals(5, s.size());
         Iterator it = s.iterator();
         while (it.hasNext()) {
             Map.Entry e = (Map.Entryit.next();
             assertTrue(
                     (e.getKey().equals() && e.getValue().equals("A")) ||
                             (e.getKey().equals() && e.getValue().equals("B")) ||
                             (e.getKey().equals() && e.getValue().equals("C")) ||
                             (e.getKey().equals() && e.getValue().equals("D")) ||
                             (e.getKey().equals() && e.getValue().equals("E")));
         }
     }

    
putAll adds all key-value pairs from the given map
 
     public void testPutAll() {
         ConcurrentNavigableMap empty = map0();
         ConcurrentNavigableMap map = map5();
         empty.putAll(map);
         assertEquals(5, empty.size());
         assertTrue(empty.containsKey());
         assertTrue(empty.containsKey());
         assertTrue(empty.containsKey());
         assertTrue(empty.containsKey());
         assertTrue(empty.containsKey());
     }

    
putIfAbsent works when the given key is not present
 
     public void testPutIfAbsent() {
         ConcurrentNavigableMap map = map5();
         map.putIfAbsent("Z");
         assertTrue(map.containsKey());
     }

    
putIfAbsent does not add the pair if the key is already present
 
     public void testPutIfAbsent2() {
         ConcurrentNavigableMap map = map5();
         assertEquals("A"map.putIfAbsent("Z"));
     }

    
replace fails when the given key is not present
 
     public void testReplace() {
         ConcurrentNavigableMap map = map5();
         assertNull(map.replace("Z"));
         assertFalse(map.containsKey());
     }

    
replace succeeds if the key is already present
 
     public void testReplace2() {
         ConcurrentNavigableMap map = map5();
         assertNotNull(map.replace("Z"));
         assertEquals("Z"map.get());
     }

    
replace value fails when the given key not mapped to expected value
 
     public void testReplaceValue() {
         ConcurrentNavigableMap map = map5();
         assertEquals("A"map.get());
         assertFalse(map.replace("Z""Z"));
         assertEquals("A"map.get());
     }

    
replace value succeeds when the given key mapped to expected value
 
     public void testReplaceValue2() {
         ConcurrentNavigableMap map = map5();
         assertEquals("A"map.get());
         assertTrue(map.replace("A""Z"));
         assertEquals("Z"map.get());
     }

    
remove removes the correct key-value pair from the map
 
     public void testRemove() {
         ConcurrentNavigableMap map = map5();
         map.remove();
         assertEquals(4, map.size());
         assertFalse(map.containsKey());
     }

    
remove(key,value) removes only if pair present
 
     public void testRemove2() {
         ConcurrentNavigableMap map = map5();
         assertTrue(map.containsKey());
         assertEquals("E"map.get());
         map.remove("E");
         assertEquals(4, map.size());
         assertFalse(map.containsKey());
         map.remove("A");
         assertEquals(4, map.size());
         assertTrue(map.containsKey());
     }

    
lowerEntry returns preceding entry.
 
     public void testLowerEntry() {
         ConcurrentNavigableMap map = map5();
         Map.Entry e1 = map.lowerEntry();
         assertEquals(e1.getKey());
 
         Map.Entry e2 = map.lowerEntry();
         assertEquals(e2.getKey());
 
         Map.Entry e3 = map.lowerEntry();
         assertNull(e3);
 
         Map.Entry e4 = map.lowerEntry();
         assertNull(e4);
     }

    
higherEntry returns next entry.
 
     public void testHigherEntry() {
         ConcurrentNavigableMap map = map5();
         Map.Entry e1 = map.higherEntry();
         assertEquals(e1.getKey());
 
         Map.Entry e2 = map.higherEntry();
         assertEquals(e2.getKey());
 
         Map.Entry e3 = map.higherEntry();
         assertNull(e3);
 
         Map.Entry e4 = map.higherEntry();
         assertNull(e4);
     }

    
floorEntry returns preceding entry.
 
     public void testFloorEntry() {
         ConcurrentNavigableMap map = map5();
         Map.Entry e1 = map.floorEntry();
         assertEquals(e1.getKey());
 
         Map.Entry e2 = map.floorEntry();
         assertEquals(e2.getKey());
 
         Map.Entry e3 = map.floorEntry();
         assertEquals(e3.getKey());
 
         Map.Entry e4 = map.floorEntry();
         assertNull(e4);
     }

    
ceilingEntry returns next entry.
 
     public void testCeilingEntry() {
         ConcurrentNavigableMap map = map5();
         Map.Entry e1 = map.ceilingEntry();
         assertEquals(e1.getKey());
 
         Map.Entry e2 = map.ceilingEntry();
         assertEquals(e2.getKey());
 
         Map.Entry e3 = map.ceilingEntry();
         assertEquals(e3.getKey());
 
         Map.Entry e4 = map.ceilingEntry();
         assertNull(e4);
     }

    
pollFirstEntry returns entries in order
 
     public void testPollFirstEntry() {
         ConcurrentNavigableMap map = map5();
         Map.Entry e = map.pollFirstEntry();
         assertEquals(e.getKey());
         assertEquals("A"e.getValue());
         e = map.pollFirstEntry();
         assertEquals(e.getKey());
         map.put("A");
         e = map.pollFirstEntry();
         assertEquals(e.getKey());
         assertEquals("A"e.getValue());
         e = map.pollFirstEntry();
         assertEquals(e.getKey());
         map.remove();
         e = map.pollFirstEntry();
         assertEquals(e.getKey());
         try {
             e.setValue("A");
             shouldThrow();
         } catch (UnsupportedOperationException success) {}
         e = map.pollFirstEntry();
         assertNull(e);
     }

    
pollLastEntry returns entries in order
 
     public void testPollLastEntry() {
         ConcurrentNavigableMap map = map5();
         Map.Entry e = map.pollLastEntry();
         assertEquals(e.getKey());
         assertEquals("E"e.getValue());
         e = map.pollLastEntry();
         assertEquals(e.getKey());
         map.put("E");
         e = map.pollLastEntry();
         assertEquals(e.getKey());
         assertEquals("E"e.getValue());
         e = map.pollLastEntry();
         assertEquals(e.getKey());
         map.remove();
         e = map.pollLastEntry();
         assertEquals(e.getKey());
         try {
             e.setValue("E");
             shouldThrow();
         } catch (UnsupportedOperationException success) {}
         e = map.pollLastEntry();
         assertNull(e);
     }

    
size returns the correct values
 
     public void testSize() {
         ConcurrentNavigableMap map = map5();
         ConcurrentNavigableMap empty = map0();
         assertEquals(0, empty.size());
         assertEquals(5, map.size());
     }

    
toString contains toString of elements
 
     public void testToString() {
         ConcurrentNavigableMap map = map5();
         String s = map.toString();
         for (int i = 1; i <= 5; ++i) {
             assertTrue(s.contains(String.valueOf(i)));
         }
     }
 
     // Exception tests
 
    
get(null) of nonempty map throws NPE
 
     public void testGet_NullPointerException() {
         try {
             ConcurrentNavigableMap c = map5();
             c.get(null);
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
containsKey(null) of nonempty map throws NPE
 
     public void testContainsKey_NullPointerException() {
         try {
             ConcurrentNavigableMap c = map5();
             c.containsKey(null);
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
containsValue(null) throws NPE
 
     public void testContainsValue_NullPointerException() {
         try {
             ConcurrentNavigableMap c = map0();
             c.containsValue(null);
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
put(null,x) throws NPE
 
     public void testPut1_NullPointerException() {
         try {
             ConcurrentNavigableMap c = map5();
             c.put(null"whatever");
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
putIfAbsent(null, x) throws NPE
 
     public void testPutIfAbsent1_NullPointerException() {
         try {
             ConcurrentNavigableMap c = map5();
             c.putIfAbsent(null"whatever");
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
replace(null, x) throws NPE
 
     public void testReplace_NullPointerException() {
         try {
             ConcurrentNavigableMap c = map5();
             c.replace(null"whatever");
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
replace(null, x, y) throws NPE
 
     public void testReplaceValue_NullPointerException() {
         try {
             ConcurrentNavigableMap c = map5();
             c.replace(null"whatever");
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
remove(null) throws NPE
 
     public void testRemove1_NullPointerException() {
         try {
             ConcurrentNavigableMap c = map5();
             c.remove(null);
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
remove(null, x) throws NPE
 
     public void testRemove2_NullPointerException() {
         try {
             ConcurrentNavigableMap c = map5();
             c.remove(null"whatever");
             shouldThrow();
         } catch (NullPointerException success) {}
     }
 
 //    /**
 //     * A deserialized map equals original
 //     */
 //    public void testSerialization() throws Exception {
 //        NavigableMap x = map5();
 //        NavigableMap y = serialClone(x);
 //
 //        assertNotSame(x, y);
 //        assertEquals(x.size(), y.size());
 //        assertEquals(x.toString(), y.toString());
 //        assertEquals(x, y);
 //        assertEquals(y, x);
 //    }
 
    
subMap returns map with keys in requested range
 
     public void testSubMapContents() {
         ConcurrentNavigableMap map = map5();
         SortedMap sm = map.subMap();
         assertEquals(sm.firstKey());
         assertEquals(sm.lastKey());
         assertEquals(2, sm.size());
         assertFalse(sm.containsKey());
         assertTrue(sm.containsKey());
         assertTrue(sm.containsKey());
         assertFalse(sm.containsKey());
         assertFalse(sm.containsKey());
         Iterator i = sm.keySet().iterator();
         Object k;
         k = (Integer)(i.next());
         assertEquals(k);
         k = (Integer)(i.next());
         assertEquals(k);
         assertFalse(i.hasNext());
         Iterator j = sm.keySet().iterator();
         j.next();
         j.remove();
         assertFalse(map.containsKey());
         assertEquals(4, map.size());
         assertEquals(1, sm.size());
         assertEquals(sm.firstKey());
         assertEquals(sm.lastKey());
         assertEquals("C"sm.remove());
         assertTrue(sm.isEmpty());
         assertEquals(3, map.size());
     }
 
     public void testSubMapContents2() {
         ConcurrentNavigableMap map = map5();
         SortedMap sm = map.subMap();
         assertEquals(1, sm.size());
         assertEquals(sm.firstKey());
         assertEquals(sm.lastKey());
         assertFalse(sm.containsKey());
         assertTrue(sm.containsKey());
         assertFalse(sm.containsKey());
         assertFalse(sm.containsKey());
         assertFalse(sm.containsKey());
         Iterator i = sm.keySet().iterator();
         Object k;
         k = (Integer)(i.next());
         assertEquals(k);
         assertFalse(i.hasNext());
         Iterator j = sm.keySet().iterator();
         j.next();
         j.remove();
         assertFalse(map.containsKey());
         assertEquals(4, map.size());
         assertEquals(0, sm.size());
         assertTrue(sm.isEmpty());
         assertSame(sm.remove(), null);
         assertEquals(4, map.size());
     }

    
headMap returns map with keys in requested range
 
     public void testHeadMapContents() {
         ConcurrentNavigableMap map = map5();
         SortedMap sm = map.headMap();
         assertTrue(sm.containsKey());
         assertTrue(sm.containsKey());
         assertTrue(sm.containsKey());
         assertFalse(sm.containsKey());
         assertFalse(sm.containsKey());
         Iterator i = sm.keySet().iterator();
         Object k;
         k = (Integer)(i.next());
         assertEquals(k);
         k = (Integer)(i.next());
         assertEquals(k);
         k = (Integer)(i.next());
         assertEquals(k);
         assertFalse(i.hasNext());
         sm.clear();
         assertTrue(sm.isEmpty());
         assertEquals(2, map.size());
         assertEquals(map.firstKey());
     }

    
headMap returns map with keys in requested range
 
     public void testTailMapContents() {
         ConcurrentNavigableMap map = map5();
         SortedMap sm = map.tailMap();
         assertFalse(sm.containsKey());
         assertTrue(sm.containsKey());
         assertTrue(sm.containsKey());
         assertTrue(sm.containsKey());
         assertTrue(sm.containsKey());
         Iterator i = sm.keySet().iterator();
         Object k;
         k = (Integer)(i.next());
         assertEquals(k);
         k = (Integer)(i.next());
         assertEquals(k);
         k = (Integer)(i.next());
         assertEquals(k);
         k = (Integer)(i.next());
         assertEquals(k);
         assertFalse(i.hasNext());
 
         Iterator ei = sm.entrySet().iterator();
         Map.Entry e;
         e = (Map.Entry)(ei.next());
         assertEquals(e.getKey());
         assertEquals("B"e.getValue());
         e = (Map.Entry)(ei.next());
         assertEquals(e.getKey());
         assertEquals("C"e.getValue());
         e = (Map.Entry)(ei.next());
         assertEquals(e.getKey());
         assertEquals("D"e.getValue());
         e = (Map.Entry)(ei.next());
         assertEquals(e.getKey());
         assertEquals("E"e.getValue());
         assertFalse(i.hasNext());
 
         SortedMap ssm = sm.tailMap();
         assertEquals(ssm.firstKey());
         assertEquals(ssm.lastKey());
         assertEquals("D"ssm.remove());
         assertEquals(1, ssm.size());
         assertEquals(3, sm.size());
         assertEquals(4, map.size());
     }

    
clear removes all pairs
 
     public void testDescendingClear() {
         ConcurrentNavigableMap map = dmap5();
         map.clear();
         assertEquals(0, map.size());
     }

    
Maps with same contents are equal
 
     public void testDescendingEquals() {
         ConcurrentNavigableMap map1 = dmap5();
         ConcurrentNavigableMap map2 = dmap5();
         assertEquals(map1map2);
         assertEquals(map2map1);
         map1.clear();
         assertFalse(map1.equals(map2));
         assertFalse(map2.equals(map1));
     }

    
containsKey returns true for contained key
 
     public void testDescendingContainsKey() {
         ConcurrentNavigableMap map = dmap5();
         assertTrue(map.containsKey());
         assertFalse(map.containsKey());
     }

    
containsValue returns true for held values
 
     public void testDescendingContainsValue() {
         ConcurrentNavigableMap map = dmap5();
         assertTrue(map.containsValue("A"));
         assertFalse(map.containsValue("Z"));
     }

    
get returns the correct element at the given key, or null if not present
 
     public void testDescendingGet() {
         ConcurrentNavigableMap map = dmap5();
         assertEquals("A", (String)map.get());
         ConcurrentNavigableMap empty = dmap0();
         assertNull(empty.get());
     }

    
isEmpty is true of empty map and false for non-empty
 
     public void testDescendingIsEmpty() {
         ConcurrentNavigableMap empty = dmap0();
         ConcurrentNavigableMap map = dmap5();
         assertTrue(empty.isEmpty());
         assertFalse(map.isEmpty());
     }

    
firstKey returns first key
 
     public void testDescendingFirstKey() {
         ConcurrentNavigableMap map = dmap5();
         assertEquals(map.firstKey());
     }

    
lastKey returns last key
 
     public void testDescendingLastKey() {
         ConcurrentNavigableMap map = dmap5();
         assertEquals(map.lastKey());
     }

    
keySet returns a Set containing all the keys
 
     public void testDescendingKeySet() {
         ConcurrentNavigableMap map = dmap5();
         Set s = map.keySet();
         assertEquals(5, s.size());
         assertTrue(s.contains());
         assertTrue(s.contains());
         assertTrue(s.contains());
         assertTrue(s.contains());
         assertTrue(s.contains());
     }

    
keySet is ordered
 
     public void testDescendingKeySetOrder() {
         ConcurrentNavigableMap map = dmap5();
         Set s = map.keySet();
         Iterator i = s.iterator();
         Integer last = (Integer)i.next();
         assertEquals(last);
         while (i.hasNext()) {
             Integer k = (Integer)i.next();
             assertTrue(last.compareTo(k) > 0);
             last = k;
         }
     }

    
values collection contains all values
 
     public void testDescendingValues() {
         ConcurrentNavigableMap map = dmap5();
         Collection s = map.values();
         assertEquals(5, s.size());
         assertTrue(s.contains("A"));
         assertTrue(s.contains("B"));
         assertTrue(s.contains("C"));
         assertTrue(s.contains("D"));
         assertTrue(s.contains("E"));
     }

    
keySet.toArray returns contains all keys
 
     public void testDescendingAscendingKeySetToArray() {
         ConcurrentNavigableMap map = dmap5();
         Set s = map.keySet();
         Object[] ar = s.toArray();
         assertTrue(s.containsAll(Arrays.asList(ar)));
         assertEquals(5, ar.length);
         ar[0] = ;
         assertFalse(s.containsAll(Arrays.asList(ar)));
     }

    
descendingkeySet.toArray returns contains all keys
 
     public void testDescendingDescendingKeySetToArray() {
         ConcurrentNavigableMap map = dmap5();
         Set s = map.descendingKeySet();
         Object[] ar = s.toArray();
         assertEquals(5, ar.length);
         assertTrue(s.containsAll(Arrays.asList(ar)));
         ar[0] = ;
         assertFalse(s.containsAll(Arrays.asList(ar)));
     }

    
Values.toArray contains all values
 
     public void testDescendingValuesToArray() {
         ConcurrentNavigableMap map = dmap5();
         Collection v = map.values();
         Object[] ar = v.toArray();
         ArrayList s = new ArrayList(Arrays.asList(ar));
         assertEquals(5, ar.length);
         assertTrue(s.contains("A"));
         assertTrue(s.contains("B"));
         assertTrue(s.contains("C"));
         assertTrue(s.contains("D"));
         assertTrue(s.contains("E"));
     }

    
entrySet contains all pairs
 
     public void testDescendingEntrySet() {
         ConcurrentNavigableMap map = dmap5();
         Set s = map.entrySet();
         assertEquals(5, s.size());
         Iterator it = s.iterator();
         while (it.hasNext()) {
             Map.Entry e = (Map.Entryit.next();
             assertTrue(
                     (e.getKey().equals() && e.getValue().equals("A")) ||
                             (e.getKey().equals() && e.getValue().equals("B")) ||
                             (e.getKey().equals() && e.getValue().equals("C")) ||
                             (e.getKey().equals() && e.getValue().equals("D")) ||
                             (e.getKey().equals() && e.getValue().equals("E")));
         }
     }

    
putAll adds all key-value pairs from the given map
 
     public void testDescendingPutAll() {
         ConcurrentNavigableMap empty = dmap0();
         ConcurrentNavigableMap map = dmap5();
         empty.putAll(map);
         assertEquals(5, empty.size());
         assertTrue(empty.containsKey());
         assertTrue(empty.containsKey());
         assertTrue(empty.containsKey());
         assertTrue(empty.containsKey());
         assertTrue(empty.containsKey());
     }

    
putIfAbsent works when the given key is not present
 
     public void testDescendingPutIfAbsent() {
         ConcurrentNavigableMap map = dmap5();
         map.putIfAbsent("Z");
         assertTrue(map.containsKey());
     }

    
putIfAbsent does not add the pair if the key is already present
 
     public void testDescendingPutIfAbsent2() {
         ConcurrentNavigableMap map = dmap5();
         assertEquals("A"map.putIfAbsent("Z"));
     }

    
replace fails when the given key is not present
 
     public void testDescendingReplace() {
         ConcurrentNavigableMap map = dmap5();
         assertNull(map.replace("Z"));
         assertFalse(map.containsKey());
     }

    
replace succeeds if the key is already present
 
     public void testDescendingReplace2() {
         ConcurrentNavigableMap map = dmap5();
         assertNotNull(map.replace("Z"));
         assertEquals("Z"map.get());
     }

    
replace value fails when the given key not mapped to expected value
 
     public void testDescendingReplaceValue() {
         ConcurrentNavigableMap map = dmap5();
         assertEquals("A"map.get());
         assertFalse(map.replace("Z""Z"));
         assertEquals("A"map.get());
     }

    
replace value succeeds when the given key mapped to expected value
 
     public void testDescendingReplaceValue2() {
         ConcurrentNavigableMap map = dmap5();
         assertEquals("A"map.get());
         assertTrue(map.replace("A""Z"));
         assertEquals("Z"map.get());
     }

    
remove removes the correct key-value pair from the map
 
     public void testDescendingRemove() {
         ConcurrentNavigableMap map = dmap5();
         map.remove();
        assertEquals(4, map.size());
        assertFalse(map.containsKey());
    }

    
remove(key,value) removes only if pair present
    public void testDescendingRemove2() {
        ConcurrentNavigableMap map = dmap5();
        assertTrue(map.containsKey());
        assertEquals("E"map.get());
        map.remove("E");
        assertEquals(4, map.size());
        assertFalse(map.containsKey());
        map.remove("A");
        assertEquals(4, map.size());
        assertTrue(map.containsKey());
    }

    
lowerEntry returns preceding entry.
    public void testDescendingLowerEntry() {
        ConcurrentNavigableMap map = dmap5();
        Map.Entry e1 = map.lowerEntry();
        assertEquals(e1.getKey());
        Map.Entry e2 = map.lowerEntry();
        assertEquals(e2.getKey());
        Map.Entry e3 = map.lowerEntry();
        assertNull(e3);
        Map.Entry e4 = map.lowerEntry();
        assertNull(e4);
    }

    
higherEntry returns next entry.
    public void testDescendingHigherEntry() {
        ConcurrentNavigableMap map = dmap5();
        Map.Entry e1 = map.higherEntry();
        assertEquals(e1.getKey());
        Map.Entry e2 = map.higherEntry();
        assertEquals(e2.getKey());
        Map.Entry e3 = map.higherEntry();
        assertNull(e3);
        Map.Entry e4 = map.higherEntry();
        assertNull(e4);
    }

    
floorEntry returns preceding entry.
    public void testDescendingFloorEntry() {
        ConcurrentNavigableMap map = dmap5();
        Map.Entry e1 = map.floorEntry();
        assertEquals(e1.getKey());
        Map.Entry e2 = map.floorEntry();
        assertEquals(e2.getKey());
        Map.Entry e3 = map.floorEntry();
        assertEquals(e3.getKey());
        Map.Entry e4 = map.floorEntry();
        assertNull(e4);
    }

    
ceilingEntry returns next entry.
    public void testDescendingCeilingEntry() {
        ConcurrentNavigableMap map = dmap5();
        Map.Entry e1 = map.ceilingEntry();
        assertEquals(e1.getKey());
        Map.Entry e2 = map.ceilingEntry();
        assertEquals(e2.getKey());
        Map.Entry e3 = map.ceilingEntry();
        assertEquals(e3.getKey());
        Map.Entry e4 = map.ceilingEntry();
        assertNull(e4);
    }

    
pollFirstEntry returns entries in order
    public void testDescendingPollFirstEntry() {
        ConcurrentNavigableMap map = dmap5();
        Map.Entry e = map.pollFirstEntry();
        assertEquals(e.getKey());
        assertEquals("A"e.getValue());
        e = map.pollFirstEntry();
        assertEquals(e.getKey());
        map.put("A");
        e = map.pollFirstEntry();
        assertEquals(e.getKey());
        assertEquals("A"e.getValue());
        e = map.pollFirstEntry();
        assertEquals(e.getKey());
        map.remove();
        e = map.pollFirstEntry();
        assertEquals(e.getKey());
        try {
            e.setValue("A");
            shouldThrow();
        } catch (UnsupportedOperationException success) {}
        e = map.pollFirstEntry();
        assertNull(e);
    }

    
pollLastEntry returns entries in order
    public void testDescendingPollLastEntry() {
        ConcurrentNavigableMap map = dmap5();
        Map.Entry e = map.pollLastEntry();
        assertEquals(e.getKey());
        assertEquals("E"e.getValue());
        e = map.pollLastEntry();
        assertEquals(e.getKey());
        map.put("E");
        e = map.pollLastEntry();
        assertEquals(e.getKey());
        assertEquals("E"e.getValue());
        e = map.pollLastEntry();
        assertEquals(e.getKey());
        map.remove();
        e = map.pollLastEntry();
        assertEquals(e.getKey());
        try {
            e.setValue("E");
            shouldThrow();
        } catch (UnsupportedOperationException success) {}