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

See gh-47263
This commit is contained in:
Moritz Halbritter 2025-10-06 11:46:56 +02:00
parent 307dc1c477
commit dee42bfe2d
5 changed files with 21 additions and 7 deletions

View File

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

View File

@ -58,6 +58,7 @@ class DataElasticsearchTestReactiveIntegrationTests {
ExampleDocument exampleDocument = new ExampleDocument(); ExampleDocument exampleDocument = new ExampleDocument();
exampleDocument.setText("Look, new @DataElasticsearchTest!"); exampleDocument.setText("Look, new @DataElasticsearchTest!");
exampleDocument = this.exampleReactiveRepository.save(exampleDocument).block(Duration.ofSeconds(30)); exampleDocument = this.exampleReactiveRepository.save(exampleDocument).block(Duration.ofSeconds(30));
assertThat(exampleDocument).isNotNull();
assertThat(exampleDocument.getId()).isNotNull(); assertThat(exampleDocument.getId()).isNotNull();
assertThat(this.elasticsearchTemplate.exists(exampleDocument.getId(), ExampleDocument.class) assertThat(this.elasticsearchTemplate.exists(exampleDocument.getId(), ExampleDocument.class)
.block(Duration.ofSeconds(30))).isTrue(); .block(Duration.ofSeconds(30))).isTrue();

View File

@ -61,6 +61,7 @@ class DataElasticsearchTestWithIncludeFilterIntegrationTests {
String id = UUID.randomUUID().toString(); String id = UUID.randomUUID().toString();
document.setId(id); document.setId(id);
ExampleDocument savedDocument = this.exampleRepository.save(document); ExampleDocument savedDocument = this.exampleRepository.save(document);
assertThat(savedDocument.getId()).isNotNull();
assertThat(this.service.findById(savedDocument.getId())).isNotNull(); assertThat(this.service.findById(savedDocument.getId())).isNotNull();
} }

View File

@ -16,6 +16,8 @@
package org.springframework.boot.data.elasticsearch.test.autoconfigure; package org.springframework.boot.data.elasticsearch.test.autoconfigure;
import org.jspecify.annotations.Nullable;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Document;
@ -28,23 +30,23 @@ import org.springframework.data.elasticsearch.annotations.Document;
public class ExampleDocument { public class ExampleDocument {
@Id @Id
private String id; private @Nullable String id;
private String text; private @Nullable String text;
public String getId() { public @Nullable String getId() {
return this.id; return this.id;
} }
public void setId(String id) { public void setId(@Nullable String id) {
this.id = id; this.id = id;
} }
public String getText() { public @Nullable String getText() {
return this.text; return this.text;
} }
public void setText(String text) { public void setText(@Nullable String text) {
this.text = text; this.text = text;
} }

View File

@ -16,6 +16,8 @@
package org.springframework.boot.data.elasticsearch.test.autoconfigure; package org.springframework.boot.data.elasticsearch.test.autoconfigure;
import org.jspecify.annotations.Nullable;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate; import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -33,7 +35,7 @@ public class ExampleService {
this.elasticsearchTemplate = elasticsearchRestTemplate; this.elasticsearchTemplate = elasticsearchRestTemplate;
} }
public ExampleDocument findById(String id) { public @Nullable ExampleDocument findById(String id) {
return this.elasticsearchTemplate.get(id, ExampleDocument.class); return this.elasticsearchTemplate.get(id, ExampleDocument.class);
} }