Add nullability annotations to tests in module/spring-boot-data-elasticsearch-test
See gh-47263
This commit is contained in:
parent
307dc1c477
commit
dee42bfe2d
|
@ -46,3 +46,11 @@ dependencies {
|
|||
|
||||
testRuntimeOnly("ch.qos.logback:logback-classic")
|
||||
}
|
||||
|
||||
tasks.named("compileTestJava") {
|
||||
options.nullability.checking = "tests"
|
||||
}
|
||||
|
||||
tasks.named("compileDockerTestJava") {
|
||||
options.nullability.checking = "tests"
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ class DataElasticsearchTestReactiveIntegrationTests {
|
|||
ExampleDocument exampleDocument = new ExampleDocument();
|
||||
exampleDocument.setText("Look, new @DataElasticsearchTest!");
|
||||
exampleDocument = this.exampleReactiveRepository.save(exampleDocument).block(Duration.ofSeconds(30));
|
||||
assertThat(exampleDocument).isNotNull();
|
||||
assertThat(exampleDocument.getId()).isNotNull();
|
||||
assertThat(this.elasticsearchTemplate.exists(exampleDocument.getId(), ExampleDocument.class)
|
||||
.block(Duration.ofSeconds(30))).isTrue();
|
||||
|
|
|
@ -61,6 +61,7 @@ class DataElasticsearchTestWithIncludeFilterIntegrationTests {
|
|||
String id = UUID.randomUUID().toString();
|
||||
document.setId(id);
|
||||
ExampleDocument savedDocument = this.exampleRepository.save(document);
|
||||
assertThat(savedDocument.getId()).isNotNull();
|
||||
assertThat(this.service.findById(savedDocument.getId())).isNotNull();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.boot.data.elasticsearch.test.autoconfigure;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
|
||||
|
@ -28,23 +30,23 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
|||
public class ExampleDocument {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
public void setId(@Nullable String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
public @Nullable String getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
public void setText(@Nullable String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.boot.data.elasticsearch.test.autoconfigure;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -33,7 +35,7 @@ public class ExampleService {
|
|||
this.elasticsearchTemplate = elasticsearchRestTemplate;
|
||||
}
|
||||
|
||||
public ExampleDocument findById(String id) {
|
||||
public @Nullable ExampleDocument findById(String id) {
|
||||
return this.elasticsearchTemplate.get(id, ExampleDocument.class);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue