Skip to content

Commit a1038a5

Browse files
committed
Add nullability annotations to tests in module/spring-boot-data-mongodb-test
See gh-47263
1 parent 99f8c4c commit a1038a5

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,17 @@ dependencies {
4444
dockerTestImplementation("org.testcontainers:mongodb")
4545
dockerTestImplementation("org.testcontainers:testcontainers")
4646

47+
dockerTestCompileOnly("com.google.code.findbugs:jsr305")
48+
4749
testImplementation(project(":test-support:spring-boot-test-support"))
4850

4951
testRuntimeOnly("ch.qos.logback:logback-classic")
5052
}
53+
54+
tasks.named("compileTestJava") {
55+
options.nullability.checking = "tests"
56+
}
57+
58+
tasks.named("compileDockerTestJava") {
59+
options.nullability.checking = "tests"
60+
}

module/spring-boot-data-mongodb-test/src/dockerTest/java/org/springframework/boot/data/mongodb/test/autoconfigure/DataMongoTestReactiveIntegrationTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void testRepository() {
5757
ExampleDocument exampleDocument = new ExampleDocument();
5858
exampleDocument.setText("Look, new @DataMongoTest!");
5959
exampleDocument = this.exampleRepository.save(exampleDocument).block(Duration.ofSeconds(30));
60+
assertThat(exampleDocument).isNotNull();
6061
assertThat(exampleDocument.getId()).isNotNull();
6162
assertThat(this.mongoTemplate.collectionExists("exampleDocuments").block(Duration.ofSeconds(30))).isTrue();
6263
}

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

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.data.mongodb.core.mapping.Document;
2022

2123
/**
@@ -26,23 +28,23 @@
2628
@Document(collection = "exampleDocuments")
2729
public class ExampleDocument {
2830

29-
private String id;
31+
private @Nullable String id;
3032

31-
private String text;
33+
private @Nullable String text;
3234

33-
public String getId() {
35+
public @Nullable String getId() {
3436
return this.id;
3537
}
3638

37-
public void setId(String id) {
39+
public void setId(@Nullable String id) {
3840
this.id = id;
3941
}
4042

41-
public String getText() {
43+
public @Nullable String getText() {
4244
return this.text;
4345
}
4446

45-
public void setText(String text) {
47+
public void setText(@Nullable String text) {
4648
this.text = text;
4749
}
4850

0 commit comments

Comments
 (0)