From a1a7d8d9891d27c389f4e2952cd047e146d4b5d7 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Thu, 16 Oct 2025 09:59:09 +0200 Subject: [PATCH] Add nullability annotations to tests in smoke-test/spring-boot-smoke-test-web-secure See gh-47263 --- .../spring-boot-smoke-test-web-secure/build.gradle | 4 ++++ .../smoketest/web/secure/AbstractErrorPageTests.java | 2 ++ .../secure/AbstractUnauthenticatedErrorPageTests.java | 6 ++++++ .../web/secure/SampleWebSecureApplicationTests.java | 9 +++++++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/smoke-test/spring-boot-smoke-test-web-secure/build.gradle b/smoke-test/spring-boot-smoke-test-web-secure/build.gradle index 95140a5e62c..3a009a47c21 100644 --- a/smoke-test/spring-boot-smoke-test-web-secure/build.gradle +++ b/smoke-test/spring-boot-smoke-test-web-secure/build.gradle @@ -28,3 +28,7 @@ dependencies { testImplementation(project(":starter:spring-boot-starter-webmvc-test")) testImplementation("org.apache.httpcomponents.client5:httpclient5") } + +tasks.named("compileTestJava") { + options.nullability.checking = "tests" +} diff --git a/smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/AbstractErrorPageTests.java b/smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/AbstractErrorPageTests.java index 48ffa894398..86477b1ca83 100644 --- a/smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/AbstractErrorPageTests.java +++ b/smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/AbstractErrorPageTests.java @@ -73,6 +73,7 @@ abstract class AbstractErrorPageTests { .exchange(this.pathPrefix + "/public/notfound", HttpMethod.GET, null, JsonNode.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); JsonNode jsonResponse = response.getBody(); + assertThat(jsonResponse).isNotNull(); assertThat(jsonResponse.get("error").asString()).isEqualTo("Not Found"); } @@ -91,6 +92,7 @@ abstract class AbstractErrorPageTests { .exchange(this.pathPrefix + "/fail", HttpMethod.GET, null, JsonNode.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); JsonNode jsonResponse = response.getBody(); + assertThat(jsonResponse).isNotNull(); assertThat(jsonResponse.get("error").asString()).isEqualTo("Internal Server Error"); } diff --git a/smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/AbstractUnauthenticatedErrorPageTests.java b/smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/AbstractUnauthenticatedErrorPageTests.java index 8453cef1164..2299e6f4235 100644 --- a/smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/AbstractUnauthenticatedErrorPageTests.java +++ b/smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/AbstractUnauthenticatedErrorPageTests.java @@ -52,6 +52,7 @@ abstract class AbstractUnauthenticatedErrorPageTests { .exchange(this.pathPrefix + "/test", HttpMethod.GET, null, JsonNode.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); JsonNode jsonResponse = response.getBody(); + assertThat(jsonResponse).isNotNull(); assertThat(jsonResponse.get("error").asString()).isEqualTo("Unauthorized"); } @@ -61,6 +62,7 @@ abstract class AbstractUnauthenticatedErrorPageTests { HttpMethod.GET, null, JsonNode.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); JsonNode jsonResponse = response.getBody(); + assertThat(jsonResponse).isNotNull(); assertThat(jsonResponse.get("error").asString()).isEqualTo("Unauthorized"); } @@ -70,6 +72,7 @@ abstract class AbstractUnauthenticatedErrorPageTests { HttpMethod.GET, null, JsonNode.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); JsonNode jsonResponse = response.getBody(); + assertThat(jsonResponse).isNotNull(); assertThat(jsonResponse.get("error").asString()).isEqualTo("Not Found"); } @@ -79,6 +82,7 @@ abstract class AbstractUnauthenticatedErrorPageTests { .exchange(this.pathPrefix + "/public/notfound", HttpMethod.GET, null, JsonNode.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); JsonNode jsonResponse = response.getBody(); + assertThat(jsonResponse).isNotNull(); assertThat(jsonResponse.get("error").asString()).isEqualTo("Not Found"); } @@ -88,6 +92,7 @@ abstract class AbstractUnauthenticatedErrorPageTests { .exchange(this.pathPrefix + "/public/notfound", HttpMethod.GET, null, JsonNode.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); JsonNode jsonResponse = response.getBody(); + assertThat(jsonResponse).isNotNull(); assertThat(jsonResponse.get("error").asString()).isEqualTo("Unauthorized"); } @@ -97,6 +102,7 @@ abstract class AbstractUnauthenticatedErrorPageTests { .exchange(this.pathPrefix + "/fail", HttpMethod.GET, null, JsonNode.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); JsonNode jsonResponse = response.getBody(); + assertThat(jsonResponse).isNotNull(); assertThat(jsonResponse.get("error").asString()).isEqualTo("Internal Server Error"); } diff --git a/smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/SampleWebSecureApplicationTests.java b/smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/SampleWebSecureApplicationTests.java index e22c717539e..b0457604dab 100644 --- a/smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/SampleWebSecureApplicationTests.java +++ b/smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/SampleWebSecureApplicationTests.java @@ -16,6 +16,7 @@ package smoketest.web.secure; +import java.net.URI; import java.util.Collections; import jakarta.servlet.DispatcherType; @@ -68,7 +69,9 @@ class SampleWebSecureApplicationTests { ResponseEntity entity = this.restTemplate.withRedirects(HttpRedirects.DONT_FOLLOW) .exchange("/home", HttpMethod.GET, new HttpEntity<>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/login"); + URI location = entity.getHeaders().getLocation(); + assertThat(location).isNotNull(); + assertThat(location.toString()).endsWith(this.port + "/login"); } @Test @@ -92,7 +95,9 @@ class SampleWebSecureApplicationTests { ResponseEntity entity = this.restTemplate.withRedirects(HttpRedirects.DONT_FOLLOW) .exchange("/login", HttpMethod.POST, new HttpEntity<>(form, headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/"); + URI location = entity.getHeaders().getLocation(); + assertThat(location).isNotNull(); + assertThat(location.toString()).endsWith(this.port + "/"); } @org.springframework.boot.test.context.TestConfiguration(proxyBeanMethods = false)