Skip to content

Commit dd7369d

Browse files
committed
WiretapConnector.Info is private
The claimRequest method was not intended to be public and couldn't have been used since the Info type it returned was package private. This change completely hides the Info. See gh-19647
1 parent 4116e6d commit dd7369d

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -306,8 +306,8 @@ public RequestHeadersSpec<?> syncBody(Object body) {
306306
public ResponseSpec exchange() {
307307
ClientResponse clientResponse = this.bodySpec.exchange().block(getTimeout());
308308
Assert.state(clientResponse != null, "No ClientResponse");
309-
WiretapConnector.Info info = wiretapConnector.claimRequest(this.requestId);
310-
return new DefaultResponseSpec(info, clientResponse, this.uriTemplate, getTimeout());
309+
ExchangeResult result = wiretapConnector.getExchangeResult(this.requestId, this.uriTemplate, getTimeout());
310+
return new DefaultResponseSpec(result, clientResponse, getTimeout());
311311
}
312312
}
313313

@@ -321,10 +321,8 @@ private static class DefaultResponseSpec implements ResponseSpec {
321321
private final Duration timeout;
322322

323323

324-
DefaultResponseSpec(WiretapConnector.Info wiretapInfo, ClientResponse response,
325-
@Nullable String uriTemplate, Duration timeout) {
326-
327-
this.exchangeResult = wiretapInfo.createExchangeResult(timeout, uriTemplate);
324+
DefaultResponseSpec(ExchangeResult exchangeResult, ClientResponse response, Duration timeout) {
325+
this.exchangeResult = exchangeResult;
328326
this.response = response;
329327
this.timeout = timeout;
330328
}

spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -53,7 +53,7 @@ class WiretapConnector implements ClientHttpConnector {
5353

5454
private final ClientHttpConnector delegate;
5555

56-
private final Map<String, Info> exchanges = new ConcurrentHashMap<>();
56+
private final Map<String, ClientExchangeInfo> exchanges = new ConcurrentHashMap<>();
5757

5858

5959
WiretapConnector(ClientHttpConnector delegate) {
@@ -79,43 +79,47 @@ public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri,
7979
String requestId = wrappedRequest.getHeaders().getFirst(header);
8080
Assert.state(requestId != null, () -> "No \"" + header + "\" header");
8181
WiretapClientHttpResponse wrappedResponse = new WiretapClientHttpResponse(response);
82-
this.exchanges.put(requestId, new Info(wrappedRequest, wrappedResponse));
82+
this.exchanges.put(requestId, new ClientExchangeInfo(wrappedRequest, wrappedResponse));
8383
return wrappedResponse;
8484
});
8585
}
8686

8787
/**
88-
* Retrieve the {@link Info} for the given "request-id" header value.
88+
* Create the {@link ExchangeResult} for the given "request-id" header value.
8989
*/
90-
public Info claimRequest(String requestId) {
91-
Info info = this.exchanges.remove(requestId);
90+
ExchangeResult getExchangeResult(String requestId, @Nullable String uriTemplate, Duration timeout) {
91+
ClientExchangeInfo info = this.exchanges.remove(requestId);
9292
Assert.state(info != null, () -> {
9393
String header = WebTestClient.WEBTESTCLIENT_REQUEST_ID;
9494
return "No match for " + header + "=" + requestId;
9595
});
96-
return info;
96+
return new ExchangeResult(info.getRequest(), info.getResponse(),
97+
info.getRequest().getRecorder().getContent(),
98+
info.getResponse().getRecorder().getContent(),
99+
timeout, uriTemplate);
97100
}
98101

99102

100103
/**
101104
* Holder for {@link WiretapClientHttpRequest} and {@link WiretapClientHttpResponse}.
102105
*/
103-
class Info {
106+
private static class ClientExchangeInfo {
104107

105108
private final WiretapClientHttpRequest request;
106109

107110
private final WiretapClientHttpResponse response;
108111

109-
110-
public Info(WiretapClientHttpRequest request, WiretapClientHttpResponse response) {
112+
public ClientExchangeInfo(WiretapClientHttpRequest request, WiretapClientHttpResponse response) {
111113
this.request = request;
112114
this.response = response;
113115
}
114116

117+
public WiretapClientHttpRequest getRequest() {
118+
return this.request;
119+
}
115120

116-
public ExchangeResult createExchangeResult(Duration timeout, @Nullable String uriTemplate) {
117-
return new ExchangeResult(this.request, this.response, this.request.getRecorder().getContent(),
118-
this.response.getRecorder().getContent(), timeout, uriTemplate);
121+
public WiretapClientHttpResponse getResponse() {
122+
return this.response;
119123
}
120124
}
121125

spring-test/src/test/java/org/springframework/test/web/reactive/server/WiretapConnectorTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -57,8 +57,7 @@ public void captureAndClaim() {
5757
ExchangeFunction function = ExchangeFunctions.create(wiretapConnector);
5858
function.exchange(clientRequest).block(ofMillis(0));
5959

60-
WiretapConnector.Info actual = wiretapConnector.claimRequest("1");
61-
ExchangeResult result = actual.createExchangeResult(Duration.ZERO, null);
60+
ExchangeResult result = wiretapConnector.getExchangeResult("1", null, Duration.ZERO);
6261
assertThat(result.getMethod()).isEqualTo(HttpMethod.GET);
6362
assertThat(result.getUrl().toString()).isEqualTo("/test");
6463
}

0 commit comments

Comments
 (0)