diff --git a/core/spring-boot-test-autoconfigure/build.gradle b/core/spring-boot-test-autoconfigure/build.gradle index 1fb96603afa..7313537b33d 100644 --- a/core/spring-boot-test-autoconfigure/build.gradle +++ b/core/spring-boot-test-autoconfigure/build.gradle @@ -38,3 +38,7 @@ dependencies { testRuntimeOnly("org.aspectj:aspectjrt") testRuntimeOnly("org.aspectj:aspectjweaver") } + +tasks.named("compileTestJava") { + options.nullability.checking = "tests" +} diff --git a/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/ImportsContextCustomizerFactoryWithAutoConfigurationTests.java b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/ImportsContextCustomizerFactoryWithAutoConfigurationTests.java index fec35567928..bf54b9699f4 100644 --- a/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/ImportsContextCustomizerFactoryWithAutoConfigurationTests.java +++ b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/ImportsContextCustomizerFactoryWithAutoConfigurationTests.java @@ -19,6 +19,7 @@ package org.springframework.boot.test.autoconfigure; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.junit.platform.engine.discovery.DiscoverySelectors; import org.junit.platform.launcher.Launcher; @@ -44,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ class ImportsContextCustomizerFactoryWithAutoConfigurationTests { - static ApplicationContext contextFromTest; + static @Nullable ApplicationContext contextFromTest; @Test void testClassesThatHaveSameAnnotationsShareAContext() { diff --git a/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactoryTests.java b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactoryTests.java index 1e9840f08d2..da4c884a07a 100644 --- a/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactoryTests.java +++ b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactoryTests.java @@ -16,6 +16,8 @@ package org.springframework.boot.test.autoconfigure; +import java.util.Collections; + import org.junit.jupiter.api.Test; import org.springframework.test.context.ContextCustomizer; @@ -33,26 +35,31 @@ class OverrideAutoConfigurationContextCustomizerFactoryTests { @Test void getContextCustomizerWhenHasNoAnnotationShouldReturnNull() { - ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class, null); + ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class, + Collections.emptyList()); assertThat(customizer).isNull(); } @Test void getContextCustomizerWhenHasAnnotationEnabledTrueShouldReturnNull() { - ContextCustomizer customizer = this.factory.createContextCustomizer(WithAnnotationEnabledTrue.class, null); + ContextCustomizer customizer = this.factory.createContextCustomizer(WithAnnotationEnabledTrue.class, + Collections.emptyList()); assertThat(customizer).isNull(); } @Test void getContextCustomizerWhenHasAnnotationEnabledFalseShouldReturnCustomizer() { - ContextCustomizer customizer = this.factory.createContextCustomizer(WithAnnotationEnabledFalse.class, null); + ContextCustomizer customizer = this.factory.createContextCustomizer(WithAnnotationEnabledFalse.class, + Collections.emptyList()); assertThat(customizer).isNotNull(); } @Test void hashCodeAndEquals() { - ContextCustomizer customizer1 = this.factory.createContextCustomizer(WithAnnotationEnabledFalse.class, null); - ContextCustomizer customizer2 = this.factory.createContextCustomizer(WithSameAnnotation.class, null); + ContextCustomizer customizer1 = this.factory.createContextCustomizer(WithAnnotationEnabledFalse.class, + Collections.emptyList()); + ContextCustomizer customizer2 = this.factory.createContextCustomizer(WithSameAnnotation.class, + Collections.emptyList()); assertThat(customizer1).hasSameHashCodeAs(customizer2); assertThat(customizer1).isEqualTo(customizer1).isEqualTo(customizer2); }