Skip to content

Commit

Permalink
Try global switch for unordered collection
Browse files Browse the repository at this point in the history
Unfortunately it doesn't work.

xmlunit/xmlunit#111 (comment)
  • Loading branch information
izeye committed Feb 28, 2018
1 parent 7cd4d01 commit 36a469e
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/test/java/learningtest/org/xmlunit/diff/DiffTests.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package learningtest.org.xmlunit.diff;

import org.junit.Ignore;
import org.junit.Test;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.builder.Input;
import org.xmlunit.diff.ComparisonResult;
import org.xmlunit.diff.ComparisonType;
import org.xmlunit.diff.DefaultNodeMatcher;
import org.xmlunit.diff.Diff;
import org.xmlunit.diff.Difference;
import org.xmlunit.diff.DifferenceEvaluators;
import org.xmlunit.diff.ElementSelectors;

import java.util.HashSet;
Expand All @@ -25,7 +28,7 @@ public void getDifferencesWhenIdenticalShouldHaveNoDifference() {
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
.checkForSimilar()
.build();
assertThat(diff.getDifferences().iterator().hasNext()).isFalse();
assertThat(diff.hasDifferences()).isFalse();
}

@Test
Expand Down Expand Up @@ -56,7 +59,7 @@ public void getDifferencesWhenDifferentPropertyOrderShouldHaveNoDifference() {
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
.checkForSimilar()
.build();
assertThat(diff.getDifferences().iterator().hasNext()).isFalse();
assertThat(diff.hasDifferences()).isFalse();
}

@Test
Expand All @@ -72,7 +75,7 @@ public void getDifferencesWhenDifferentlyOrderedCollectionShouldHaveNoDifference
.build();

// FIXME: Expected with unordered collection.
// assertThat(diff.getDifferences().iterator().hasNext()).isFalse();
// assertThat(diff.hasDifferences()).isFalse();

Set<ComparisonResult> comparisonResults = new HashSet<>();
for (Difference difference : diff.getDifferences()) {
Expand All @@ -81,4 +84,24 @@ public void getDifferencesWhenDifferentlyOrderedCollectionShouldHaveNoDifference
assertThat(comparisonResults).containsExactly(ComparisonResult.DIFFERENT);
}

// FIXME: See https://github.com/xmlunit/xmlunit/issues/111#issuecomment-368859900
// This doesn't work.
@Ignore
@Test
public void getDifferencesWhenDifferentlyOrderedCollectionShouldHaveNoDifferenceWithGlobalUnordered() {
String xml1 = "<persons><person><id>1</id><name>Johnny</name></person><person><id>2</id><name>John</name></person></persons>";
String xml2 = "<persons><person><id>2</id><name>John</name></person><person><id>1</id><name>Johnny</name></person></persons>";

Diff diff = DiffBuilder.compare(Input.fromString(xml1))
.withTest(Input.fromString(xml2))
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
.withDifferenceEvaluator(
DifferenceEvaluators.chain(
DifferenceEvaluators.Default,
DifferenceEvaluators.downgradeDifferencesToSimilar(ComparisonType.CHILD_NODELIST_SEQUENCE)))
.checkForSimilar()
.build();
assertThat(diff.hasDifferences()).isFalse();
}

}

0 comments on commit 36a469e

Please sign in to comment.