01: /*
02: * Copyright (C) 2006, 2007 XStream Committers.
03: * All rights reserved.
04: *
05: * The software in this package is published under the terms of the BSD
06: * style license a copy of which has been included with this distribution in
07: * the LICENSE.txt file.
08: *
09: * Created on 07. March 2006 by Joerg Schaible
10: */
11: package com.thoughtworks.xstream.core;
12:
13: import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14: import com.thoughtworks.acceptance.someobjects.WithNamedList;
15: import com.thoughtworks.xstream.XStream;
16:
17: import java.util.ArrayList;
18:
19: public class ReferenceByIDMarshallingStrategyTest extends
20: AbstractAcceptanceTest {
21:
22: protected void setUp() throws Exception {
23: super .setUp();
24: xstream.setMode(XStream.ID_REFERENCES);
25: }
26:
27: public void testIgnoresImplicitCollection() {
28: xstream.alias("strings", WithNamedList.class);
29: xstream.addImplicitCollection(WithNamedList.class, "things");
30: WithNamedList wl = new WithNamedList("foo");
31: wl.things.add("Hello");
32: wl.things.add("Daniel");
33:
34: final String expected = "<strings id=\"1\">\n"
35: + " <string>Hello</string>\n"
36: + " <string>Daniel</string>\n"
37: + " <name>foo</name>\n" + "</strings>";
38:
39: assertBothWays(wl, expected);
40: }
41:
42: static class List {
43: public Object o;
44: public ArrayList list = new ArrayList();
45: }
46:
47: public void testIgnoresImplicitCollectionAtAnyFieldPosition() {
48: final List another = new List();
49: another.o = new Object();
50: another.list.add(new Object());
51: xstream.addImplicitCollection(List.class, "list");
52: xstream.alias("list", List.class);
53:
54: final String expected = "<list id=\"1\">\n"
55: + " <o id=\"2\"/>\n" + " <object id=\"4\"/>\n"
56: + "</list>";
57:
58: assertBothWays(another, expected);
59: }
60: }
|