Skip to content

Commit 1b44baf

Browse files
committed
Add nullability annotations to tests in core/spring-boot-test-autoconfigure
See gh-47263
1 parent e4a58a5 commit 1b44baf

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

core/spring-boot-test-autoconfigure/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ dependencies {
3838
testRuntimeOnly("org.aspectj:aspectjrt")
3939
testRuntimeOnly("org.aspectj:aspectjweaver")
4040
}
41+
42+
tasks.named("compileTestJava") {
43+
options.nullability.checking = "tests"
44+
}

core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/ImportsContextCustomizerFactoryWithAutoConfigurationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.lang.annotation.Retention;
2020
import java.lang.annotation.RetentionPolicy;
2121

22+
import org.jspecify.annotations.Nullable;
2223
import org.junit.jupiter.api.Test;
2324
import org.junit.platform.engine.discovery.DiscoverySelectors;
2425
import org.junit.platform.launcher.Launcher;
@@ -44,7 +45,7 @@
4445
*/
4546
class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
4647

47-
static ApplicationContext contextFromTest;
48+
static @Nullable ApplicationContext contextFromTest;
4849

4950
@Test
5051
void testClassesThatHaveSameAnnotationsShareAContext() {

core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactoryTests.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.test.autoconfigure;
1818

19+
import java.util.Collections;
20+
1921
import org.junit.jupiter.api.Test;
2022

2123
import org.springframework.test.context.ContextCustomizer;
@@ -33,26 +35,31 @@ class OverrideAutoConfigurationContextCustomizerFactoryTests {
3335

3436
@Test
3537
void getContextCustomizerWhenHasNoAnnotationShouldReturnNull() {
36-
ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class, null);
38+
ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class,
39+
Collections.emptyList());
3740
assertThat(customizer).isNull();
3841
}
3942

4043
@Test
4144
void getContextCustomizerWhenHasAnnotationEnabledTrueShouldReturnNull() {
42-
ContextCustomizer customizer = this.factory.createContextCustomizer(WithAnnotationEnabledTrue.class, null);
45+
ContextCustomizer customizer = this.factory.createContextCustomizer(WithAnnotationEnabledTrue.class,
46+
Collections.emptyList());
4347
assertThat(customizer).isNull();
4448
}
4549

4650
@Test
4751
void getContextCustomizerWhenHasAnnotationEnabledFalseShouldReturnCustomizer() {
48-
ContextCustomizer customizer = this.factory.createContextCustomizer(WithAnnotationEnabledFalse.class, null);
52+
ContextCustomizer customizer = this.factory.createContextCustomizer(WithAnnotationEnabledFalse.class,
53+
Collections.emptyList());
4954
assertThat(customizer).isNotNull();
5055
}
5156

5257
@Test
5358
void hashCodeAndEquals() {
54-
ContextCustomizer customizer1 = this.factory.createContextCustomizer(WithAnnotationEnabledFalse.class, null);
55-
ContextCustomizer customizer2 = this.factory.createContextCustomizer(WithSameAnnotation.class, null);
59+
ContextCustomizer customizer1 = this.factory.createContextCustomizer(WithAnnotationEnabledFalse.class,
60+
Collections.emptyList());
61+
ContextCustomizer customizer2 = this.factory.createContextCustomizer(WithSameAnnotation.class,
62+
Collections.emptyList());
5663
assertThat(customizer1).hasSameHashCodeAs(customizer2);
5764
assertThat(customizer1).isEqualTo(customizer1).isEqualTo(customizer2);
5865
}

0 commit comments

Comments
 (0)