Browse Source

Add nullability annotations to tests in module/spring-boot-restclient-test

See gh-47263
pull/47626/head
Moritz Halbritter 4 months ago
parent
commit
558183e0fe
  1. 4
      module/spring-boot-restclient-test/build.gradle
  2. 2
      module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestClientCustomizerTests.java
  3. 2
      module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizerTests.java
  4. 3
      module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManagerTests.java
  5. 4
      module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestClientService.java
  6. 4
      module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestTemplateService.java
  7. 4
      module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestClientService.java
  8. 4
      module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestTemplateService.java
  9. 12
      module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/RestClientTestRestClientTwoComponentsIntegrationTests.java
  10. 12
      module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/RestClientTestRestTemplateTwoComponentsIntegrationTests.java

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

@ -40,3 +40,7 @@ dependencies { @@ -40,3 +40,7 @@ dependencies {
testRuntimeOnly("ch.qos.logback:logback-classic")
}
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}

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

@ -56,6 +56,7 @@ class MockServerRestClientCustomizerTests { @@ -56,6 +56,7 @@ class MockServerRestClientCustomizerTests {
}
@Test
@SuppressWarnings("NullAway") // Test null check
void createWhenExpectationManagerClassIsNullShouldThrowException() {
Class<? extends RequestExpectationManager> expectationManager = null;
assertThatIllegalArgumentException().isThrownBy(() -> new MockServerRestClientCustomizer(expectationManager))
@ -63,6 +64,7 @@ class MockServerRestClientCustomizerTests { @@ -63,6 +64,7 @@ class MockServerRestClientCustomizerTests {
}
@Test
@SuppressWarnings("NullAway") // Test null check
void createWhenExpectationManagerSupplierIsNullShouldThrowException() {
Supplier<? extends RequestExpectationManager> expectationManagerSupplier = null;
assertThatIllegalArgumentException()

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

@ -59,6 +59,7 @@ class MockServerRestTemplateCustomizerTests { @@ -59,6 +59,7 @@ class MockServerRestTemplateCustomizerTests {
}
@Test
@SuppressWarnings("NullAway") // Test null check
void createWhenExpectationManagerClassIsNullShouldThrowException() {
Class<? extends RequestExpectationManager> expectationManager = null;
assertThatIllegalArgumentException().isThrownBy(() -> new MockServerRestTemplateCustomizer(expectationManager))
@ -66,6 +67,7 @@ class MockServerRestTemplateCustomizerTests { @@ -66,6 +67,7 @@ class MockServerRestTemplateCustomizerTests {
}
@Test
@SuppressWarnings("NullAway") // Test null check
void createWhenExpectationManagerSupplierIsNullShouldThrowException() {
Supplier<? extends RequestExpectationManager> expectationManagerSupplier = null;
assertThatIllegalArgumentException()

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

@ -55,6 +55,7 @@ class RootUriRequestExpectationManagerTests { @@ -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 { @@ -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");

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

@ -16,6 +16,8 @@ @@ -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 { @@ -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();
}

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

@ -16,6 +16,8 @@ @@ -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 { @@ -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();
}

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

@ -16,6 +16,8 @@ @@ -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 { @@ -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();
}

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

@ -16,6 +16,8 @@ @@ -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 { @@ -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();
}

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

@ -58,17 +58,17 @@ class RestClientTestRestClientTwoComponentsIntegrationTests { @@ -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");
}

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

@ -58,17 +58,17 @@ class RestClientTestRestTemplateTwoComponentsIntegrationTests { @@ -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");
}

Loading…
Cancel
Save