diff --git a/module/spring-boot-restclient-test/build.gradle b/module/spring-boot-restclient-test/build.gradle index 77e71c54e80..213f653d3fc 100644 --- a/module/spring-boot-restclient-test/build.gradle +++ b/module/spring-boot-restclient-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-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestClientCustomizerTests.java b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestClientCustomizerTests.java index 61c8db091fe..1d0a3f86dfc 100644 --- a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestClientCustomizerTests.java +++ b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestClientCustomizerTests.java @@ -56,6 +56,7 @@ class MockServerRestClientCustomizerTests { } @Test + @SuppressWarnings("NullAway") // Test null check void createWhenExpectationManagerClassIsNullShouldThrowException() { Class expectationManager = null; assertThatIllegalArgumentException().isThrownBy(() -> new MockServerRestClientCustomizer(expectationManager)) @@ -63,6 +64,7 @@ class MockServerRestClientCustomizerTests { } @Test + @SuppressWarnings("NullAway") // Test null check void createWhenExpectationManagerSupplierIsNullShouldThrowException() { Supplier expectationManagerSupplier = null; assertThatIllegalArgumentException() diff --git a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizerTests.java b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizerTests.java index 523fe81a4c7..404f92ed7d6 100644 --- a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizerTests.java +++ b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizerTests.java @@ -59,6 +59,7 @@ class MockServerRestTemplateCustomizerTests { } @Test + @SuppressWarnings("NullAway") // Test null check void createWhenExpectationManagerClassIsNullShouldThrowException() { Class expectationManager = null; assertThatIllegalArgumentException().isThrownBy(() -> new MockServerRestTemplateCustomizer(expectationManager)) @@ -66,6 +67,7 @@ class MockServerRestTemplateCustomizerTests { } @Test + @SuppressWarnings("NullAway") // Test null check void createWhenExpectationManagerSupplierIsNullShouldThrowException() { Supplier expectationManagerSupplier = null; assertThatIllegalArgumentException() diff --git a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManagerTests.java b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManagerTests.java index 5539e6ee974..acdb2d9fd44 100644 --- a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManagerTests.java +++ b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManagerTests.java @@ -55,6 +55,7 @@ class RootUriRequestExpectationManagerTests { private final String uri = "https://example.com"; @Mock + @SuppressWarnings("NullAway.Init") private RequestExpectationManager delegate; private RootUriRequestExpectationManager manager; @@ -65,12 +66,14 @@ class RootUriRequestExpectationManagerTests { } @Test + @SuppressWarnings("NullAway") // Test null check void createWhenRootUriIsNullShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> new RootUriRequestExpectationManager(null, this.delegate)) .withMessageContaining("'rootUri' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void createWhenExpectationManagerIsNullShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> new RootUriRequestExpectationManager(this.uri, null)) .withMessageContaining("'expectationManager' must not be null"); diff --git a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestClientService.java b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestClientService.java index 7d1b76821b2..a0c8f98feda 100644 --- a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestClientService.java +++ b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestClientService.java @@ -16,6 +16,8 @@ package org.springframework.boot.restclient.test.autoconfigure; +import org.jspecify.annotations.Nullable; + import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; import org.springframework.web.client.RestClient.Builder; @@ -41,7 +43,7 @@ public class AnotherExampleRestClientService { return this.builder; } - public String test() { + public @Nullable String test() { return this.restClient.get().uri("/test").retrieve().toEntity(String.class).getBody(); } diff --git a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestTemplateService.java b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestTemplateService.java index f9a64c94aed..511f1473062 100644 --- a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestTemplateService.java +++ b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestTemplateService.java @@ -16,6 +16,8 @@ package org.springframework.boot.restclient.test.autoconfigure; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.restclient.RestTemplateBuilder; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; @@ -38,7 +40,7 @@ public class AnotherExampleRestTemplateService { return this.restTemplate; } - public String test() { + public @Nullable String test() { return this.restTemplate.getForEntity("/test", String.class).getBody(); } diff --git a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestClientService.java b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestClientService.java index 4b19fadbc7f..431e800d311 100644 --- a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestClientService.java +++ b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestClientService.java @@ -16,6 +16,8 @@ package org.springframework.boot.restclient.test.autoconfigure; +import org.jspecify.annotations.Nullable; + import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; import org.springframework.web.client.RestClient.Builder; @@ -42,7 +44,7 @@ public class ExampleRestClientService { return this.builder; } - public String test() { + public @Nullable String test() { return this.restClient.get().uri("/test").retrieve().toEntity(String.class).getBody(); } diff --git a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestTemplateService.java b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestTemplateService.java index 4a01d175de9..4f04ecdd472 100644 --- a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestTemplateService.java +++ b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestTemplateService.java @@ -16,6 +16,8 @@ package org.springframework.boot.restclient.test.autoconfigure; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.restclient.RestTemplateBuilder; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; @@ -39,7 +41,7 @@ public class ExampleRestTemplateService { return this.restTemplate; } - public String test() { + public @Nullable String test() { return this.restTemplate.getForEntity("/test", String.class).getBody(); } diff --git a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/RestClientTestRestClientTwoComponentsIntegrationTests.java b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/RestClientTestRestClientTwoComponentsIntegrationTests.java index befdf8ed000..58c3d754623 100644 --- a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/RestClientTestRestClientTwoComponentsIntegrationTests.java +++ b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/RestClientTestRestClientTwoComponentsIntegrationTests.java @@ -58,17 +58,17 @@ class RestClientTestRestClientTwoComponentsIntegrationTests { @Test void client1RestCallViaCustomizer() { - this.customizer.getServer(this.client1.getRestClientBuilder()) - .expect(requestTo(uri("/test"))) - .andRespond(withSuccess("hello", MediaType.TEXT_HTML)); + MockRestServiceServer server = this.customizer.getServer(this.client1.getRestClientBuilder()); + assertThat(server).isNotNull(); + server.expect(requestTo(uri("/test"))).andRespond(withSuccess("hello", MediaType.TEXT_HTML)); assertThat(this.client1.test()).isEqualTo("hello"); } @Test void client2RestCallViaCustomizer() { - this.customizer.getServer(this.client2.getRestClientBuilder()) - .expect(requestTo(uri("/test"))) - .andRespond(withSuccess("there", MediaType.TEXT_HTML)); + MockRestServiceServer server = this.customizer.getServer(this.client2.getRestClientBuilder()); + assertThat(server).isNotNull(); + server.expect(requestTo(uri("/test"))).andRespond(withSuccess("there", MediaType.TEXT_HTML)); assertThat(this.client2.test()).isEqualTo("there"); } diff --git a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/RestClientTestRestTemplateTwoComponentsIntegrationTests.java b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/RestClientTestRestTemplateTwoComponentsIntegrationTests.java index 2cd40bab55a..90543c70054 100644 --- a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/RestClientTestRestTemplateTwoComponentsIntegrationTests.java +++ b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/RestClientTestRestTemplateTwoComponentsIntegrationTests.java @@ -58,17 +58,17 @@ class RestClientTestRestTemplateTwoComponentsIntegrationTests { @Test void client1RestCallViaCustomizer() { - this.customizer.getServer(this.client1.getRestTemplate()) - .expect(requestTo("/test")) - .andRespond(withSuccess("hello", MediaType.TEXT_HTML)); + MockRestServiceServer server = this.customizer.getServer(this.client1.getRestTemplate()); + assertThat(server).isNotNull(); + server.expect(requestTo("/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML)); assertThat(this.client1.test()).isEqualTo("hello"); } @Test void client2RestCallViaCustomizer() { - this.customizer.getServer(this.client2.getRestTemplate()) - .expect(requestTo("/test")) - .andRespond(withSuccess("there", MediaType.TEXT_HTML)); + MockRestServiceServer server = this.customizer.getServer(this.client2.getRestTemplate()); + assertThat(server).isNotNull(); + server.expect(requestTo("/test")).andRespond(withSuccess("there", MediaType.TEXT_HTML)); assertThat(this.client2.test()).isEqualTo("there"); }