Skip to content

Commit

Permalink
Add unit test omitting a legacy outer-class element.
Browse files Browse the repository at this point in the history
  • Loading branch information
joehni committed Dec 27, 2024
1 parent d987316 commit 9cbe889
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion xstream/src/test/com/thoughtworks/acceptance/OmitFieldsTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2005 Joe Walnes.
* Copyright (C) 2006, 2007, 2010, 2012, 2013, 2014, 2018, 2020, 2021 XStream Committers.
* Copyright (C) 2006, 2007, 2010, 2012, 2013, 2014, 2018, 2020, 2021, 2024 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -548,4 +548,35 @@ public void testReferencedElementsCanBeIgnored() {
final Wrapper out = xstream.fromXML(expectedXml);
assertEquals("junit", out.member.name);
}

public void testOmitFormerOuterClass() {
final Thing in = new Thing();
in.alwaysIgnore = "a";
in.sometimesIgnore = "b";
in.neverIgnore = "c";

final String expectedXml = ""
+ "<thing>\n"
+ " <sometimesIgnore>b</sometimesIgnore>\n"
+ " <neverIgnore>c</neverIgnore>\n"
+ "</thing>";

xstream.alias("thing", Thing.class);
xstream.aliasField("outer-class", Thing.class, "alwaysIgnore");

final String actualXml = xstream.toXML(in);
assertEquals(expectedXml, actualXml);

final String legacyXml = ""
+ "<thing>\n"
+ " <outer-class>\n"
+ " <member>some value</member>"
+ " </outer-class>\n"
+ " <sometimesIgnore>b</sometimesIgnore>\n"
+ " <neverIgnore>c</neverIgnore>\n"
+ "</thing>";

final Thing out = xstream.fromXML(legacyXml);
assertEquals(in, out);
}
}

0 comments on commit 9cbe889

Please sign in to comment.