Browse Source

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

See gh-47263
pull/47415/head
Moritz Halbritter 2 months ago
parent
commit
9d85c379bd
  1. 4
      module/spring-boot-jpa-test/build.gradle
  2. 4
      module/spring-boot-jpa-test/src/test/java/org/springframework/boot/jpa/test/autoconfigure/TestEntityManagerTests.java

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

@ -34,3 +34,7 @@ dependencies {
testRuntimeOnly("ch.qos.logback:logback-classic") testRuntimeOnly("ch.qos.logback:logback-classic")
} }
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}

4
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 { class TestEntityManagerTests {
@Mock @Mock
@SuppressWarnings("NullAway.Init")
private EntityManagerFactory entityManagerFactory; private EntityManagerFactory entityManagerFactory;
@Mock @Mock
@SuppressWarnings("NullAway.Init")
private EntityManager entityManager; private EntityManager entityManager;
@Mock @Mock
@SuppressWarnings("NullAway.Init")
private PersistenceUnitUtil persistenceUnitUtil; private PersistenceUnitUtil persistenceUnitUtil;
private TestEntityManager testEntityManager; private TestEntityManager testEntityManager;
@ -59,6 +62,7 @@ class TestEntityManagerTests {
} }
@Test @Test
@SuppressWarnings("NullAway") // Test null check
void createWhenEntityManagerIsNullShouldThrowException() { void createWhenEntityManagerIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new TestEntityManager(null)) assertThatIllegalArgumentException().isThrownBy(() -> new TestEntityManager(null))
.withMessageContaining("'entityManagerFactory' must not be null"); .withMessageContaining("'entityManagerFactory' must not be null");

Loading…
Cancel
Save