Browse Source

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

See gh-47263
pull/47415/head
Moritz Halbritter 2 months ago
parent
commit
2edd8f9d62
  1. 4
      module/spring-boot-data-jpa-test/build.gradle
  2. 2
      module/spring-boot-data-jpa-test/src/test/java/org/springframework/boot/data/jpa/test/autoconfigure/DataJpaTestIntegrationTests.java
  3. 3
      module/spring-boot-data-jpa-test/src/test/java/org/springframework/boot/data/jpa/test/autoconfigure/ExampleEntity.java

4
module/spring-boot-data-jpa-test/build.gradle

@ -38,3 +38,7 @@ dependencies {
testRuntimeOnly("com.h2database:h2") testRuntimeOnly("com.h2database:h2")
testRuntimeOnly("org.hsqldb:hsqldb") testRuntimeOnly("org.hsqldb:hsqldb")
} }
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}

2
module/spring-boot-data-jpa-test/src/test/java/org/springframework/boot/data/jpa/test/autoconfigure/DataJpaTestIntegrationTests.java

@ -67,7 +67,9 @@ class DataJpaTestIntegrationTests {
ExampleEntity entity = this.entities.persist(new ExampleEntity("spring", "123")); ExampleEntity entity = this.entities.persist(new ExampleEntity("spring", "123"));
this.entities.flush(); this.entities.flush();
Object id = this.entities.getId(entity); Object id = this.entities.getId(entity);
assertThat(id).isNotNull();
ExampleEntity found = this.entities.find(ExampleEntity.class, id); ExampleEntity found = this.entities.find(ExampleEntity.class, id);
assertThat(found).isNotNull();
assertThat(found.getName()).isEqualTo("spring"); assertThat(found.getName()).isEqualTo("spring");
} }

3
module/spring-boot-data-jpa-test/src/test/java/org/springframework/boot/data/jpa/test/autoconfigure/ExampleEntity.java

@ -30,10 +30,13 @@ public class ExampleEntity {
@Id @Id
@GeneratedValue @GeneratedValue
@SuppressWarnings("NullAway.Init")
private Long id; private Long id;
@SuppressWarnings("NullAway.Init")
private String name; private String name;
@SuppressWarnings("NullAway.Init")
private String reference; private String reference;
protected ExampleEntity() { protected ExampleEntity() {

Loading…
Cancel
Save