|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -57,13 +57,17 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder {
|
57 | 57 |
|
58 | 58 | private static final boolean httpComponentsClientPresent;
|
59 | 59 |
|
| 60 | + private static final boolean webFluxPresent; |
| 61 | + |
60 | 62 | static {
|
61 | 63 | ClassLoader loader = DefaultWebTestClientBuilder.class.getClassLoader();
|
62 | 64 | reactorClientPresent = ClassUtils.isPresent("reactor.netty.http.client.HttpClient", loader);
|
63 | 65 | jettyClientPresent = ClassUtils.isPresent("org.eclipse.jetty.client.HttpClient", loader);
|
64 | 66 | httpComponentsClientPresent =
|
65 | 67 | ClassUtils.isPresent("org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient", loader) &&
|
66 | 68 | ClassUtils.isPresent("org.apache.hc.core5.reactive.ReactiveDataConsumer", loader);
|
| 69 | + webFluxPresent = ClassUtils.isPresent( |
| 70 | + "org.springframework.web.reactive.function.client.ExchangeFunction", loader); |
67 | 71 | }
|
68 | 72 |
|
69 | 73 |
|
@@ -119,6 +123,10 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder {
|
119 | 123 | Assert.isTrue(httpHandlerBuilder == null || connector == null,
|
120 | 124 | "Expected WebHttpHandlerBuilder or ClientHttpConnector but not both.");
|
121 | 125 |
|
| 126 | + // Helpful message especially for MockMvcWebTestClient users |
| 127 | + Assert.state(webFluxPresent, |
| 128 | + "To use WebTestClient, please add spring-webflux to the test classpath."); |
| 129 | + |
122 | 130 | this.connector = connector;
|
123 | 131 | this.httpHandlerBuilder = (httpHandlerBuilder != null ? httpHandlerBuilder.clone() : null);
|
124 | 132 | }
|
|
0 commit comments