Skip to content

Commit e8d9a60

Browse files
committed
Test refactoring; JsonNode test wrt #402
1 parent 41864be commit e8d9a60

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

src/test/java/com/fasterxml/jackson/dataformat/xml/XmlTestBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ protected void verifyException(Throwable e, String... matches)
298298
/**********************************************************
299299
*/
300300

301-
protected static String aposToQuotes(String json) {
302-
return json.replace("'", "\"");
301+
protected static String a2q(String content) {
302+
return content.replace("'", "\"");
303303
}
304304

305305
protected byte[] utf8Bytes(String str) {

src/test/java/com/fasterxml/jackson/dataformat/xml/deser/JsonNodeDeser403Test.java renamed to src/test/java/com/fasterxml/jackson/dataformat/xml/deser/JsonNodeBasicDeserTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
import com.fasterxml.jackson.databind.JsonNode;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.fasterxml.jackson.databind.node.JsonNodeType;
6+
67
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
78

8-
public class JsonNodeDeser403Test extends XmlTestBase
9+
public class JsonNodeBasicDeserTest extends XmlTestBase
910
{
10-
final private ObjectMapper MAPPER = newMapper();
11+
final private ObjectMapper XML_MAPPER = newMapper();
1112

1213
public void testSimpleNode() throws Exception
1314
{
14-
JsonNode root = MAPPER.readTree("<root attr='123' />");
15+
JsonNode root = XML_MAPPER.readTree("<root attr='123' />");
1516
assertTrue(root.isObject());
1617
assertEquals(1, root.size());
1718
assertEquals("123", root.get("attr").textValue());
@@ -20,7 +21,7 @@ public void testSimpleNode() throws Exception
2021
// [dataformat-xml#403]: Allow sequences
2122
public void testRepeated() throws Exception
2223
{
23-
JsonNode root = MAPPER.readTree("<root><value>a</value><value>b</value></root>");
24+
JsonNode root = XML_MAPPER.readTree("<root><value>a</value><value>b</value></root>");
2425
assertTrue(root.isObject());
2526
JsonNode arr = root.get("value");
2627
assertEquals(JsonNodeType.ARRAY, arr.getNodeType());
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fasterxml.jackson.dataformat.xml.failing;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.databind.json.JsonMapper;
5+
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
6+
7+
public class JsonNodeMixedContentTest extends XmlTestBase
8+
{
9+
final private ObjectMapper XML_MAPPER = newMapper();
10+
11+
final private ObjectMapper JSON_MAPPER = new JsonMapper();
12+
13+
public void testMixedContentBefore() throws Exception
14+
{
15+
// First, before elements:
16+
assertEquals(JSON_MAPPER.readTree(a2q("{'':'before','a':1,'b':'2'}")),
17+
XML_MAPPER.readTree("<root>before<a>1</a><b>2</b></root>"));
18+
}
19+
20+
public void testMixedContentBetween() throws Exception
21+
{
22+
// Second, between
23+
assertEquals(JSON_MAPPER.readTree(a2q("{'a':1,'':'between','b':'2'}")),
24+
XML_MAPPER.readTree("<root><a>1</a>between<b>2</b></root>"));
25+
}
26+
27+
public void testMixedContentAfter() throws Exception
28+
{
29+
// and then after
30+
assertEquals(JSON_MAPPER.readTree(a2q("{'a':1,'b':'2','':'after'}")),
31+
XML_MAPPER.readTree("<root><a>1</a><b>2</b>after</root>"));
32+
}
33+
34+
public void testMultipleMixedContent() throws Exception
35+
{
36+
// and then after
37+
assertEquals(JSON_MAPPER.readTree(a2q("{'':['first','second','third'],'a':1,'b':'2','':'after'}")),
38+
XML_MAPPER.readTree("<root>first<a>1</a>second<b>2</b>this</root>"));
39+
}
40+
}

src/test/java/com/fasterxml/jackson/dataformat/xml/ser/TestIndentation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public void testMultiLevel172() throws Exception
173173
.with(ToXmlGenerator.Feature.WRITE_XML_DECLARATION)
174174
.writeValueAsString(root);
175175
// unify possible apostrophes to quotes
176-
xml = aposToQuotes(xml);
176+
xml = a2q(xml);
177177
// with indentation, should get linefeeds in prolog/epilog too
178178
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
179179
+"<Company>\n"

0 commit comments

Comments
 (0)