Skip to content

Commit 39953bb

Browse files
committed
Merge pull request #24152 from gesellix
* pr/24152: Polish "Check that WebClient is available" Check that WebClient is available Closes gh-24152
2 parents b1678ee + f248cfe commit 39953bb

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/reactive/server/WebTestClientContextCustomizerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public ContextCustomizer createContextCustomizer(Class<?> testClass,
3939
List<ContextConfigurationAttributes> configAttributes) {
4040
SpringBootTest springBootTest = TestContextAnnotationUtils.findMergedAnnotation(testClass,
4141
SpringBootTest.class);
42-
return (springBootTest != null) ? new WebTestClientContextCustomizer() : null;
42+
return (springBootTest != null && isWebClientPresent()) ? new WebTestClientContextCustomizer() : null;
4343
}
4444

4545
private boolean isWebClientPresent() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2012-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.boot.test.web.reactive.server;
17+
18+
import java.util.Collections;
19+
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.boot.test.context.SpringBootTest;
23+
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
24+
import org.springframework.test.context.ContextCustomizer;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
/**
29+
* Tests for {@link WebTestClientContextCustomizerFactory} when spring webflux is not on
30+
* the classpath.
31+
*
32+
* @author Tobias Gesellchen
33+
* @author Stephane Nicoll
34+
*/
35+
@ClassPathExclusions("spring-webflux*.jar")
36+
public class WebTestClientContextCustomizerWithoutWebfluxIntegrationTests {
37+
38+
@Test
39+
void customizerIsNotCreatedWithoutWebClient() {
40+
WebTestClientContextCustomizerFactory contextCustomizerFactory = new WebTestClientContextCustomizerFactory();
41+
ContextCustomizer contextCustomizer = contextCustomizerFactory.createContextCustomizer(TestClass.class,
42+
Collections.emptyList());
43+
assertThat(contextCustomizer).isNull();
44+
}
45+
46+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
47+
private static class TestClass {
48+
49+
}
50+
51+
}

0 commit comments

Comments
 (0)