Add nullability annotations to tests in module/spring-boot-webclient-test

See gh-47263
This commit is contained in:
Moritz Halbritter
2025-10-15 16:58:21 +02:00
parent a97975df25
commit 969c23f34a
3 changed files with 22 additions and 4 deletions
@@ -40,3 +40,7 @@ dependencies {
testRuntimeOnly("ch.qos.logback:logback-classic")
}
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}
@@ -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<String> response = this.webClient.get().uri("/test").retrieve().toEntity(String.class).block();
assertThat(response).isNotNull();
return response.getBody();
}
}
@@ -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<String> response = this.webClient.get().uri("/test").retrieve().toEntity(String.class).block();
assertThat(response).isNotNull();
return response.getBody();
}
public void testPostWithBody(String body) {