001: /*
002: * Copyright (C) 2005 Joe Walnes.
003: * Copyright (C) 2006, 2007 XStream Committers.
004: * All rights reserved.
005: *
006: * The software in this package is published under the terms of the BSD
007: * style license a copy of which has been included with this distribution in
008: * the LICENSE.txt file.
009: *
010: * Created on 10. April 2005 by Mauro Talevi
011: */
012: package com.thoughtworks.xstream.core;
013:
014: import com.thoughtworks.acceptance.AbstractAcceptanceTest;
015:
016: import java.util.ArrayList;
017: import java.util.List;
018:
019: public class TreeUnmarshallerTest extends AbstractAcceptanceTest {
020:
021: protected void setUp() throws Exception {
022: super .setUp();
023: }
024:
025: public void testUnmarshallingOfAliasedInterfaces() {
026: xstream.alias("addressBookInfo", AddressBookInfo.class,
027: AddressBook.class);
028: xstream.alias("addressInfo", AddressInfo.class, Address.class);
029: AddressBookInfo initialObject = new AddressBook();
030: String marshalledXML = xstream.toXML(initialObject);
031: AddressBookInfo unmarshalledObject = (AddressBookInfo) xstream
032: .fromXML(marshalledXML);
033: assertEquals(marshalledXML, xstream.toXML(unmarshalledObject));
034: }
035:
036: public interface AddressBookInfo {
037: public List getAddresses();
038:
039: public void setAddresses(List address);
040: }
041:
042: public static class AddressBook implements AddressBookInfo {
043: private List addresses;
044:
045: public AddressBook() {
046: addresses = new ArrayList();
047: AddressInfo addr = new Address("Home", "Home");
048: AddressInfo addr1 = new Address("Office", "Office");
049: addresses.add(addr);
050: addresses.add(addr1);
051: }
052:
053: public List getAddresses() {
054: return addresses;
055: }
056:
057: public void setAddresses(List addresses) {
058: this .addresses = addresses;
059: }
060: }
061:
062: public interface AddressInfo {
063: public String getAddr1();
064:
065: public String getAddr2();
066:
067: public void setAddr1(String addr1);
068:
069: public void setAddr2(String addr2);
070: }
071:
072: public static class Address implements AddressInfo {
073: private String addr1 = "addr1";
074:
075: private String addr2 = "addr2";
076:
077: private Address() {
078: }
079:
080: public Address(String addr1, String addr2) {
081: this .addr1 = addr1;
082: this .addr2 = addr2;
083: }
084:
085: public String getAddr1() {
086: return addr1;
087: }
088:
089: public String getAddr2() {
090: return addr2;
091: }
092:
093: public void setAddr1(String addr1) {
094: this .addr1 = addr1;
095: }
096:
097: public void setAddr2(String addr2) {
098: this.addr2 = addr2;
099: }
100: }
101: }
|