Skip to content

Commit 4263be2

Browse files
committed
Polishing.
See #1203.
1 parent 72ef3ad commit 4263be2

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

spring-ws-test/src/main/java/org/springframework/ws/test/support/matcher/xmlunit2/PayloadDiffMatcher.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.ws.test.support.matcher.xmlunit2;
1818

19-
import static org.springframework.ws.test.support.AssertionErrors.fail;
19+
import static org.springframework.ws.test.support.AssertionErrors.*;
2020

2121
import javax.xml.transform.Source;
2222
import javax.xml.transform.TransformerException;
@@ -33,6 +33,7 @@
3333
* Matches {@link Source} payloads.
3434
*
3535
* @author Greg Turnquist
36+
* @author Mikołaj Fejzer
3637
* @since 4.0
3738
*/
3839
public class PayloadDiffMatcher extends DiffMatcher {
@@ -42,22 +43,28 @@ public class PayloadDiffMatcher extends DiffMatcher {
4243
private final TransformerHelper transformerHelper = new TransformerHelper();
4344

4445
public PayloadDiffMatcher(Source expected) {
46+
4547
Assert.notNull(expected, "'expected' must not be null");
4648
this.expected = expected;
4749
}
4850

4951
@Override
5052
protected final Diff createDiff(WebServiceMessage message) {
53+
5154
Source payload = message.getPayloadSource();
55+
5256
if (payload == null) {
5357
fail("Request message does not contain payload");
5458
}
59+
5560
return createDiff(payload);
5661
}
5762

5863
protected Diff createDiff(Source payload) {
64+
5965
Document expectedDocument = createDocumentFromSource(expected);
6066
Document actualDocument = createDocumentFromSource(payload);
67+
6168
return DiffBuilder.compare(expectedDocument) //
6269
.withTest(actualDocument) //
6370
.ignoreWhitespace() //
@@ -66,11 +73,14 @@ protected Diff createDiff(Source payload) {
6673
}
6774

6875
private Document createDocumentFromSource(Source source) {
76+
6977
try {
78+
7079
DOMResult result = new DOMResult();
7180
transformerHelper.transform(source, result);
7281
return (Document) result.getNode();
7382
} catch (TransformerException ex) {
83+
7484
fail("Could not transform source to DOMResult" + ex.getMessage());
7585
return null;
7686
}

spring-ws-test/src/test/java/org/springframework/ws/test/support/matcher/xmlunit2/PayloadDiffMatcherTest.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@
1616

1717
package org.springframework.ws.test.support.matcher.xmlunit2;
1818

19-
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
20-
import static org.easymock.EasyMock.createMock;
21-
import static org.easymock.EasyMock.expect;
22-
import static org.easymock.EasyMock.replay;
23-
import static org.easymock.EasyMock.verify;
19+
import static org.assertj.core.api.Assertions.*;
20+
import static org.easymock.EasyMock.*;
2421

2522
import jakarta.xml.soap.MessageFactory;
2623

2724
import org.junit.jupiter.api.Test;
2825
import org.springframework.ws.WebServiceMessage;
29-
import org.springframework.ws.soap.SoapMessage;
3026
import org.springframework.ws.soap.saaj.SaajSoapMessage;
3127
import org.springframework.xml.transform.StringSource;
3228

@@ -35,12 +31,13 @@ public class PayloadDiffMatcherTest {
3531
@Test
3632
public void match() {
3733

38-
String xml = "<element xmlns='http://example.com'/>";
34+
var xml = "<element xmlns='http://example.com'/>";
3935
WebServiceMessage message = createMock(WebServiceMessage.class);
36+
4037
expect(message.getPayloadSource()).andReturn(new StringSource(xml)).times(2);
4138
replay(message);
4239

43-
PayloadDiffMatcher matcher = new PayloadDiffMatcher(new StringSource(xml));
40+
var matcher = new PayloadDiffMatcher(new StringSource(xml));
4441
matcher.match(message);
4542

4643
verify(message);
@@ -49,31 +46,32 @@ public void match() {
4946
@Test
5047
public void matchIgnoringWhitespace() {
5148

52-
String xml = "<response><success>true</success></response>";
53-
String xmlWithAdditionalWhitespace = "<response> <success>true</success> </response>";
49+
var xml = "<response><success>true</success></response>";
50+
var xmlWithAdditionalWhitespace = "<response> <success>true</success> </response>";
5451
WebServiceMessage message = createMock(WebServiceMessage.class);
52+
5553
expect(message.getPayloadSource()).andReturn(new StringSource(xml)).times(2);
5654
replay(message);
5755

58-
PayloadDiffMatcher matcher = new PayloadDiffMatcher(new StringSource(xmlWithAdditionalWhitespace));
56+
var matcher = new PayloadDiffMatcher(new StringSource(xmlWithAdditionalWhitespace));
5957
matcher.match(message);
6058

6159
verify(message);
6260
}
6361

64-
6562
@Test
6663
public void nonMatch() {
6764

6865
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> {
6966

70-
String actual = "<element1 xmlns='http://example.com'/>";
67+
var actual = "<element1 xmlns='http://example.com'/>";
7168
WebServiceMessage message = createMock(WebServiceMessage.class);
69+
7270
expect(message.getPayloadSource()).andReturn(new StringSource(actual)).times(2);
7371
replay(message);
7472

75-
String expected = "<element2 xmlns='http://example.com'/>";
76-
PayloadDiffMatcher matcher = new PayloadDiffMatcher(new StringSource(expected));
73+
var expected = "<element2 xmlns='http://example.com'/>";
74+
var matcher = new PayloadDiffMatcher(new StringSource(expected));
7775
matcher.match(message);
7876
});
7977
}
@@ -83,12 +81,11 @@ public void noPayload() {
8381

8482
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> {
8583

86-
PayloadDiffMatcher matcher = new PayloadDiffMatcher(new StringSource("<message/>"));
87-
MessageFactory messageFactory = MessageFactory.newInstance();
88-
SoapMessage soapMessage = new SaajSoapMessage(messageFactory.createMessage());
84+
var matcher = new PayloadDiffMatcher(new StringSource("<message/>"));
85+
var messageFactory = MessageFactory.newInstance();
86+
var soapMessage = new SaajSoapMessage(messageFactory.createMessage());
8987

9088
matcher.createDiff(soapMessage);
9189
});
9290
}
93-
9491
}

0 commit comments

Comments
 (0)