Add nullability annotations to tests in module/spring-boot-data-elasticsearch

See gh-47263
This commit is contained in:
Moritz Halbritter 2025-09-18 12:28:49 +02:00
parent e313624263
commit 3db8b5fb26
3 changed files with 15 additions and 1 deletions

View File

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

View File

@ -20,6 +20,7 @@ import java.math.BigDecimal;
import java.util.Collections;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
@ -151,7 +152,7 @@ class DataElasticsearchAutoConfigurationTests {
static class MyConverter implements Converter<ElasticsearchTemplate, Boolean> {
@Override
public Boolean convert(ElasticsearchTemplate source) {
public @Nullable Boolean convert(ElasticsearchTemplate source) {
return null;
}

View File

@ -74,6 +74,7 @@ class DataElasticsearchReactiveHealthIndicatorTests {
void elasticsearchIsUp() {
setupMockResponse("green");
Health health = this.healthIndicator.health().block(TIMEOUT);
assertThat(health).isNotNull();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertHealthDetailsWithStatus(health.getDetails(), "green");
}
@ -82,6 +83,7 @@ class DataElasticsearchReactiveHealthIndicatorTests {
void elasticsearchWithYellowStatusIsUp() {
setupMockResponse("yellow");
Health health = this.healthIndicator.health().block(TIMEOUT);
assertThat(health).isNotNull();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertHealthDetailsWithStatus(health.getDetails(), "yellow");
}
@ -91,6 +93,7 @@ class DataElasticsearchReactiveHealthIndicatorTests {
void elasticsearchIsDown() throws Exception {
this.server.shutdown();
Health health = this.healthIndicator.health().block(TIMEOUT);
assertThat(health).isNotNull();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("error")).asString().contains("Connection refused");
}
@ -99,6 +102,7 @@ class DataElasticsearchReactiveHealthIndicatorTests {
void elasticsearchIsDownByResponseCode() {
this.server.enqueue(new MockResponse().setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR.value()));
Health health = this.healthIndicator.health().block(TIMEOUT);
assertThat(health).isNotNull();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("error")).asString().startsWith(ResponseException.class.getName());
}
@ -107,6 +111,7 @@ class DataElasticsearchReactiveHealthIndicatorTests {
void elasticsearchIsOutOfServiceByStatus() {
setupMockResponse("red");
Health health = this.healthIndicator.health().block(TIMEOUT);
assertThat(health).isNotNull();
assertThat(health.getStatus()).isEqualTo(Status.OUT_OF_SERVICE);
assertHealthDetailsWithStatus(health.getDetails(), "red");
}