Skip to content

Commit 558183e

Browse files
committed
Add nullability annotations to tests in module/spring-boot-restclient-test
See gh-47263
1 parent b56d9c6 commit 558183e

10 files changed

Lines changed: 35 additions & 16 deletions

module/spring-boot-restclient-test/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ dependencies {
4040

4141
testRuntimeOnly("ch.qos.logback:logback-classic")
4242
}
43+
44+
tasks.named("compileTestJava") {
45+
options.nullability.checking = "tests"
46+
}

module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestClientCustomizerTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ void createShouldUseSimpleRequestExpectationManager() {
5656
}
5757

5858
@Test
59+
@SuppressWarnings("NullAway") // Test null check
5960
void createWhenExpectationManagerClassIsNullShouldThrowException() {
6061
Class<? extends RequestExpectationManager> expectationManager = null;
6162
assertThatIllegalArgumentException().isThrownBy(() -> new MockServerRestClientCustomizer(expectationManager))
6263
.withMessageContaining("'expectationManager' must not be null");
6364
}
6465

6566
@Test
67+
@SuppressWarnings("NullAway") // Test null check
6668
void createWhenExpectationManagerSupplierIsNullShouldThrowException() {
6769
Supplier<? extends RequestExpectationManager> expectationManagerSupplier = null;
6870
assertThatIllegalArgumentException()

module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizerTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,15 @@ void createShouldUseSimpleRequestExpectationManager() {
5959
}
6060

6161
@Test
62+
@SuppressWarnings("NullAway") // Test null check
6263
void createWhenExpectationManagerClassIsNullShouldThrowException() {
6364
Class<? extends RequestExpectationManager> expectationManager = null;
6465
assertThatIllegalArgumentException().isThrownBy(() -> new MockServerRestTemplateCustomizer(expectationManager))
6566
.withMessageContaining("'expectationManager' must not be null");
6667
}
6768

6869
@Test
70+
@SuppressWarnings("NullAway") // Test null check
6971
void createWhenExpectationManagerSupplierIsNullShouldThrowException() {
7072
Supplier<? extends RequestExpectationManager> expectationManagerSupplier = null;
7173
assertThatIllegalArgumentException()

module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManagerTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class RootUriRequestExpectationManagerTests {
5555
private final String uri = "https://example.com";
5656

5757
@Mock
58+
@SuppressWarnings("NullAway.Init")
5859
private RequestExpectationManager delegate;
5960

6061
private RootUriRequestExpectationManager manager;
@@ -65,12 +66,14 @@ void setup() {
6566
}
6667

6768
@Test
69+
@SuppressWarnings("NullAway") // Test null check
6870
void createWhenRootUriIsNullShouldThrowException() {
6971
assertThatIllegalArgumentException().isThrownBy(() -> new RootUriRequestExpectationManager(null, this.delegate))
7072
.withMessageContaining("'rootUri' must not be null");
7173
}
7274

7375
@Test
76+
@SuppressWarnings("NullAway") // Test null check
7477
void createWhenExpectationManagerIsNullShouldThrowException() {
7578
assertThatIllegalArgumentException().isThrownBy(() -> new RootUriRequestExpectationManager(this.uri, null))
7679
.withMessageContaining("'expectationManager' must not be null");

module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestClientService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.restclient.test.autoconfigure;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.stereotype.Service;
2022
import org.springframework.web.client.RestClient;
2123
import org.springframework.web.client.RestClient.Builder;
@@ -41,7 +43,7 @@ protected Builder getRestClientBuilder() {
4143
return this.builder;
4244
}
4345

44-
public String test() {
46+
public @Nullable String test() {
4547
return this.restClient.get().uri("/test").retrieve().toEntity(String.class).getBody();
4648
}
4749

module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestTemplateService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.restclient.test.autoconfigure;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.boot.restclient.RestTemplateBuilder;
2022
import org.springframework.stereotype.Service;
2123
import org.springframework.web.client.RestTemplate;
@@ -38,7 +40,7 @@ protected RestTemplate getRestTemplate() {
3840
return this.restTemplate;
3941
}
4042

41-
public String test() {
43+
public @Nullable String test() {
4244
return this.restTemplate.getForEntity("/test", String.class).getBody();
4345
}
4446

module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestClientService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.restclient.test.autoconfigure;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.stereotype.Service;
2022
import org.springframework.web.client.RestClient;
2123
import org.springframework.web.client.RestClient.Builder;
@@ -42,7 +44,7 @@ protected Builder getRestClientBuilder() {
4244
return this.builder;
4345
}
4446

45-
public String test() {
47+
public @Nullable String test() {
4648
return this.restClient.get().uri("/test").retrieve().toEntity(String.class).getBody();
4749
}
4850

module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestTemplateService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.restclient.test.autoconfigure;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.boot.restclient.RestTemplateBuilder;
2022
import org.springframework.stereotype.Service;
2123
import org.springframework.web.client.RestTemplate;
@@ -39,7 +41,7 @@ protected RestTemplate getRestTemplate() {
3941
return this.restTemplate;
4042
}
4143

42-
public String test() {
44+
public @Nullable String test() {
4345
return this.restTemplate.getForEntity("/test", String.class).getBody();
4446
}
4547

module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/RestClientTestRestClientTwoComponentsIntegrationTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ void serverShouldNotWork() {
5858

5959
@Test
6060
void client1RestCallViaCustomizer() {
61-
this.customizer.getServer(this.client1.getRestClientBuilder())
62-
.expect(requestTo(uri("/test")))
63-
.andRespond(withSuccess("hello", MediaType.TEXT_HTML));
61+
MockRestServiceServer server = this.customizer.getServer(this.client1.getRestClientBuilder());
62+
assertThat(server).isNotNull();
63+
server.expect(requestTo(uri("/test"))).andRespond(withSuccess("hello", MediaType.TEXT_HTML));
6464
assertThat(this.client1.test()).isEqualTo("hello");
6565
}
6666

6767
@Test
6868
void client2RestCallViaCustomizer() {
69-
this.customizer.getServer(this.client2.getRestClientBuilder())
70-
.expect(requestTo(uri("/test")))
71-
.andRespond(withSuccess("there", MediaType.TEXT_HTML));
69+
MockRestServiceServer server = this.customizer.getServer(this.client2.getRestClientBuilder());
70+
assertThat(server).isNotNull();
71+
server.expect(requestTo(uri("/test"))).andRespond(withSuccess("there", MediaType.TEXT_HTML));
7272
assertThat(this.client2.test()).isEqualTo("there");
7373
}
7474

module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/RestClientTestRestTemplateTwoComponentsIntegrationTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ void serverShouldNotWork() {
5858

5959
@Test
6060
void client1RestCallViaCustomizer() {
61-
this.customizer.getServer(this.client1.getRestTemplate())
62-
.expect(requestTo("/test"))
63-
.andRespond(withSuccess("hello", MediaType.TEXT_HTML));
61+
MockRestServiceServer server = this.customizer.getServer(this.client1.getRestTemplate());
62+
assertThat(server).isNotNull();
63+
server.expect(requestTo("/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML));
6464
assertThat(this.client1.test()).isEqualTo("hello");
6565
}
6666

6767
@Test
6868
void client2RestCallViaCustomizer() {
69-
this.customizer.getServer(this.client2.getRestTemplate())
70-
.expect(requestTo("/test"))
71-
.andRespond(withSuccess("there", MediaType.TEXT_HTML));
69+
MockRestServiceServer server = this.customizer.getServer(this.client2.getRestTemplate());
70+
assertThat(server).isNotNull();
71+
server.expect(requestTo("/test")).andRespond(withSuccess("there", MediaType.TEXT_HTML));
7272
assertThat(this.client2.test()).isEqualTo("there");
7373
}
7474

0 commit comments

Comments
 (0)