diff --git a/module/spring-boot-jersey/build.gradle b/module/spring-boot-jersey/build.gradle index 05b9982cbac..ab4de6a7d5a 100644 --- a/module/spring-boot-jersey/build.gradle +++ b/module/spring-boot-jersey/build.gradle @@ -61,3 +61,7 @@ dependencies { testRuntimeOnly("ch.qos.logback:logback-classic") } + +tasks.named("compileTestJava") { + options.nullability.checking = "tests" +} diff --git a/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/JerseyAutoConfigurationCustomObjectMapperProviderTests.java b/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/JerseyAutoConfigurationCustomObjectMapperProviderTests.java index d60816f68aa..b31da768609 100644 --- a/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/JerseyAutoConfigurationCustomObjectMapperProviderTests.java +++ b/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/JerseyAutoConfigurationCustomObjectMapperProviderTests.java @@ -26,6 +26,7 @@ import jakarta.ws.rs.ApplicationPath; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import org.glassfish.jersey.server.ResourceConfig; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -89,9 +90,9 @@ class JerseyAutoConfigurationCustomObjectMapperProviderTests { private String subject; - private String body; + private @Nullable String body; - Message(String subject, String body) { + Message(String subject, @Nullable String body) { this.subject = subject; this.body = body; } @@ -104,11 +105,11 @@ class JerseyAutoConfigurationCustomObjectMapperProviderTests { this.subject = subject; } - public String getBody() { + public @Nullable String getBody() { return this.body; } - public void setBody(String body) { + public void setBody(@Nullable String body) { this.body = body; } diff --git a/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/JerseyAutoConfigurationObjectMapperProviderTests.java b/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/JerseyAutoConfigurationObjectMapperProviderTests.java index d6f5fa89281..96ff5515bf1 100644 --- a/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/JerseyAutoConfigurationObjectMapperProviderTests.java +++ b/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/JerseyAutoConfigurationObjectMapperProviderTests.java @@ -27,6 +27,7 @@ import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.xml.bind.annotation.XmlTransient; import org.glassfish.jersey.server.ResourceConfig; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -89,31 +90,31 @@ class JerseyAutoConfigurationObjectMapperProviderTests { public static class Message { - private String subject; + private @Nullable String subject; - private String body; + private @Nullable String body; Message() { } - Message(String subject, String body) { + Message(@Nullable String subject, @Nullable String body) { this.subject = subject; this.body = body; } - public String getSubject() { + public @Nullable String getSubject() { return this.subject; } - public void setSubject(String subject) { + public void setSubject(@Nullable String subject) { this.subject = subject; } - public String getBody() { + public @Nullable String getBody() { return this.body; } - public void setBody(String body) { + public void setBody(@Nullable String body) { this.body = body; } diff --git a/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/actuate/endpoint/web/JerseyEndpointAccessIntegrationTests.java b/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/actuate/endpoint/web/JerseyEndpointAccessIntegrationTests.java index ce57643d43f..d5553485311 100644 --- a/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/actuate/endpoint/web/JerseyEndpointAccessIntegrationTests.java +++ b/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/actuate/endpoint/web/JerseyEndpointAccessIntegrationTests.java @@ -35,6 +35,7 @@ import org.springframework.boot.jersey.autoconfigure.JerseyAutoConfiguration; import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; import org.springframework.boot.tomcat.autoconfigure.servlet.TomcatServletWebServerAutoConfiguration; +import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.server.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.boot.web.server.servlet.context.ServletWebServerApplicationContext; import org.springframework.http.HttpMethod; @@ -139,9 +140,10 @@ class JerseyEndpointAccessIntegrationTests { } private WebTestClient createClient(AssertableWebApplicationContext context) { - int port = context.getSourceApplicationContext(ServletWebServerApplicationContext.class) - .getWebServer() - .getPort(); + WebServer webServer = context.getSourceApplicationContext(ServletWebServerApplicationContext.class) + .getWebServer(); + assertThat(webServer).isNotNull(); + int port = webServer.getPort(); ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder() .codecs((configurer) -> configurer.defaultCodecs().maxInMemorySize(-1)) .build(); diff --git a/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/actuate/endpoint/web/JerseyEndpointIntegrationTests.java b/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/actuate/endpoint/web/JerseyEndpointIntegrationTests.java index cf47a77338d..9f89556e6fe 100644 --- a/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/actuate/endpoint/web/JerseyEndpointIntegrationTests.java +++ b/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/actuate/endpoint/web/JerseyEndpointIntegrationTests.java @@ -40,6 +40,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.jersey.autoconfigure.JerseyAutoConfiguration; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; import org.springframework.boot.tomcat.autoconfigure.servlet.TomcatServletWebServerAutoConfiguration; +import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.server.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -65,9 +66,11 @@ class JerseyEndpointIntegrationTests { getContextRunner(new Class[] { EndpointsConfiguration.class, ResourceConfigConfiguration.class }) .withPropertyValues("management.endpoints.web.discovery.enabled:false") .run((context) -> { - int port = context.getSourceApplicationContext(AnnotationConfigServletWebServerApplicationContext.class) - .getWebServer() - .getPort(); + WebServer webServer = context + .getSourceApplicationContext(AnnotationConfigServletWebServerApplicationContext.class) + .getWebServer(); + assertThat(webServer).isNotNull(); + int port = webServer.getPort(); WebTestClient client = WebTestClient.bindToServer() .baseUrl("http://localhost:" + port) .responseTimeout(Duration.ofMinutes(5)) @@ -86,9 +89,11 @@ class JerseyEndpointIntegrationTests { WebApplicationContextRunner contextRunner = getContextRunner(new Class[] { EndpointsConfiguration.class, ResourceConfigConfiguration.class, EndpointObjectMapperConfiguration.class }); contextRunner.run((context) -> { - int port = context.getSourceApplicationContext(AnnotationConfigServletWebServerApplicationContext.class) - .getWebServer() - .getPort(); + WebServer webServer = context + .getSourceApplicationContext(AnnotationConfigServletWebServerApplicationContext.class) + .getWebServer(); + assertThat(webServer).isNotNull(); + int port = webServer.getPort(); WebTestClient client = WebTestClient.bindToServer() .baseUrl("http://localhost:" + port) .responseTimeout(Duration.ofMinutes(5)) @@ -102,9 +107,11 @@ class JerseyEndpointIntegrationTests { protected void testJerseyEndpoints(Class[] userConfigurations) { getContextRunner(userConfigurations).run((context) -> { - int port = context.getSourceApplicationContext(AnnotationConfigServletWebServerApplicationContext.class) - .getWebServer() - .getPort(); + WebServer webServer = context + .getSourceApplicationContext(AnnotationConfigServletWebServerApplicationContext.class) + .getWebServer(); + assertThat(webServer).isNotNull(); + int port = webServer.getPort(); WebTestClient client = WebTestClient.bindToServer() .baseUrl("http://localhost:" + port) .responseTimeout(Duration.ofMinutes(5)) diff --git a/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/metrics/JerseyServerMetricsAutoConfigurationTests.java b/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/metrics/JerseyServerMetricsAutoConfigurationTests.java index e632b6978ee..4ba0052863c 100644 --- a/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/metrics/JerseyServerMetricsAutoConfigurationTests.java +++ b/module/spring-boot-jersey/src/test/java/org/springframework/boot/jersey/autoconfigure/metrics/JerseyServerMetricsAutoConfigurationTests.java @@ -44,6 +44,7 @@ import org.springframework.boot.test.context.assertj.AssertableWebApplicationCon import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; import org.springframework.boot.tomcat.autoconfigure.servlet.TomcatServletWebServerAutoConfiguration; +import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.server.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -109,9 +110,11 @@ class JerseyServerMetricsAutoConfigurationTests { } private static void doRequest(AssertableWebApplicationContext context) { - int port = context.getSourceApplicationContext(AnnotationConfigServletWebServerApplicationContext.class) - .getWebServer() - .getPort(); + WebServer webServer = context + .getSourceApplicationContext(AnnotationConfigServletWebServerApplicationContext.class) + .getWebServer(); + assertThat(webServer).isNotNull(); + int port = webServer.getPort(); RestClient restClient = RestClient.create(); restClient.get().uri(URI.create("http://localhost:" + port + "/users/3")).retrieve().toEntity(String.class); }