Merge branch '6.2.x'

This commit is contained in:
Sam Brannen 2024-11-19 13:33:53 +01:00
commit a7547cd311
2 changed files with 28 additions and 23 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -110,7 +110,7 @@ public class XmlExpectationsHelper {
@Override @Override
public String toString() { public String toString() {
return this.diff.toString(); return this.diff.fullDescription();
} }
} }

View File

@ -27,51 +27,56 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
*/ */
class XmlExpectationsHelperTests { class XmlExpectationsHelperTests {
private static final String CONTROL = "<root><field1>f1</field1><field2>f2</field2></root>";
private final XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper();
@Test @Test
void assertXmlEqualForEqual() throws Exception { void assertXmlEqualForEqual() throws Exception {
String control = "<root><field1>f1</field1><field2>f2</field2></root>";
String test = "<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 @Test
void assertXmlEqualExceptionForIncorrectValue() { void assertXmlEqualExceptionForIncorrectValue() {
String control = "<root><field1>f1</field1><field2>f2</field2></root>";
String test = "<root><field1>notf1</field1><field2>f2</field2></root>"; String test = "<root><field1>notf1</field1><field2>f2</field2></root>";
XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); assertThatExceptionOfType(AssertionError.class)
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> .isThrownBy(() -> xmlHelper.assertXmlEqual(CONTROL, test))
xmlHelper.assertXmlEqual(control, test))
.withMessageStartingWith("Body content Expected child 'field1'"); .withMessageStartingWith("Body content Expected child 'field1'");
} }
@Test @Test
void assertXmlEqualForOutOfOrder() throws Exception { void assertXmlEqualForOutOfOrder() throws Exception {
String control = "<root><field1>f1</field1><field2>f2</field2></root>";
String test = "<root><field2>f2</field2><field1>f1</field1></root>"; String test = "<root><field2>f2</field2><field1>f1</field1></root>";
XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); xmlHelper.assertXmlEqual(CONTROL, test);
xmlHelper.assertXmlEqual(control, test);
} }
@Test @Test
void assertXmlEqualExceptionForMoreEntries() { 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>"; String test = "<root><field1>f1</field1><field2>f2</field2><field3>f3</field3></root>";
XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); assertThatExceptionOfType(AssertionError.class)
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> .isThrownBy(() -> xmlHelper.assertXmlEqual(CONTROL, test))
xmlHelper.assertXmlEqual(control, test))
.withMessageContaining("Expected child nodelist length '2' but was '3'"); .withMessageContaining("Expected child nodelist length '2' but was '3'");
} }
@Test @Test
void assertXmlEqualExceptionForLessEntries() { void assertXmlEqualExceptionForFewerEntries() {
String control = "<root><field1>f1</field1><field2>f2</field2><field3>f3</field3></root>"; String control = "<root><field1>f1</field1><field2>f2</field2><field3>f3</field3></root>";
String test = "<root><field1>f1</field1><field2>f2</field2></root>"; String test = "<root><field1>f1</field1><field2>f2</field2></root>";
XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); assertThatExceptionOfType(AssertionError.class)
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> .isThrownBy(() -> xmlHelper.assertXmlEqual(control, test))
xmlHelper.assertXmlEqual(control, test))
.withMessageContaining("Expected child nodelist length '3' but was '2'"); .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'");
}
} }