Skip to content

Commit

Permalink
Minor test clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 12, 2022
1 parent dfcef81 commit 077a9d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.fasterxml.jackson.dataformat.xml.ser;

import java.io.IOException;
import java.util.*;

import com.fasterxml.jackson.annotation.*;
Expand Down Expand Up @@ -51,21 +50,6 @@ public DynaBean(Map<String, String> values) {
public Map<String, String> getProperties() {
return _properties;
}
}

/*
/**********************************************************
/* Set up
/**********************************************************
*/

protected XmlMapper _xmlMapper;

// let's actually reuse XmlMapper to make things bit faster
@Override
public void setUp() throws Exception {
super.setUp();
_xmlMapper = new XmlMapper();
}

/*
Expand All @@ -74,17 +58,19 @@ public void setUp() throws Exception {
/**********************************************************
*/

public void testSimpleNsAttr() throws IOException
private final XmlMapper XML_MAPPER = newMapper();

public void testSimpleNsAttr() throws Exception
{
String xml = _xmlMapper.writeValueAsString(new NsAttrBean());
String xml = XML_MAPPER.writeValueAsString(new NsAttrBean());
xml = removeSjsxpNamespace(xml);
// here we assume woodstox automatic prefixes, not very robust but:
assertEquals("<NsAttrBean xmlns:wstxns1=\"http://foo\" wstxns1:attr=\"3\"/>", xml);
}

public void testIssue19() throws IOException
public void testIssue19() throws Exception
{
String xml = _xmlMapper.writeValueAsString(new Issue19Bean());
String xml = XML_MAPPER.writeValueAsString(new Issue19Bean());
xml = removeSjsxpNamespace(xml);
xml = xml.replaceAll("\"", "'");
// as with above, assumes exact NS allocation strategy, not optimal:
Expand All @@ -93,22 +79,22 @@ public void testIssue19() throws IOException
xml);
}

public void testIssue6() throws IOException
public void testIssue6() throws Exception
{
assertEquals("<Jurisdiction name=\"Foo\" value=\"13\"/>",
_xmlMapper.writeValueAsString(new Jurisdiction()));
XML_MAPPER.writeValueAsString(new Jurisdiction()));
}

public void testIssue117AnySetterAttrs() throws IOException
public void testIssue117AnySetterAttrs() throws Exception
{
Map<String, String> values = new HashMap<String, String>();
values.put("prop1", "val1");

String xml = _xmlMapper.writeValueAsString(new DynaBean(values));
String xml = XML_MAPPER.writeValueAsString(new DynaBean(values));
assertEquals("<dynaBean class=\"TestSerializationAttr$DynaBean\"><prop1>val1</prop1></dynaBean>",
removeSjsxpNamespace(xml));
}

/*
/**********************************************************
/* Helper methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public class TestSerializationOrdering extends XmlTestBase
{
@JsonPropertyOrder({"a", "c" })
static class Bean91 {
public String a;
public String c;
@JacksonXmlProperty(isAttribute = true)
public String b;
public String c;
public String a;

public Bean91(String a, String b, String c) {
this.a = a;
Expand All @@ -21,10 +21,11 @@ public Bean91(String a, String b, String c) {
}
}

private final XmlMapper MAPPER = newMapper();

public void testOrdering() throws Exception
{
XmlMapper xmlMapper = new XmlMapper();
String xml = xmlMapper.writeValueAsString(new Bean91("1", "2", "3"));
String xml = MAPPER.writeValueAsString(new Bean91("1", "2", "3"));
assertEquals("<Bean91 b=\"2\"><a>1</a><c>3</c></Bean91>", xml);
}
}

0 comments on commit 077a9d9

Please sign in to comment.