Skip to content

Commit

Permalink
Update tests based on @bodewig's advice
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye committed Feb 28, 2018
1 parent 36a469e commit daedc5e
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/test/java/learningtest/org/xmlunit/diff/DiffTests.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package learningtest.org.xmlunit.diff;

import org.junit.Ignore;
import org.junit.Test;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.builder.Input;
Expand All @@ -16,6 +15,9 @@
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;
import static org.xmlunit.diff.ElementSelectors.byNameAndText;
import static org.xmlunit.diff.ElementSelectors.byXPath;
import static org.xmlunit.diff.ElementSelectors.conditionalBuilder;

public class DiffTests {

Expand Down Expand Up @@ -84,14 +86,30 @@ 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(conditionalBuilder()
.whenElementIsNamed("person").thenUse(byXPath("./id", byNameAndText))
.elseUse(byNameAndText).build()))
.withDifferenceEvaluator(
DifferenceEvaluators.chain(
DifferenceEvaluators.Default,
DifferenceEvaluators.downgradeDifferencesToSimilar(ComparisonType.CHILD_NODELIST_SEQUENCE)))
.checkForSimilar()
.build();
assertThat(diff.hasDifferences()).isFalse();
}

@Test
public void getDifferencesWhenDifferentlyOrderedCollectionShouldHaveNoDifferenceWithGlobalUnordered2() {
String xml1 = "<persons><person>Johnny</person><person>John</person></persons>";
String xml2 = "<persons><person>John</person><person>Johnny</person></persons>";

Diff diff = DiffBuilder.compare(Input.fromString(xml1))
.withTest(Input.fromString(xml2))
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
Expand Down

0 comments on commit daedc5e

Please sign in to comment.