Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Jan 16, 2024
1 parent dc5a21f commit 1b312b6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,37 +185,34 @@ private class DefaultRequestBodyUriSpec implements RequestBodyUriSpec {

private final Map<String, Object> attributes = new LinkedHashMap<>(4);

@Nullable
private Consumer<ClientHttpRequest> httpRequestConsumer;

@Nullable
private String uriTemplate;

private final String requestId;

DefaultRequestBodyUriSpec(HttpMethod httpMethod) {
this.httpMethod = httpMethod;
this.requestId = String.valueOf(requestIndex.incrementAndGet());
this.requestId = String.valueOf(DefaultWebTestClient.this.requestIndex.incrementAndGet());
this.headers = new HttpHeaders();
this.headers.add(WebTestClient.WEBTESTCLIENT_REQUEST_ID, this.requestId);
}

@Override
public RequestBodySpec uri(String uriTemplate, Object... uriVariables) {
this.uriTemplate = uriTemplate;
return uri(uriBuilderFactory.expand(uriTemplate, uriVariables));
return uri(DefaultWebTestClient.this.uriBuilderFactory.expand(uriTemplate, uriVariables));
}

@Override
public RequestBodySpec uri(String uriTemplate, Map<String, ?> uriVariables) {
this.uriTemplate = uriTemplate;
return uri(uriBuilderFactory.expand(uriTemplate, uriVariables));
return uri(DefaultWebTestClient.this.uriBuilderFactory.expand(uriTemplate, uriVariables));
}

@Override
public RequestBodySpec uri(Function<UriBuilder, URI> uriFunction) {
this.uriTemplate = null;
return uri(uriFunction.apply(uriBuilderFactory.builder()));
return uri(uriFunction.apply(DefaultWebTestClient.this.uriBuilderFactory.builder()));
}

@Override
Expand Down Expand Up @@ -358,45 +355,39 @@ public ResponseSpec exchange() {
initRequestBuilder().body(this.inserter).build() :
initRequestBuilder().build());

ClientResponse response = exchangeFunction.exchange(request).block(getResponseTimeout());
ClientResponse response = DefaultWebTestClient.this.exchangeFunction.exchange(request).block(getResponseTimeout());
Assert.state(response != null, "No ClientResponse");

ExchangeResult result = wiretapConnector.getExchangeResult(
ExchangeResult result = DefaultWebTestClient.this.wiretapConnector.getExchangeResult(
this.requestId, this.uriTemplate, getResponseTimeout());

return new DefaultResponseSpec(result, response,
DefaultWebTestClient.this.entityResultConsumer, getResponseTimeout());
}

private ClientRequest.Builder initRequestBuilder() {
ClientRequest.Builder builder = ClientRequest.create(this.httpMethod, initUri())
return ClientRequest.create(this.httpMethod, initUri())
.headers(headersToUse -> {
if (!CollectionUtils.isEmpty(defaultHeaders)) {
headersToUse.putAll(defaultHeaders);
if (!CollectionUtils.isEmpty(DefaultWebTestClient.this.defaultHeaders)) {
headersToUse.putAll(DefaultWebTestClient.this.defaultHeaders);
}
if (!CollectionUtils.isEmpty(this.headers)) {
headersToUse.putAll(this.headers);
}
})
.cookies(cookiesToUse -> {
if (!CollectionUtils.isEmpty(defaultCookies)) {
cookiesToUse.putAll(defaultCookies);
if (!CollectionUtils.isEmpty(DefaultWebTestClient.this.defaultCookies)) {
cookiesToUse.putAll(DefaultWebTestClient.this.defaultCookies);
}
if (!CollectionUtils.isEmpty(this.cookies)) {
cookiesToUse.putAll(this.cookies);
}
})
.attributes(attributes -> attributes.putAll(this.attributes));

if (this.httpRequestConsumer != null) {
builder.httpRequest(this.httpRequestConsumer);
}

return builder;
}

private URI initUri() {
return (this.uri != null ? this.uri : uriBuilderFactory.expand(""));
return (this.uri != null ? this.uri : DefaultWebTestClient.this.uriBuilderFactory.expand(""));
}

}
Expand Down Expand Up @@ -520,9 +511,7 @@ public ResponseSpec expectAll(ResponseSpecConsumer... consumers) {
// that is not a RuntimeException, but since ExceptionCollector may
// throw a checked Exception, we handle this to appease the compiler
// and in case someone uses a "sneaky throws" technique.
AssertionError assertionError = new AssertionError(ex.getMessage());
assertionError.initCause(ex);
throw assertionError;
throw new AssertionError(ex.getMessage(), ex);
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public WebTestClient.Builder exchangeStrategies(ExchangeStrategies strategies) {
}

@Override
@SuppressWarnings("deprecation")
@Deprecated
public WebTestClient.Builder exchangeStrategies(Consumer<ExchangeStrategies.Builder> configurer) {
if (this.strategiesConfigurers == null) {
this.strategiesConfigurers = new ArrayList<>(4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
*/
public class HttpHandlerConnector implements ClientHttpConnector {

private static Log logger = LogFactory.getLog(HttpHandlerConnector.class);
private static final Log logger = LogFactory.getLog(HttpHandlerConnector.class);

private final HttpHandler handler;

Expand Down

0 comments on commit 1b312b6

Please sign in to comment.