Skip to content

Commit dee42bf

Browse files
committed
Add nullability annotations to tests in module/spring-boot-data-elasticsearch-test
See gh-47263
1 parent 307dc1c commit dee42bf

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

module/spring-boot-data-elasticsearch-test/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@ dependencies {
4646

4747
testRuntimeOnly("ch.qos.logback:logback-classic")
4848
}
49+
50+
tasks.named("compileTestJava") {
51+
options.nullability.checking = "tests"
52+
}
53+
54+
tasks.named("compileDockerTestJava") {
55+
options.nullability.checking = "tests"
56+
}

module/spring-boot-data-elasticsearch-test/src/dockerTest/java/org/springframework/boot/data/elasticsearch/test/autoconfigure/DataElasticsearchTestReactiveIntegrationTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void testRepository() {
5858
ExampleDocument exampleDocument = new ExampleDocument();
5959
exampleDocument.setText("Look, new @DataElasticsearchTest!");
6060
exampleDocument = this.exampleReactiveRepository.save(exampleDocument).block(Duration.ofSeconds(30));
61+
assertThat(exampleDocument).isNotNull();
6162
assertThat(exampleDocument.getId()).isNotNull();
6263
assertThat(this.elasticsearchTemplate.exists(exampleDocument.getId(), ExampleDocument.class)
6364
.block(Duration.ofSeconds(30))).isTrue();

module/spring-boot-data-elasticsearch-test/src/dockerTest/java/org/springframework/boot/data/elasticsearch/test/autoconfigure/DataElasticsearchTestWithIncludeFilterIntegrationTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void testService() {
6161
String id = UUID.randomUUID().toString();
6262
document.setId(id);
6363
ExampleDocument savedDocument = this.exampleRepository.save(document);
64+
assertThat(savedDocument.getId()).isNotNull();
6465
assertThat(this.service.findById(savedDocument.getId())).isNotNull();
6566
}
6667

module/spring-boot-data-elasticsearch-test/src/dockerTest/java/org/springframework/boot/data/elasticsearch/test/autoconfigure/ExampleDocument.java

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

1717
package org.springframework.boot.data.elasticsearch.test.autoconfigure;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.data.annotation.Id;
2022
import org.springframework.data.elasticsearch.annotations.Document;
2123

@@ -28,23 +30,23 @@
2830
public class ExampleDocument {
2931

3032
@Id
31-
private String id;
33+
private @Nullable String id;
3234

33-
private String text;
35+
private @Nullable String text;
3436

35-
public String getId() {
37+
public @Nullable String getId() {
3638
return this.id;
3739
}
3840

39-
public void setId(String id) {
41+
public void setId(@Nullable String id) {
4042
this.id = id;
4143
}
4244

43-
public String getText() {
45+
public @Nullable String getText() {
4446
return this.text;
4547
}
4648

47-
public void setText(String text) {
49+
public void setText(@Nullable String text) {
4850
this.text = text;
4951
}
5052

module/spring-boot-data-elasticsearch-test/src/dockerTest/java/org/springframework/boot/data/elasticsearch/test/autoconfigure/ExampleService.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.data.elasticsearch.test.autoconfigure;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
2022
import org.springframework.stereotype.Service;
2123

@@ -33,7 +35,7 @@ public ExampleService(ElasticsearchTemplate elasticsearchRestTemplate) {
3335
this.elasticsearchTemplate = elasticsearchRestTemplate;
3436
}
3537

36-
public ExampleDocument findById(String id) {
38+
public @Nullable ExampleDocument findById(String id) {
3739
return this.elasticsearchTemplate.get(id, ExampleDocument.class);
3840
}
3941

0 commit comments

Comments
 (0)