Example #1
0
  /**
   * Since the field type is {@link ImmutableMap}, XML shouldn't contain a reference to the type
   * name.
   */
  private void roundtripImmutableMap(XStream2 xs, ImmutableMap<?, ?> m) {
    ImmutableMapHolder a = new ImmutableMapHolder();
    a.m = m;
    String xml = xs.toXML(a);
    System.out.println(xml);
    assertFalse("shouldn't contain the class name", xml.contains("google"));
    assertFalse("shouldn't contain the class name", xml.contains("class"));
    a = (ImmutableMapHolder) xs.fromXML(xml);

    assertSame(
        m.getClass(), a.m.getClass()); // should get back the exact same type, not just a random map
    assertEquals(m, a.m);
  }
Example #2
0
  private void roundtripImmutableMapAsPlainMap(XStream2 xs, ImmutableMap<?, ?> m) {
    MapHolder a = new MapHolder();
    a.m = m;
    String xml = xs.toXML(a);
    System.out.println(xml);
    assertTrue(
        "XML should mention the class name",
        xml.contains('\"' + ImmutableMap.class.getName() + '\"'));
    a = (MapHolder) xs.fromXML(xml);

    assertSame(
        m.getClass(), a.m.getClass()); // should get back the exact same type, not just a random map
    assertEquals(m, a.m);
  }