修复toMap方法的bug,并加入单元测试代码

This commit is contained in:
Binary Wang
2017-01-04 19:23:03 +08:00
parent 70af494a4a
commit c47b8eceba
2 changed files with 64 additions and 3 deletions

View File

@@ -4,9 +4,10 @@ import com.google.common.collect.Maps;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import io.restassured.internal.path.xml.NodeChildrenImpl;
import io.restassured.internal.path.xml.NodeImpl;
import io.restassured.path.xml.XmlPath;
import io.restassured.path.xml.element.Node;
import io.restassured.path.xml.element.NodeChildren;
import io.restassured.path.xml.exception.XmlPathException;
import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import org.slf4j.Logger;
@@ -186,12 +187,23 @@ public abstract class WxPayBaseResult {
public Map<String, String> toMap() {
Map<String, String> result = Maps.newHashMap();
XmlPath xmlPath = new XmlPath(this.xmlString);
NodeChildren nodeChildren = xmlPath.getNodeChildren("xml");
Iterator<Node> iterator = nodeChildren.nodeIterator();
NodeImpl rootNode = null;
try {
rootNode = xmlPath.get("xml");
} catch (XmlPathException e) {
throw new RuntimeException("xml数据有问题请核实");
}
if (rootNode == null) {
throw new RuntimeException("xml数据有问题请核实");
}
Iterator<Node> iterator = rootNode.children().nodeIterator();
while (iterator.hasNext()) {
Node node = iterator.next();
result.put(node.name(), node.value());
}
return result;
}