diff --git a/module/spring-boot-webservices/build.gradle b/module/spring-boot-webservices/build.gradle index 6aaf10eb52d..4668f461f30 100644 --- a/module/spring-boot-webservices/build.gradle +++ b/module/spring-boot-webservices/build.gradle @@ -41,3 +41,7 @@ dependencies { testRuntimeOnly("io.projectreactor.netty:reactor-netty-http") testRuntimeOnly("org.apache.httpcomponents.client5:httpclient5") } + +tasks.named("compileTestJava") { + options.nullability.checking = "tests" +} diff --git a/module/spring-boot-webservices/src/test/java/org/springframework/boot/webservices/autoconfigure/WebServicesPropertiesTests.java b/module/spring-boot-webservices/src/test/java/org/springframework/boot/webservices/autoconfigure/WebServicesPropertiesTests.java index 16a13ca57af..33b6db6ffa6 100644 --- a/module/spring-boot-webservices/src/test/java/org/springframework/boot/webservices/autoconfigure/WebServicesPropertiesTests.java +++ b/module/spring-boot-webservices/src/test/java/org/springframework/boot/webservices/autoconfigure/WebServicesPropertiesTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.webservices.autoconfigure; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; @@ -29,23 +30,25 @@ class WebServicesPropertiesTests { private WebServicesProperties properties; + @BeforeEach + void setUp() { + this.properties = new WebServicesProperties(); + } + @Test void pathMustNotBeEmpty() { - this.properties = new WebServicesProperties(); assertThatIllegalArgumentException().isThrownBy(() -> this.properties.setPath("")) .withMessageContaining("'path' must have length greater than 1"); } @Test void pathMustHaveLengthGreaterThanOne() { - this.properties = new WebServicesProperties(); assertThatIllegalArgumentException().isThrownBy(() -> this.properties.setPath("/")) .withMessageContaining("'path' must have length greater than 1"); } @Test void customPathMustBeginWithASlash() { - this.properties = new WebServicesProperties(); assertThatIllegalArgumentException().isThrownBy(() -> this.properties.setPath("custom")) .withMessageContaining("'path' must start with '/'"); } diff --git a/module/spring-boot-webservices/src/test/java/org/springframework/boot/webservices/client/WebServiceMessageSenderFactoryTests.java b/module/spring-boot-webservices/src/test/java/org/springframework/boot/webservices/client/WebServiceMessageSenderFactoryTests.java index d407802c73c..7726370aab4 100644 --- a/module/spring-boot-webservices/src/test/java/org/springframework/boot/webservices/client/WebServiceMessageSenderFactoryTests.java +++ b/module/spring-boot-webservices/src/test/java/org/springframework/boot/webservices/client/WebServiceMessageSenderFactoryTests.java @@ -94,6 +94,7 @@ class WebServiceMessageSenderFactoryTests { } @Test + @SuppressWarnings("NullAway") // Test null check void httpWithFactoryAndSettingsWhenFactoryIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> WebServiceMessageSenderFactory.http(null, null)) .withMessage("'requestFactoryBuilder' must not be null"); @@ -113,8 +114,7 @@ class WebServiceMessageSenderFactoryTests { private ClientHttpRequestFactory getRequestFactory(WebServiceMessageSender sender) { assertThat(sender).isInstanceOf(ClientHttpRequestMessageSender.class); - ClientHttpRequestFactory requestFactory = ((ClientHttpRequestMessageSender) sender).getRequestFactory(); - return requestFactory; + return ((ClientHttpRequestMessageSender) sender).getRequestFactory(); } } diff --git a/module/spring-boot-webservices/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderTests.java b/module/spring-boot-webservices/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderTests.java index 14136d5d763..049bff9d3d3 100644 --- a/module/spring-boot-webservices/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderTests.java +++ b/module/spring-boot-webservices/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderTests.java @@ -62,9 +62,11 @@ class WebServiceTemplateBuilderTests { private final WebServiceTemplateBuilder builder = new WebServiceTemplateBuilder(); @Mock + @SuppressWarnings("NullAway.Init") private WebServiceMessageSender messageSender; @Mock + @SuppressWarnings("NullAway.Init") private ClientInterceptor interceptor; @Test @@ -100,6 +102,7 @@ class WebServiceTemplateBuilderTests { } @Test + @SuppressWarnings("NullAway") // Test null check void messageSendersWhenSendersAreAreNullShouldThrowException() { assertThatIllegalArgumentException() .isThrownBy(() -> this.builder.messageSenders((WebServiceMessageSender[]) null)) @@ -107,6 +110,7 @@ class WebServiceTemplateBuilderTests { } @Test + @SuppressWarnings("NullAway") // Test null check void messageSendersCollectionWhenSendersAreAreNullShouldThrowException() { assertThatIllegalArgumentException() .isThrownBy(() -> this.builder.messageSenders((Collection) null)) @@ -128,6 +132,7 @@ class WebServiceTemplateBuilderTests { } @Test + @SuppressWarnings("NullAway") // Test null check void additionalMessageSendersWhenSendersAreAreNullShouldThrowException() { assertThatIllegalArgumentException() .isThrownBy(() -> this.builder.additionalMessageSenders((WebServiceMessageSender[]) null)) @@ -135,6 +140,7 @@ class WebServiceTemplateBuilderTests { } @Test + @SuppressWarnings("NullAway") // Test null check void additionalMessageSendersCollectionWhenSendersAreAreNullShouldThrowException() { assertThatIllegalArgumentException() .isThrownBy( @@ -159,12 +165,14 @@ class WebServiceTemplateBuilderTests { } @Test + @SuppressWarnings("NullAway") // Test null check void interceptorsWhenInterceptorsAreNullShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> this.builder.interceptors((ClientInterceptor[]) null)) .withMessageContaining("'interceptors' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void interceptorsCollectionWhenInterceptorsAreNullShouldThrowException() { assertThatIllegalArgumentException() .isThrownBy(() -> this.builder.interceptors((Collection) null)) @@ -186,6 +194,7 @@ class WebServiceTemplateBuilderTests { } @Test + @SuppressWarnings("NullAway") // Test null check void additionalInterceptorsWhenInterceptorsAreNullShouldThrowException() { assertThatIllegalArgumentException() .isThrownBy(() -> this.builder.additionalInterceptors((ClientInterceptor[]) null)) @@ -193,6 +202,7 @@ class WebServiceTemplateBuilderTests { } @Test + @SuppressWarnings("NullAway") // Test null check void additionalInterceptorsCollectionWhenInterceptorsAreNullShouldThrowException() { assertThatIllegalArgumentException() .isThrownBy(() -> this.builder.additionalInterceptors((Set) null)) @@ -219,6 +229,7 @@ class WebServiceTemplateBuilderTests { } @Test + @SuppressWarnings("NullAway") // Test null check void customizersWhenCustomizersAreNullShouldThrowException() { assertThatIllegalArgumentException() .isThrownBy(() -> this.builder.customizers((WebServiceTemplateCustomizer[]) null)) @@ -226,6 +237,7 @@ class WebServiceTemplateBuilderTests { } @Test + @SuppressWarnings("NullAway") // Test null check void customizersCollectionWhenCustomizersAreNullShouldThrowException() { assertThatIllegalArgumentException() .isThrownBy(() -> this.builder.customizers((Collection) null)) @@ -259,6 +271,7 @@ class WebServiceTemplateBuilderTests { } @Test + @SuppressWarnings("NullAway") // Test null check void additionalCustomizersWhenCustomizersAreNullShouldThrowException() { assertThatIllegalArgumentException() .isThrownBy(() -> this.builder.additionalCustomizers((WebServiceTemplateCustomizer[]) null)) @@ -266,6 +279,7 @@ class WebServiceTemplateBuilderTests { } @Test + @SuppressWarnings("NullAway") // Test null check void additionalCustomizersCollectionWhenCustomizersAreNullShouldThrowException() { assertThatIllegalArgumentException() .isThrownBy( @@ -336,7 +350,9 @@ class WebServiceTemplateBuilderTests { void setDefaultUri() { URI uri = URI.create("http://localhost:8080"); WebServiceTemplate webServiceTemplate = this.builder.setDefaultUri(uri.toString()).build(); - assertThat(webServiceTemplate.getDestinationProvider().getDestination()).isEqualTo(uri); + DestinationProvider destinationProvider = webServiceTemplate.getDestinationProvider(); + assertThat(destinationProvider).isNotNull(); + assertThat(destinationProvider.getDestination()).isEqualTo(uri); } @Test