Add nullability annotations to tests in smoke-test/spring-boot-smoke-test-webflux

See gh-47263
This commit is contained in:
Moritz Halbritter
2025-10-16 11:24:50 +02:00
parent 8fad79753c
commit 3818c21eb3
3 changed files with 22 additions and 5 deletions
@@ -30,3 +30,7 @@ dependencies {
testImplementation(project(":starter:spring-boot-starter-webflux-test"))
testImplementation("io.projectreactor:reactor-test")
}
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}
@@ -16,6 +16,9 @@
package smoketest.webflux;
import java.util.function.Consumer;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
@@ -77,6 +80,7 @@ class SampleWebFluxApplicationIntegrationTests {
@Test
void templated404ErrorPage() {
Consumer<@Nullable String> test = (body) -> assertThat(body).isEqualToNormalizingNewlines("404 page\n");
this.webClient.get()
.uri("/404")
.accept(MediaType.TEXT_HTML)
@@ -84,11 +88,12 @@ class SampleWebFluxApplicationIntegrationTests {
.expectStatus()
.isNotFound()
.expectBody(String.class)
.value((body) -> assertThat(body).isEqualToNormalizingNewlines("404 page\n"));
.value(test);
}
@Test
void templated4xxErrorPage() {
Consumer<@Nullable String> test = (body) -> assertThat(body).isEqualToNormalizingNewlines("4xx page\n");
this.webClient.get()
.uri("/bad-request")
.accept(MediaType.TEXT_HTML)
@@ -96,11 +101,13 @@ class SampleWebFluxApplicationIntegrationTests {
.expectStatus()
.isBadRequest()
.expectBody(String.class)
.value((body) -> assertThat(body).isEqualToNormalizingNewlines("4xx page\n"));
.value(test);
}
@Test
void htmlErrorPage() {
Consumer<@Nullable String> test = (body) -> assertThat(body).contains("status: 500")
.contains("message: Expected!");
this.webClient.get()
.uri("/five-hundred")
.accept(MediaType.TEXT_HTML)
@@ -108,7 +115,7 @@ class SampleWebFluxApplicationIntegrationTests {
.expectStatus()
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR)
.expectBody(String.class)
.value((body) -> assertThat(body).contains("status: 500").contains("message: Expected!"));
.value(test);
}
}
@@ -17,7 +17,9 @@
package smoketest.webflux;
import java.util.Map;
import java.util.function.Consumer;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
@@ -61,6 +63,8 @@ class SampleWebFluxApplicationTests {
@Test
void testBadRequest() {
Consumer<@Nullable Map<String, Object>> test = (content) -> assertThat(content).containsEntry("path",
"/bad-request");
this.webClient.get()
.uri("/bad-request")
.accept(MediaType.APPLICATION_JSON)
@@ -68,11 +72,13 @@ class SampleWebFluxApplicationTests {
.expectStatus()
.isBadRequest()
.expectBody(MAP_TYPE)
.value((content) -> assertThat(content).containsEntry("path", "/bad-request"));
.value(test);
}
@Test
void testServerError() {
Consumer<@Nullable Map<String, Object>> test = (content) -> assertThat(content).containsEntry("path",
"/five-hundred");
this.webClient.get()
.uri("/five-hundred")
.accept(MediaType.APPLICATION_JSON)
@@ -80,7 +86,7 @@ class SampleWebFluxApplicationTests {
.expectStatus()
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR)
.expectBody(MAP_TYPE)
.value((content) -> assertThat(content).containsEntry("path", "/five-hundred"));
.value(test);
}
}