diff --git a/module/spring-boot-webclient-test/build.gradle b/module/spring-boot-webclient-test/build.gradle index 00a7b00d94a..b9ba510320e 100644 --- a/module/spring-boot-webclient-test/build.gradle +++ b/module/spring-boot-webclient-test/build.gradle @@ -40,3 +40,7 @@ dependencies { testRuntimeOnly("ch.qos.logback:logback-classic") } + +tasks.named("compileTestJava") { + options.nullability.checking = "tests" +} diff --git a/module/spring-boot-webclient-test/src/test/java/org/springframework/boot/webclient/test/autoconfigure/AnotherExampleWebClientService.java b/module/spring-boot-webclient-test/src/test/java/org/springframework/boot/webclient/test/autoconfigure/AnotherExampleWebClientService.java index 07193bb3d18..dcbefc427a4 100644 --- a/module/spring-boot-webclient-test/src/test/java/org/springframework/boot/webclient/test/autoconfigure/AnotherExampleWebClientService.java +++ b/module/spring-boot-webclient-test/src/test/java/org/springframework/boot/webclient/test/autoconfigure/AnotherExampleWebClientService.java @@ -16,9 +16,14 @@ package org.springframework.boot.webclient.test.autoconfigure; +import org.jspecify.annotations.Nullable; + +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; +import static org.assertj.core.api.Assertions.assertThat; + /** * A second example web client used with {@link WebClientTest @WebClientTest} tests. * @@ -40,8 +45,10 @@ public class AnotherExampleWebClientService { return this.builder; } - public String test() { - return this.webClient.get().uri("/test").retrieve().toEntity(String.class).block().getBody(); + public @Nullable String test() { + ResponseEntity response = this.webClient.get().uri("/test").retrieve().toEntity(String.class).block(); + assertThat(response).isNotNull(); + return response.getBody(); } } diff --git a/module/spring-boot-webclient-test/src/test/java/org/springframework/boot/webclient/test/autoconfigure/ExampleWebClientService.java b/module/spring-boot-webclient-test/src/test/java/org/springframework/boot/webclient/test/autoconfigure/ExampleWebClientService.java index 7a05cd769e8..95f219f2432 100644 --- a/module/spring-boot-webclient-test/src/test/java/org/springframework/boot/webclient/test/autoconfigure/ExampleWebClientService.java +++ b/module/spring-boot-webclient-test/src/test/java/org/springframework/boot/webclient/test/autoconfigure/ExampleWebClientService.java @@ -16,9 +16,14 @@ package org.springframework.boot.webclient.test.autoconfigure; +import org.jspecify.annotations.Nullable; + +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; +import static org.assertj.core.api.Assertions.assertThat; + /** * Example web client using {@code WebClient} with {@link WebClientTest @WebClientTest} * tests. @@ -41,8 +46,10 @@ public class ExampleWebClientService { return this.builder; } - public String test() { - return this.webClient.get().uri("/test").retrieve().toEntity(String.class).block().getBody(); + public @Nullable String test() { + ResponseEntity response = this.webClient.get().uri("/test").retrieve().toEntity(String.class).block(); + assertThat(response).isNotNull(); + return response.getBody(); } public void testPostWithBody(String body) {