1 package com.thoughtworks.acceptance; 2 3 import com.thoughtworks.xstream.XStream; 4 5 public class IDCircularReferenceTest extends AbstractCircularReferenceTest { 6 7 protected void setUp() throws Exception { 9 super.setUp(); 10 xstream.setMode(XStream.ID_REFERENCES); 11 } 12 13 public void testCircularReferenceXml() { 14 Person bob = new Person("bob"); 15 Person jane = new Person("jane"); 16 bob.likes = jane; 17 jane.likes = bob; 18 19 String expected = "" + 20 "<person id=\"1\">\n" + 21 " <firstname>bob</firstname>\n" + 22 " <likes id=\"2\">\n" + 23 " <firstname>jane</firstname>\n" + 24 " <likes reference=\"1\"/>\n" + 25 " </likes>\n" + 26 "</person>"; 27 28 assertEquals(expected, xstream.toXML(bob)); 29 } 30 31 public void testCircularReferenceToSelfXml() { 32 Person bob = new Person("bob"); 33 bob.likes = bob; 34 35 String expected = "" + 36 "<person id=\"1\">\n" + 37 " <firstname>bob</firstname>\n" + 38 " <likes reference=\"1\"/>\n" + 39 "</person>"; 40 41 assertEquals(expected, xstream.toXML(bob)); 42 } 43 44 } 45 | Popular Tags |