Index: src/test/com/thoughtworks/acceptance/InheritanceTest.java =================================================================== --- src/test/com/thoughtworks/acceptance/InheritanceTest.java (revision 809) +++ src/test/com/thoughtworks/acceptance/InheritanceTest.java (working copy) @@ -127,4 +127,96 @@ ""; assertBothWays(childA, expected); } + + + public static class Person { + String firstName; + String lastName; + boolean isOld; + + public Person(String firstName, String lastName, boolean old) { + this.firstName = firstName; + this.lastName = lastName; + isOld = old; + } + } + + public static class House { + List people = new ArrayList(); + } + + public static class Woman extends Person { + public Woman(String firstName, String lastName, boolean old) { + super(firstName, lastName, old); + } + } + + public static class Man extends Person { + public Man(String firstName, String lastName, boolean old) { + super(firstName, lastName, old); + } + } + + public void testBasicInheritance() { + xstream.alias("house", House.class); + xstream.aliasField("first-name", Person.class, "firstName"); + xstream.aliasField("last-name", Person.class, "lastName"); + xstream.aliasField("is-old", Person.class, "isOld"); + xstream.alias("woman", Woman.class); + xstream.alias("man", Man.class); + + Man man = new Man("John", "Doe", true); + Woman woman = new Woman("Jane", "Doe", true); + House house = new House(); + house.people.add(man); + house.people.add(woman); + + String expected = "\n" + + " \n" + + " \n" + + " John\n" + + " Doe\n" + + " true\n" + + " \n" + + " \n" + + " Jane\n" + + " Doe\n" + + " true\n" + + " \n" + + " \n" + + ""; + assertBothWays(house, expected); + } + + public void testInheritanceOverriding() { + xstream.alias("house", House.class); + xstream.aliasField("first-name", Person.class, "firstName"); + xstream.aliasField("last-name", Person.class, "lastName"); + xstream.aliasField("is-old", Person.class, "isOld"); + xstream.alias("woman", Woman.class); + xstream.alias("man", Man.class); + xstream.aliasField("is-distinguished", Man.class, "isOld"); + + Man man = new Man("John", "Doe", true); + Woman woman = new Woman("Jane", "Doe", true); + House house = new House(); + house.people.add(man); + house.people.add(woman); + + String expected = "\n" + + " \n" + + " \n" + + " John\n" + + " Doe\n" + + " true\n" + + " \n" + + " \n" + + " Jane\n" + + " Doe\n" + + " true\n" + + " \n" + + " \n" + + ""; + assertBothWays(house, expected); + } }