|
27 | 27 | */
|
28 | 28 | class XmlExpectationsHelperTests {
|
29 | 29 |
|
| 30 | + private static final String CONTROL = "<root><field1>f1</field1><field2>f2</field2></root>"; |
| 31 | + |
| 32 | + private final XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); |
| 33 | + |
| 34 | + |
30 | 35 | @Test
|
31 | 36 | void assertXmlEqualForEqual() throws Exception {
|
32 |
| - String control = "<root><field1>f1</field1><field2>f2</field2></root>"; |
33 | 37 | String test = "<root><field1>f1</field1><field2>f2</field2></root>";
|
34 |
| - XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); |
35 |
| - xmlHelper.assertXmlEqual(control, test); |
| 38 | + xmlHelper.assertXmlEqual(CONTROL, test); |
36 | 39 | }
|
37 | 40 |
|
38 | 41 | @Test
|
39 | 42 | void assertXmlEqualExceptionForIncorrectValue() {
|
40 |
| - String control = "<root><field1>f1</field1><field2>f2</field2></root>"; |
41 | 43 | String test = "<root><field1>notf1</field1><field2>f2</field2></root>";
|
42 |
| - XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); |
43 |
| - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> |
44 |
| - xmlHelper.assertXmlEqual(control, test)) |
45 |
| - .withMessageStartingWith("Body content Expected child 'field1'"); |
| 44 | + assertThatExceptionOfType(AssertionError.class) |
| 45 | + .isThrownBy(() -> xmlHelper.assertXmlEqual(CONTROL, test)) |
| 46 | + .withMessageStartingWith("Body content Expected child 'field1'"); |
46 | 47 | }
|
47 | 48 |
|
48 | 49 | @Test
|
49 | 50 | void assertXmlEqualForOutOfOrder() throws Exception {
|
50 |
| - String control = "<root><field1>f1</field1><field2>f2</field2></root>"; |
51 | 51 | String test = "<root><field2>f2</field2><field1>f1</field1></root>";
|
52 |
| - XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); |
53 |
| - xmlHelper.assertXmlEqual(control, test); |
| 52 | + xmlHelper.assertXmlEqual(CONTROL, test); |
54 | 53 | }
|
55 | 54 |
|
56 | 55 | @Test
|
57 | 56 | void assertXmlEqualExceptionForMoreEntries() {
|
58 |
| - String control = "<root><field1>f1</field1><field2>f2</field2></root>"; |
59 | 57 | String test = "<root><field1>f1</field1><field2>f2</field2><field3>f3</field3></root>";
|
60 |
| - XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); |
61 |
| - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> |
62 |
| - xmlHelper.assertXmlEqual(control, test)) |
63 |
| - .withMessageContaining("Expected child nodelist length '2' but was '3'"); |
| 58 | + assertThatExceptionOfType(AssertionError.class) |
| 59 | + .isThrownBy(() -> xmlHelper.assertXmlEqual(CONTROL, test)) |
| 60 | + .withMessageContaining("Expected child nodelist length '2' but was '3'"); |
64 | 61 |
|
65 | 62 | }
|
66 | 63 |
|
67 | 64 | @Test
|
68 |
| - void assertXmlEqualExceptionForLessEntries() { |
| 65 | + void assertXmlEqualExceptionForFewerEntries() { |
69 | 66 | String control = "<root><field1>f1</field1><field2>f2</field2><field3>f3</field3></root>";
|
70 | 67 | String test = "<root><field1>f1</field1><field2>f2</field2></root>";
|
71 |
| - XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); |
72 |
| - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> |
73 |
| - xmlHelper.assertXmlEqual(control, test)) |
74 |
| - .withMessageContaining("Expected child nodelist length '3' but was '2'"); |
| 68 | + assertThatExceptionOfType(AssertionError.class) |
| 69 | + .isThrownBy(() -> xmlHelper.assertXmlEqual(control, test)) |
| 70 | + .withMessageContaining("Expected child nodelist length '3' but was '2'"); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + void assertXmlEqualExceptionWithFullDescription() { |
| 75 | + String test = "<root><field2>f2</field2><field3>f3</field3></root>"; |
| 76 | + assertThatExceptionOfType(AssertionError.class) |
| 77 | + .isThrownBy(() -> xmlHelper.assertXmlEqual(CONTROL, test)) |
| 78 | + .withMessageContaining("Expected child 'field1' but was 'null'") |
| 79 | + .withMessageContaining("Expected child 'null' but was 'field3'"); |
75 | 80 | }
|
76 | 81 |
|
77 | 82 | }
|
0 commit comments