Ejemplo n.º 1
0
  public void testSerialisation4() throws Exception {
    Flat3Map map = new Flat3Map();
    map.put(ONE, TEN);
    map.put(TWO, TWENTY);
    map.put(TEN, ONE);
    map.put(TWENTY, TWO);

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bout);
    out.writeObject(map);
    byte[] bytes = bout.toByteArray();
    out.close();
    ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
    ObjectInputStream in = new ObjectInputStream(bin);
    Flat3Map ser = (Flat3Map) in.readObject();
    in.close();
    assertEquals(4, map.size());
    assertEquals(4, ser.size());
    assertEquals(true, ser.containsKey(ONE));
    assertEquals(true, ser.containsKey(TWO));
    assertEquals(true, ser.containsKey(TEN));
    assertEquals(true, ser.containsKey(TWENTY));
    assertEquals(TEN, ser.get(ONE));
    assertEquals(TWENTY, ser.get(TWO));
    assertEquals(ONE, ser.get(TEN));
    assertEquals(TWO, ser.get(TWENTY));
  }
Ejemplo n.º 2
0
  public void testClone4() {
    Flat3Map map = new Flat3Map();
    assertEquals(0, map.size());
    map.put(ONE, TEN);
    map.put(TWO, TWENTY);
    map.put(TEN, ONE);
    map.put(TWENTY, TWO);

    // clone works (size = 4)
    Flat3Map cloned = (Flat3Map) map.clone();
    assertEquals(4, map.size());
    assertEquals(4, cloned.size());
    assertEquals(true, cloned.containsKey(ONE));
    assertEquals(true, cloned.containsKey(TWO));
    assertEquals(true, cloned.containsKey(TEN));
    assertEquals(true, cloned.containsKey(TWENTY));
    assertSame(TEN, cloned.get(ONE));
    assertSame(TWENTY, cloned.get(TWO));
    assertSame(ONE, cloned.get(TEN));
    assertSame(TWO, cloned.get(TWENTY));

    // change original doesn't change clone
    map.clear();
    assertEquals(0, map.size());
    assertEquals(4, cloned.size());
    assertEquals(true, cloned.containsKey(ONE));
    assertEquals(true, cloned.containsKey(TWO));
    assertEquals(true, cloned.containsKey(TEN));
    assertEquals(true, cloned.containsKey(TWENTY));
    assertSame(TEN, cloned.get(ONE));
    assertSame(TWENTY, cloned.get(TWO));
    assertSame(ONE, cloned.get(TEN));
    assertSame(TWO, cloned.get(TWENTY));
  }