Skip to content

Commit 06eaa1d

Browse files
committed
Review nullability of spring-ws-test
See gh-1562
1 parent 69673bc commit 06eaa1d

23 files changed

+94
-91
lines changed

spring-ws-test/src/main/java/org/springframework/ws/test/client/ErrorResponseCreator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ class ErrorResponseCreator implements ResponseCreator {
4040
@Override
4141
public WebServiceMessage createResponse(URI uri, WebServiceMessage request, WebServiceMessageFactory factory)
4242
throws IOException {
43-
// Do nothing
44-
return null;
43+
throw new UnsupportedOperationException();
4544
}
4645

4746
String getErrorMessage() {

spring-ws-test/src/main/java/org/springframework/ws/test/client/MockSenderConnection.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import java.net.URI;
2121
import java.util.LinkedList;
2222
import java.util.List;
23+
import java.util.Objects;
24+
25+
import org.jspecify.annotations.Nullable;
2326

2427
import org.springframework.util.Assert;
2528
import org.springframework.ws.WebServiceMessage;
@@ -38,11 +41,11 @@ class MockSenderConnection implements WebServiceConnection, ResponseActions {
3841

3942
private final List<RequestMatcher> requestMatchers = new LinkedList<>();
4043

41-
private URI uri;
44+
private @Nullable URI uri;
4245

43-
private WebServiceMessage request;
46+
private @Nullable WebServiceMessage request;
4447

45-
private ResponseCreator responseCreator;
48+
private @Nullable ResponseCreator responseCreator;
4649

4750
void addRequestMatcher(RequestMatcher requestMatcher) {
4851
Assert.notNull(requestMatcher, "'requestMatcher' must not be null");
@@ -74,7 +77,7 @@ public void andRespond(ResponseCreator responseCreator) {
7477
public void send(WebServiceMessage message) throws IOException {
7578
if (!this.requestMatchers.isEmpty()) {
7679
for (RequestMatcher requestMatcher : this.requestMatchers) {
77-
requestMatcher.match(this.uri, message);
80+
requestMatcher.match(Objects.requireNonNull(this.uri), message);
7881
}
7982
}
8083
else {
@@ -84,17 +87,18 @@ public void send(WebServiceMessage message) throws IOException {
8487
}
8588

8689
@Override
87-
public WebServiceMessage receive(WebServiceMessageFactory messageFactory) throws IOException {
90+
public @Nullable WebServiceMessage receive(WebServiceMessageFactory messageFactory) throws IOException {
8891
if (this.responseCreator != null) {
89-
return this.responseCreator.createResponse(this.uri, this.request, messageFactory);
92+
return this.responseCreator.createResponse(Objects.requireNonNull(this.uri),
93+
Objects.requireNonNull(this.request), messageFactory);
9094
}
9195
else {
9296
return null;
9397
}
9498
}
9599

96100
@Override
97-
public URI getUri() {
101+
public @Nullable URI getUri() {
98102
return this.uri;
99103
}
100104

@@ -104,7 +108,7 @@ public boolean hasError() throws IOException {
104108
}
105109

106110
@Override
107-
public String getErrorMessage() throws IOException {
111+
public @Nullable String getErrorMessage() throws IOException {
108112
if (this.responseCreator instanceof ErrorResponseCreator) {
109113
return ((ErrorResponseCreator) this.responseCreator).getErrorMessage();
110114
}

spring-ws-test/src/main/java/org/springframework/ws/test/client/MockWebServiceMessageSender.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.LinkedList;
2323
import java.util.List;
2424

25+
import org.jspecify.annotations.Nullable;
26+
2527
import org.springframework.util.Assert;
2628
import org.springframework.ws.transport.WebServiceMessageSender;
2729

@@ -38,7 +40,7 @@ public class MockWebServiceMessageSender implements WebServiceMessageSender {
3840

3941
private final List<MockSenderConnection> expectedConnections = new LinkedList<>();
4042

41-
private Iterator<MockSenderConnection> connectionIterator;
43+
private @Nullable Iterator<MockSenderConnection> connectionIterator;
4244

4345
@Override
4446
public MockSenderConnection createConnection(URI uri) throws IOException {

spring-ws-test/src/main/java/org/springframework/ws/test/client/XPathExpectationsHelperAdapter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.Map;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.ws.test.support.matcher.XPathExpectationsHelper;
2224

2325
/**
@@ -31,7 +33,7 @@ class XPathExpectationsHelperAdapter implements RequestXPathExpectations {
3133

3234
private final XPathExpectationsHelper helper;
3335

34-
XPathExpectationsHelperAdapter(String expression, Map<String, String> namespaces) {
36+
XPathExpectationsHelperAdapter(String expression, @Nullable Map<String, String> namespaces) {
3537
this.helper = new XPathExpectationsHelper(expression, namespaces);
3638
}
3739

spring-ws-test/src/main/java/org/springframework/ws/test/client/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@
1919
* the {@link org.springframework.ws.test.client.MockWebServiceServer}, and various
2020
* related test interfaces.
2121
*/
22+
@NullMarked
2223
package org.springframework.ws.test.client;
24+
25+
import org.jspecify.annotations.NullMarked;

spring-ws-test/src/main/java/org/springframework/ws/test/server/MockWebServiceClient.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.springframework.ws.context.MessageContext;
3030
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
3131
import org.springframework.ws.soap.server.SoapMessageDispatcher;
32-
import org.springframework.ws.test.support.AssertionErrors;
3332
import org.springframework.ws.test.support.MockStrategiesHelper;
3433
import org.springframework.ws.transport.WebServiceMessageReceiver;
3534

@@ -185,8 +184,7 @@ public ResponseActions sendRequest(RequestCreator requestCreator) {
185184
}
186185
catch (Exception ex) {
187186
logger.error("Could not send request", ex);
188-
AssertionErrors.fail(ex.getMessage());
189-
return null;
187+
throw new AssertionError(ex.getMessage());
190188
}
191189
}
192190

@@ -206,17 +204,15 @@ public ResponseActions andExpect(ResponseMatcher responseMatcher) {
206204
WebServiceMessage request = this.messageContext.getRequest();
207205
WebServiceMessage response = this.messageContext.getResponse();
208206
if (response == null) {
209-
AssertionErrors.fail("No response received");
210-
return null;
207+
throw new AssertionError("No response received");
211208
}
212209
try {
213210
responseMatcher.match(request, response);
214211
return this;
215212
}
216213
catch (IOException ex) {
217214
logger.error("Could not match request", ex);
218-
AssertionErrors.fail(ex.getMessage());
219-
return null;
215+
throw new AssertionError(ex.getMessage());
220216
}
221217
}
222218

spring-ws-test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import javax.xml.namespace.QName;
2424
import javax.xml.transform.Source;
2525

26+
import org.jspecify.annotations.Nullable;
27+
2628
import org.springframework.core.io.Resource;
2729
import org.springframework.util.Assert;
2830
import org.springframework.ws.FaultAwareWebServiceMessage;
@@ -160,7 +162,7 @@ public static ResponseMatcher mustUnderstandFault() {
160162
* {@code null} the fault string or reason text will not be verified
161163
* @see org.springframework.ws.soap.SoapBody#addMustUnderstandFault(String, Locale)
162164
*/
163-
public static ResponseMatcher mustUnderstandFault(String faultStringOrReason) {
165+
public static ResponseMatcher mustUnderstandFault(@Nullable String faultStringOrReason) {
164166
return new SoapFaultResponseMatcher(faultStringOrReason) {
165167
@Override
166168
protected QName getExpectedFaultCode(SoapVersion version) {
@@ -184,7 +186,7 @@ public static ResponseMatcher clientOrSenderFault() {
184186
* {@code null} the fault string or reason text will not be verified
185187
* @see org.springframework.ws.soap.SoapBody#addClientOrSenderFault(String, Locale)
186188
*/
187-
public static ResponseMatcher clientOrSenderFault(String faultStringOrReason) {
189+
public static ResponseMatcher clientOrSenderFault(@Nullable String faultStringOrReason) {
188190
return new SoapFaultResponseMatcher(faultStringOrReason) {
189191
@Override
190192
protected QName getExpectedFaultCode(SoapVersion version) {
@@ -209,7 +211,7 @@ public static ResponseMatcher serverOrReceiverFault() {
209211
* {@code null} the fault string or reason text will not be verified
210212
* @see org.springframework.ws.soap.SoapBody#addClientOrSenderFault(String, Locale)
211213
*/
212-
public static ResponseMatcher serverOrReceiverFault(String faultStringOrReason) {
214+
public static ResponseMatcher serverOrReceiverFault(@Nullable String faultStringOrReason) {
213215
return new SoapFaultResponseMatcher(faultStringOrReason) {
214216
@Override
215217
protected QName getExpectedFaultCode(SoapVersion version) {
@@ -233,7 +235,7 @@ public static ResponseMatcher versionMismatchFault() {
233235
* {@code null} the fault string or reason text will not be verified
234236
* @see org.springframework.ws.soap.SoapBody#addClientOrSenderFault(String, Locale)
235237
*/
236-
public static ResponseMatcher versionMismatchFault(String faultStringOrReason) {
238+
public static ResponseMatcher versionMismatchFault(@Nullable String faultStringOrReason) {
237239
return new SoapFaultResponseMatcher(faultStringOrReason) {
238240
@Override
239241
protected QName getExpectedFaultCode(SoapVersion version) {

spring-ws-test/src/main/java/org/springframework/ws/test/server/SoapFaultResponseMatcher.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import javax.xml.namespace.QName;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.ws.WebServiceMessage;
2426
import org.springframework.ws.soap.SoapBody;
2527
import org.springframework.ws.soap.SoapFault;
@@ -35,9 +37,9 @@
3537
*/
3638
abstract class SoapFaultResponseMatcher implements ResponseMatcher {
3739

38-
private final String expectedFaultStringOrReason;
40+
private final @Nullable String expectedFaultStringOrReason;
3941

40-
SoapFaultResponseMatcher(String expectedFaultStringOrReason) {
42+
SoapFaultResponseMatcher(@Nullable String expectedFaultStringOrReason) {
4143
this.expectedFaultStringOrReason = expectedFaultStringOrReason;
4244
}
4345

@@ -50,10 +52,11 @@ public void match(WebServiceMessage request, WebServiceMessage response) throws
5052
AssertionErrors.assertTrue("Response has no SOAP Fault", responseBody.hasFault());
5153
SoapFault soapFault = responseBody.getFault();
5254
QName expectedFaultCode = getExpectedFaultCode(soapResponse.getVersion());
53-
AssertionErrors.assertEquals("Invalid SOAP Fault code", expectedFaultCode, soapFault.getFaultCode());
55+
AssertionErrors.assertEquals("Invalid SOAP Fault code", expectedFaultCode,
56+
(soapFault != null) ? soapFault.getFaultCode() : null);
5457
if (this.expectedFaultStringOrReason != null) {
5558
AssertionErrors.assertEquals("Invalid SOAP Fault string/reason", this.expectedFaultStringOrReason,
56-
soapFault.getFaultStringOrReason());
59+
(soapFault != null) ? soapFault.getFaultStringOrReason() : null);
5760
}
5861
}
5962

spring-ws-test/src/main/java/org/springframework/ws/test/server/XPathExpectationsHelperAdapter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.Map;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.ws.test.support.matcher.XPathExpectationsHelper;
2224

2325
/**
@@ -31,7 +33,7 @@ class XPathExpectationsHelperAdapter implements ResponseXPathExpectations {
3133

3234
private final XPathExpectationsHelper helper;
3335

34-
XPathExpectationsHelperAdapter(String expression, Map<String, String> namespaces) {
36+
XPathExpectationsHelperAdapter(String expression, @Nullable Map<String, String> namespaces) {
3537
this.helper = new XPathExpectationsHelper(expression, namespaces);
3638
}
3739

spring-ws-test/src/main/java/org/springframework/ws/test/server/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@
1919
* the {@link org.springframework.ws.test.server.MockWebServiceClient}, and various
2020
* related test interfaces.
2121
*/
22+
@NullMarked
2223
package org.springframework.ws.test.server;
24+
25+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)