From ad85f0bc5add3241910b3782fe7e6ff67e983865 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Wed, 23 Oct 2019 10:03:59 -0700 Subject: [PATCH] Refactor backported failing test for #366 --- .../dataformat/xml/deser/XsiNil354Test.java | 35 -------------- .../dataformat/xml/failing/XsiNil366Test.java | 46 +++++++++++++++++++ 2 files changed, 46 insertions(+), 35 deletions(-) create mode 100644 src/test/java/com/fasterxml/jackson/dataformat/xml/failing/XsiNil366Test.java diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNil354Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNil354Test.java index 27d487ad4..d80d42b55 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNil354Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNil354Test.java @@ -14,20 +14,6 @@ public DoubleWrapper(Double value) { } } - protected static class Parent { - public Level1 level1; - } - - protected static class Level1 { - public Level2 level2; - public String field; // this should not be needed, but an unknown element is thrown without it - } - - protected static class Level2 { - public String ignored; - public String field; - } - private final XmlMapper MAPPER = newMapper(); public void testWithDoubleAsNull() throws Exception @@ -71,25 +57,4 @@ public void testRootPojoAsNonNull() throws Exception Point.class); assertNotNull(bean); } - - public void testDoesNotAffectHierarchy() throws Exception - { - String xml = "" - + "" - + "" - + "" - + "test-value" - + "" - + "" - + ""; - Parent bean = MAPPER.readValue(xml, Parent.class); - - assertNotNull(bean); - - // this should not be set, but having an xsi:nil field before it causes it to set the next field on the wrong class - assertEquals("test-value", bean.level1.field); - - // fails because field is set on level1 instead of on level2 - assertEquals("test-value", bean.level1.level2.field); - } } diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/XsiNil366Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/XsiNil366Test.java new file mode 100644 index 000000000..d13c0536b --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/XsiNil366Test.java @@ -0,0 +1,46 @@ +package com.fasterxml.jackson.dataformat.xml.failing; + +import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import com.fasterxml.jackson.dataformat.xml.XmlTestBase; + +public class XsiNil366Test extends XmlTestBase +{ + // for [dataformat-xml#366] + protected static class Parent366 { + public Level1 level1; + } + + protected static class Level1 { + public Level2 level2; + public String field; // this should not be needed, but an unknown element is thrown without it + } + + protected static class Level2 { + public String ignored; + public String field; + } + + private final XmlMapper MAPPER = newMapper(); + + // for [dataformat-xml#366] + public void testDoesNotAffectHierarchy() throws Exception + { + String xml = "" + + "" + + "" + + "" + + "test-value" + + "" + + "" + + ""; + Parent366 bean = MAPPER.readValue(xml, Parent366.class); + + assertNotNull(bean); + + // this should not be set, but having an xsi:nil field before it causes it to set the next field on the wrong class + assertEquals("test-value", bean.level1.field); + + // fails because field is set on level1 instead of on level2 + assertEquals("test-value", bean.level1.level2.field); + } +}