diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java index 8e1904f311..4a398e19a5 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,6 +57,8 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder { private static final boolean httpComponentsClientPresent; + private static final boolean webFluxPresent; + static { ClassLoader loader = DefaultWebTestClientBuilder.class.getClassLoader(); reactorClientPresent = ClassUtils.isPresent("reactor.netty.http.client.HttpClient", loader); @@ -64,6 +66,8 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder { httpComponentsClientPresent = ClassUtils.isPresent("org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient", loader) && ClassUtils.isPresent("org.apache.hc.core5.reactive.ReactiveDataConsumer", loader); + webFluxPresent = ClassUtils.isPresent( + "org.springframework.web.reactive.function.client.ExchangeFunction", loader); } @@ -119,6 +123,10 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder { Assert.isTrue(httpHandlerBuilder == null || connector == null, "Expected WebHttpHandlerBuilder or ClientHttpConnector but not both."); + // Helpful message especially for MockMvcWebTestClient users + Assert.state(webFluxPresent, + "To use WebTestClient, please add spring-webflux to the test classpath."); + this.connector = connector; this.httpHandlerBuilder = (httpHandlerBuilder != null ? httpHandlerBuilder.clone() : null); }