KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > acceptance > IDDuplicateReferenceTest


1 package com.thoughtworks.acceptance;
2
3 import com.thoughtworks.xstream.XStream;
4
5 import java.util.ArrayList JavaDoc;
6 import java.util.List JavaDoc;
7
8 public class IDDuplicateReferenceTest extends AbstractDuplicateReferenceTest {
9
10     // tests inherited from superclass
11

12     protected void setUp() throws Exception JavaDoc {
13         super.setUp();
14         xstream.setMode(XStream.ID_REFERENCES);
15     }
16
17     public void testXmlContainsReferenceIds() {
18
19         Thing sameThing = new Thing("hello");
20         Thing anotherThing = new Thing("hello");
21
22         List JavaDoc list = new ArrayList JavaDoc();
23         list.add(sameThing);
24         list.add(sameThing);
25         list.add(anotherThing);
26
27         String JavaDoc expected = "" +
28                 "<list id=\"1\">\n" +
29                 " <thing id=\"2\">\n" +
30                 " <field>hello</field>\n" +
31                 " </thing>\n" +
32                 " <thing reference=\"2\"/>\n" +
33                 " <thing id=\"3\">\n" +
34                 " <field>hello</field>\n" +
35                 " </thing>\n" +
36                 "</list>";
37
38         assertEquals(expected, xstream.toXML(list));
39     }
40
41 }
42
Popular Tags