Skip to content

Commit fb2e532

Browse files
committed
Assert WebFlux present for WebTestClient
Closes gh-26308
1 parent c040cd7 commit fb2e532

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 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,13 +57,17 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder {
5757

5858
private static final boolean httpComponentsClientPresent;
5959

60+
private static final boolean webFluxPresent;
61+
6062
static {
6163
ClassLoader loader = DefaultWebTestClientBuilder.class.getClassLoader();
6264
reactorClientPresent = ClassUtils.isPresent("reactor.netty.http.client.HttpClient", loader);
6365
jettyClientPresent = ClassUtils.isPresent("org.eclipse.jetty.client.HttpClient", loader);
6466
httpComponentsClientPresent =
6567
ClassUtils.isPresent("org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient", loader) &&
6668
ClassUtils.isPresent("org.apache.hc.core5.reactive.ReactiveDataConsumer", loader);
69+
webFluxPresent = ClassUtils.isPresent(
70+
"org.springframework.web.reactive.function.client.ExchangeFunction", loader);
6771
}
6872

6973

@@ -119,6 +123,10 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder {
119123
Assert.isTrue(httpHandlerBuilder == null || connector == null,
120124
"Expected WebHttpHandlerBuilder or ClientHttpConnector but not both.");
121125

126+
// Helpful message especially for MockMvcWebTestClient users
127+
Assert.state(webFluxPresent,
128+
"To use WebTestClient, please add spring-webflux to the test classpath.");
129+
122130
this.connector = connector;
123131
this.httpHandlerBuilder = (httpHandlerBuilder != null ? httpHandlerBuilder.clone() : null);
124132
}

0 commit comments

Comments
 (0)