Add nullability annotations to tests in core/spring-boot-test-autoconfigure

See gh-47263
This commit is contained in:
Moritz Halbritter
2025-10-06 12:03:56 +02:00
parent e4a58a53d0
commit 1b44bafda1
3 changed files with 18 additions and 6 deletions
@@ -38,3 +38,7 @@ dependencies {
testRuntimeOnly("org.aspectj:aspectjrt")
testRuntimeOnly("org.aspectj:aspectjweaver")
}
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}
@@ -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() {
@@ -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);
}