From 9d85c379bd0b6f46a20caf99589f52143fbaf113 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Mon, 6 Oct 2025 12:22:28 +0200 Subject: [PATCH] Add nullability annotations to tests in module/spring-boot-jpa-test See gh-47263 --- module/spring-boot-jpa-test/build.gradle | 4 ++++ .../boot/jpa/test/autoconfigure/TestEntityManagerTests.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/module/spring-boot-jpa-test/build.gradle b/module/spring-boot-jpa-test/build.gradle index 9e24f10891c..254e6210b91 100644 --- a/module/spring-boot-jpa-test/build.gradle +++ b/module/spring-boot-jpa-test/build.gradle @@ -34,3 +34,7 @@ dependencies { testRuntimeOnly("ch.qos.logback:logback-classic") } + +tasks.named("compileTestJava") { + options.nullability.checking = "tests" +} diff --git a/module/spring-boot-jpa-test/src/test/java/org/springframework/boot/jpa/test/autoconfigure/TestEntityManagerTests.java b/module/spring-boot-jpa-test/src/test/java/org/springframework/boot/jpa/test/autoconfigure/TestEntityManagerTests.java index d3197d049c1..dccd36982de 100644 --- a/module/spring-boot-jpa-test/src/test/java/org/springframework/boot/jpa/test/autoconfigure/TestEntityManagerTests.java +++ b/module/spring-boot-jpa-test/src/test/java/org/springframework/boot/jpa/test/autoconfigure/TestEntityManagerTests.java @@ -43,12 +43,15 @@ import static org.mockito.BDDMockito.then; class TestEntityManagerTests { @Mock + @SuppressWarnings("NullAway.Init") private EntityManagerFactory entityManagerFactory; @Mock + @SuppressWarnings("NullAway.Init") private EntityManager entityManager; @Mock + @SuppressWarnings("NullAway.Init") private PersistenceUnitUtil persistenceUnitUtil; private TestEntityManager testEntityManager; @@ -59,6 +62,7 @@ class TestEntityManagerTests { } @Test + @SuppressWarnings("NullAway") // Test null check void createWhenEntityManagerIsNullShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> new TestEntityManager(null)) .withMessageContaining("'entityManagerFactory' must not be null");