Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2015-12-07 19:49:10 +0000
committerSam Davis2015-12-07 19:49:10 +0000
commitb577e9b895b89f478801410421f89a6a9c0cf70d (patch)
tree11f0a675721d61874755448b75be53d56d9b9e02
parent4aa0f081f35123ab326db46cde22554913ee57d6 (diff)
downloadorg.eclipse.mylyn.context-b577e9b895b89f478801410421f89a6a9c0cf70d.tar.gz
org.eclipse.mylyn.context-b577e9b895b89f478801410421f89a6a9c0cf70d.tar.xz
org.eclipse.mylyn.context-b577e9b895b89f478801410421f89a6a9c0cf70d.zip
sort nodes before comparisonR_3_18_0e_4_5_m_3_18_x
-rw-r--r--org.eclipse.mylyn.debug.tests/src/org/eclipse/mylyn/internal/debug/ui/BreakpointsStateUtilTest.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.debug.tests/src/org/eclipse/mylyn/internal/debug/ui/BreakpointsStateUtilTest.java b/org.eclipse.mylyn.debug.tests/src/org/eclipse/mylyn/internal/debug/ui/BreakpointsStateUtilTest.java
index 3d64b693c..fdecc7060 100644
--- a/org.eclipse.mylyn.debug.tests/src/org/eclipse/mylyn/internal/debug/ui/BreakpointsStateUtilTest.java
+++ b/org.eclipse.mylyn.debug.tests/src/org/eclipse/mylyn/internal/debug/ui/BreakpointsStateUtilTest.java
@@ -19,6 +19,10 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -42,6 +46,8 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/**
@@ -85,10 +91,43 @@ public class BreakpointsStateUtilTest {
Document pluginStateDocument = getDocument(pluginStateFile);
Document testDocument = getDocument(new File("testdata/breakpointFile.xml"));
+ sortNodes(pluginStateDocument);
+ sortNodes(testDocument);
assertTrue("Documents not equal:\n" + documentToString(pluginStateDocument) + "\n===\n"
+ documentToString(testDocument), pluginStateDocument.isEqualNode(testDocument));
}
+ private void sortNodes(Node node) {
+ NodeList children = node.getChildNodes();
+ List<Node> childNodes = new ArrayList<>();
+ for (int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ node.removeChild(child);
+ childNodes.add(child);
+ sortNodes(child);
+ }
+ Collections.sort(childNodes, new Comparator<Node>() {
+
+ @Override
+ public int compare(Node a, Node b) {
+ if (a.getAttributes() == null) {
+ if (b.getAttributes() == null) {
+ return 0;
+ }
+ return 1;
+ } else if (b.getAttributes() == null) {
+ return -1;
+ }
+ Node nameA = a.getAttributes().getNamedItem("name");
+ Node nameB = b.getAttributes().getNamedItem("name");
+ return nameA.getNodeValue().compareTo(nameB.getNodeValue());
+ }
+ });
+ for (Node child : childNodes) {
+ node.appendChild(child);
+ }
+ }
+
private String documentToString(Document docuemnt) throws TransformerException {
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();

Back to the top