1 package com.thoughtworks.acceptance; 2 3 import com.thoughtworks.xstream.XStream; 4 5 public class XPathCircularReferenceTest extends AbstractCircularReferenceTest { 6 7 protected void setUp() throws Exception { 9 super.setUp(); 10 xstream.setMode(XStream.XPATH_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>\n" + 21 " <firstname>bob</firstname>\n" + 22 " <likes>\n" + 23 " <firstname>jane</firstname>\n" + 24 " <likes reference=\"../..\"/>\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>\n" + 37 " <firstname>bob</firstname>\n" + 38 " <likes reference=\"..\"/>\n" + 39 "</person>"; 40 41 assertEquals(expected, xstream.toXML(bob)); 42 } 43 44 } 45 | Popular Tags |