From 5c0d2ee18042cc3a4a180f81dc63b870d3bbeb20 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Fri, 19 Sep 2025 12:34:49 +0200 Subject: [PATCH] Add nullability annotations to tests in module/spring-boot-data-ldap See gh-47263 --- module/spring-boot-data-ldap/build.gradle | 4 ++++ ...dapRepositoriesAutoConfigurationTests.java | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/module/spring-boot-data-ldap/build.gradle b/module/spring-boot-data-ldap/build.gradle index eda46105666..2df1a01abc0 100644 --- a/module/spring-boot-data-ldap/build.gradle +++ b/module/spring-boot-data-ldap/build.gradle @@ -38,3 +38,7 @@ dependencies { testRuntimeOnly("ch.qos.logback:logback-classic") } + +tasks.named("compileTestJava") { + options.nullability.checking = "tests" +} diff --git a/module/spring-boot-data-ldap/src/test/java/org/springframework/boot/data/ldap/autoconfigure/DataLdapRepositoriesAutoConfigurationTests.java b/module/spring-boot-data-ldap/src/test/java/org/springframework/boot/data/ldap/autoconfigure/DataLdapRepositoriesAutoConfigurationTests.java index cd349a1709b..19d0a3d0175 100644 --- a/module/spring-boot-data-ldap/src/test/java/org/springframework/boot/data/ldap/autoconfigure/DataLdapRepositoriesAutoConfigurationTests.java +++ b/module/spring-boot-data-ldap/src/test/java/org/springframework/boot/data/ldap/autoconfigure/DataLdapRepositoriesAutoConfigurationTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.data.ldap.autoconfigure; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -39,31 +40,31 @@ import static org.assertj.core.api.Assertions.assertThat; */ class DataLdapRepositoriesAutoConfigurationTests { - private AnnotationConfigApplicationContext context; + private @Nullable AnnotationConfigApplicationContext context; @AfterEach void close() { - if (this.context != null) { - this.context.close(); + if (getContext() != null) { + getContext().close(); } } @Test void testDefaultRepositoryConfiguration() { load(TestConfiguration.class); - assertThat(this.context.getBean(PersonRepository.class)).isNotNull(); + assertThat(getContext().getBean(PersonRepository.class)).isNotNull(); } @Test void testNoRepositoryConfiguration() { load(EmptyConfiguration.class); - assertThat(this.context.getBeanNamesForType(PersonRepository.class)).isEmpty(); + assertThat(getContext().getBeanNamesForType(PersonRepository.class)).isEmpty(); } @Test void doesNotTriggerDefaultRepositoryDetectionIfCustomized() { load(CustomizedConfiguration.class); - assertThat(this.context.getBean(PersonRepository.class)).isNotNull(); + assertThat(getContext().getBean(PersonRepository.class)).isNotNull(); } private void load(Class... configurationClasses) { @@ -75,6 +76,12 @@ class DataLdapRepositoriesAutoConfigurationTests { this.context.refresh(); } + private AnnotationConfigApplicationContext getContext() { + AnnotationConfigApplicationContext context = this.context; + assertThat(context).isNotNull(); + return context; + } + @Configuration(proxyBeanMethods = false) @TestAutoConfigurationPackage(Person.class) static class TestConfiguration {