Skip to content

Commit a3c132c

Browse files
committed
Polish XmlExpectationsHelper[Tests]
1 parent 91791c1 commit a3c132c

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java

+19-25
Original file line numberDiff line numberDiff line change
@@ -27,60 +27,54 @@
2727
*/
2828
class XmlExpectationsHelperTests {
2929

30+
private static final String CONTROL = "<root><field1>f1</field1><field2>f2</field2></root>";
31+
32+
private final XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper();
33+
34+
3035
@Test
3136
void assertXmlEqualForEqual() throws Exception {
32-
String control = "<root><field1>f1</field1><field2>f2</field2></root>";
3337
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);
3639
}
3740

3841
@Test
3942
void assertXmlEqualExceptionForIncorrectValue() {
40-
String control = "<root><field1>f1</field1><field2>f2</field2></root>";
4143
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'");
4647
}
4748

4849
@Test
4950
void assertXmlEqualForOutOfOrder() throws Exception {
50-
String control = "<root><field1>f1</field1><field2>f2</field2></root>";
5151
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);
5453
}
5554

5655
@Test
5756
void assertXmlEqualExceptionForMoreEntries() {
58-
String control = "<root><field1>f1</field1><field2>f2</field2></root>";
5957
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'");
6461

6562
}
6663

6764
@Test
68-
void assertXmlEqualExceptionForLessEntries() {
65+
void assertXmlEqualExceptionForFewerEntries() {
6966
String control = "<root><field1>f1</field1><field2>f2</field2><field3>f3</field3></root>";
7067
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'");
7571
}
7672

7773
@Test
7874
void assertXmlEqualExceptionWithFullDescription() {
79-
String control = "<root><field1>f1</field1><field2>f2</field2></root>";
8075
String test = "<root><field2>f2</field2><field3>f3</field3></root>";
81-
XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper();
82-
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
83-
xmlHelper.assertXmlEqual(control, test))
76+
assertThatExceptionOfType(AssertionError.class)
77+
.isThrownBy(() -> xmlHelper.assertXmlEqual(CONTROL, test))
8478
.withMessageContaining("Expected child 'field1' but was 'null'")
8579
.withMessageContaining("Expected child 'null' but was 'field3'");
8680
}

0 commit comments

Comments
 (0)