1 package com.thoughtworks.xstream.core; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import com.thoughtworks.acceptance.AbstractAcceptanceTest; 7 8 public class TreeUnmarshallerTest extends AbstractAcceptanceTest { 9 10 protected void setUp() throws Exception { 11 super.setUp(); 12 } 13 14 public void testUnmarshallingOfAliasedInterfaces() { 15 xstream.alias("addressBookInfo", AddressBookInfo.class, AddressBook.class); 16 xstream.alias("addressInfo", AddressInfo.class, Address.class); 17 AddressBookInfo initialObject = new AddressBook(); 18 String marshalledXML = xstream.toXML(initialObject); 19 AddressBookInfo unmarshalledObject = (AddressBookInfo) xstream.fromXML(marshalledXML); 20 assertEquals(marshalledXML, xstream.toXML(unmarshalledObject)); 21 } 22 23 public interface AddressBookInfo { 24 public List getAddresses(); 25 26 public void setAddresses(List address); 27 } 28 29 public class AddressBook implements AddressBookInfo { 30 private List addresses; 31 32 public AddressBook() { 33 addresses = new ArrayList (); 34 AddressInfo addr = new Address("Home", "Home"); 35 AddressInfo addr1 = new Address("Office", "Office"); 36 addresses.add(addr); 37 addresses.add(addr1); 38 } 39 40 public List getAddresses() { 41 return addresses; 42 } 43 44 public void setAddresses(List addresses) { 45 this.addresses = addresses; 46 } 47 } 48 49 public interface AddressInfo { 50 public String getAddr1(); 51 52 public String getAddr2(); 53 54 public void setAddr1(String addr1); 55 56 public void setAddr2(String addr2); 57 } 58 59 public class Address implements AddressInfo { 60 private String addr1 = "addr1"; 61 62 private String addr2 = "addr2"; 63 64 public Address(String addr1, String addr2) { 65 this.addr1 = addr1; 66 this.addr2 = addr2; 67 } 68 69 public String getAddr1() { 70 return addr1; 71 } 72 73 public String getAddr2() { 74 return addr2; 75 } 76 77 public void setAddr1(String addr1) { 78 this.addr1 = addr1; 79 } 80 81 public void setAddr2(String addr2) { 82 this.addr2 = addr2; 83 } 84 } 85 } 86 | Popular Tags |