Skip to content

Commit

Permalink
Merge branch '6.2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Nov 19, 2024
2 parents e69ae51 + a3c132c commit a7547cd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -110,7 +110,7 @@ public boolean hasDifferences() {

@Override
public String toString() {
return this.diff.toString();
return this.diff.fullDescription();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,51 +27,56 @@
*/
class XmlExpectationsHelperTests {

private static final String CONTROL = "<root><field1>f1</field1><field2>f2</field2></root>";

private final XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper();


@Test
void assertXmlEqualForEqual() throws Exception {
String control = "<root><field1>f1</field1><field2>f2</field2></root>";
String test = "<root><field1>f1</field1><field2>f2</field2></root>";
XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper();
xmlHelper.assertXmlEqual(control, test);
xmlHelper.assertXmlEqual(CONTROL, test);
}

@Test
void assertXmlEqualExceptionForIncorrectValue() {
String control = "<root><field1>f1</field1><field2>f2</field2></root>";
String test = "<root><field1>notf1</field1><field2>f2</field2></root>";
XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper();
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
xmlHelper.assertXmlEqual(control, test))
.withMessageStartingWith("Body content Expected child 'field1'");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> xmlHelper.assertXmlEqual(CONTROL, test))
.withMessageStartingWith("Body content Expected child 'field1'");
}

@Test
void assertXmlEqualForOutOfOrder() throws Exception {
String control = "<root><field1>f1</field1><field2>f2</field2></root>";
String test = "<root><field2>f2</field2><field1>f1</field1></root>";
XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper();
xmlHelper.assertXmlEqual(control, test);
xmlHelper.assertXmlEqual(CONTROL, test);
}

@Test
void assertXmlEqualExceptionForMoreEntries() {
String control = "<root><field1>f1</field1><field2>f2</field2></root>";
String test = "<root><field1>f1</field1><field2>f2</field2><field3>f3</field3></root>";
XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper();
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
xmlHelper.assertXmlEqual(control, test))
.withMessageContaining("Expected child nodelist length '2' but was '3'");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> xmlHelper.assertXmlEqual(CONTROL, test))
.withMessageContaining("Expected child nodelist length '2' but was '3'");

}

@Test
void assertXmlEqualExceptionForLessEntries() {
void assertXmlEqualExceptionForFewerEntries() {
String control = "<root><field1>f1</field1><field2>f2</field2><field3>f3</field3></root>";
String test = "<root><field1>f1</field1><field2>f2</field2></root>";
XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper();
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
xmlHelper.assertXmlEqual(control, test))
.withMessageContaining("Expected child nodelist length '3' but was '2'");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> xmlHelper.assertXmlEqual(control, test))
.withMessageContaining("Expected child nodelist length '3' but was '2'");
}

@Test
void assertXmlEqualExceptionWithFullDescription() {
String test = "<root><field2>f2</field2><field3>f3</field3></root>";
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> xmlHelper.assertXmlEqual(CONTROL, test))
.withMessageContaining("Expected child 'field1' but was 'null'")
.withMessageContaining("Expected child 'null' but was 'field3'");
}

}

0 comments on commit a7547cd

Please sign in to comment.