public void testPutAll_KeyCollection() {
    MultiHashMap map = new MultiHashMap();
    Collection coll = Arrays.asList(new Object[] {"X", "Y", "Z"});

    assertEquals(true, map.putAll("A", coll));
    assertEquals(3, map.size("A"));
    assertEquals(true, map.containsValue("A", "X"));
    assertEquals(true, map.containsValue("A", "Y"));
    assertEquals(true, map.containsValue("A", "Z"));

    assertEquals(false, map.putAll("A", null));
    assertEquals(3, map.size("A"));
    assertEquals(true, map.containsValue("A", "X"));
    assertEquals(true, map.containsValue("A", "Y"));
    assertEquals(true, map.containsValue("A", "Z"));

    assertEquals(false, map.putAll("A", new ArrayList()));
    assertEquals(3, map.size("A"));
    assertEquals(true, map.containsValue("A", "X"));
    assertEquals(true, map.containsValue("A", "Y"));
    assertEquals(true, map.containsValue("A", "Z"));

    coll = Arrays.asList(new Object[] {"M"});
    assertEquals(true, map.putAll("A", coll));
    assertEquals(4, map.size("A"));
    assertEquals(true, map.containsValue("A", "X"));
    assertEquals(true, map.containsValue("A", "Y"));
    assertEquals(true, map.containsValue("A", "Z"));
    assertEquals(true, map.containsValue("A", "M"));
  }
  // ----------------------------
  //          Tests
  // ----------------------------
  public void testPutNGet() {
    MultiHashMap map = new MultiHashMap();
    loadMap(map);
    checkMap(map);

    assertTrue(map.get(new Integer(99)) == null);

    map.clear();
    assertTrue(map.size() == 0);
  }
  public void testClone() {
    MultiHashMap map = new MultiHashMap();
    map.put("A", "1");
    map.put("A", "2");
    Collection coll = (Collection) map.get("A");
    assertEquals(1, map.size());
    assertEquals(2, coll.size());

    MultiHashMap cloned = (MultiHashMap) map.clone();
    Collection clonedColl = (Collection) cloned.get("A");
    assertNotSame(map, cloned);
    assertNotSame(coll, clonedColl);
    assertEquals(1, map.size());
    assertEquals(2, coll.size());
    assertEquals(1, cloned.size());
    assertEquals(2, clonedColl.size());
    map.put("A", "3");
    assertEquals(1, map.size());
    assertEquals(3, coll.size());
    assertEquals(1, cloned.size());
    assertEquals(2, clonedColl.size());
  }
  public void testConstructorCopy2() {
    Map map = new HashMap();
    map.put("A", "1");
    map.put("B", "2");
    assertEquals(2, map.size());

    MultiHashMap newMap = new MultiHashMap(map);
    Collection newColl = (Collection) newMap.get("A");
    assertNotSame(map, newMap);
    assertEquals(2, map.size());
    assertEquals(2, newMap.size());
    assertEquals(1, newColl.size());

    map.put("A", "3");
    assertEquals(2, map.size());
    assertEquals(2, newMap.size());
    assertEquals(1, newColl.size());

    map.put("C", "4");
    assertEquals(3, map.size());
    assertEquals(2, newMap.size());
    assertEquals(1, newColl.size());
  }
  public void testPutAll_Map1() {
    MultiMap original = new MultiHashMap();
    original.put("key", "object1");
    original.put("key", "object2");

    MultiHashMap test = new MultiHashMap();
    test.put("keyA", "objectA");
    test.put("key", "object0");
    test.putAll(original);

    assertEquals(2, test.size());
    assertEquals(4, test.totalSize());
    assertEquals(1, test.getCollection("keyA").size());
    assertEquals(3, test.getCollection("key").size());
    assertEquals(true, test.containsValue("objectA"));
    assertEquals(true, test.containsValue("object0"));
    assertEquals(true, test.containsValue("object1"));
    assertEquals(true, test.containsValue("object2"));
  }
  private void loadMap(MultiHashMap map) {
    // Set up so that we load the keys "randomly"
    // (i.e. we don't want to load int row-order, so that all like keys
    // load together. We want to mix it up...)

    int numRows = sMapPairs.length;
    int maxCols = 0;
    for (int ii = 0; ii < sMapPairs.length; ii++) {
      if (sMapPairs[ii].length > maxCols) {
        maxCols = sMapPairs[ii].length;
      }
    }
    for (int ii = 0; ii < maxCols; ii++) {
      for (int jj = 0; jj < numRows; jj++) {
        if (ii < sMapPairs[jj].length) {
          map.put(sMapPairs[jj][ii].mKey, sMapPairs[jj][ii].mValue);
          // ---------------------------------------------------------
        }
      }
    }
    assertTrue(map.size() == sMapPairs.length);
  }
 public void testSize_Key() {
   MultiHashMap map = new MultiHashMap();
   assertEquals(0, map.size("A"));
   assertEquals(0, map.size("B"));
   map.put("A", "AA");
   assertEquals(1, map.size("A"));
   assertEquals(0, map.size("B"));
   map.put("B", "BA");
   assertEquals(1, map.size("A"));
   assertEquals(1, map.size("B"));
   map.put("B", "BB");
   assertEquals(1, map.size("A"));
   assertEquals(2, map.size("B"));
   map.put("B", "BC");
   assertEquals(1, map.size("A"));
   assertEquals(3, map.size("B"));
   map.remove("A");
   assertEquals(0, map.size("A"));
   assertEquals(3, map.size("B"));
   map.remove("B", "BC");
   assertEquals(0, map.size("A"));
   assertEquals(2, map.size("B"));
 }