mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-23 01:39:02 +00:00
Add nullability annotations to tests in core/spring-boot-test-autoconfigure
See gh-47263
This commit is contained in:
@@ -38,3 +38,7 @@ dependencies {
|
||||
testRuntimeOnly("org.aspectj:aspectjrt")
|
||||
testRuntimeOnly("org.aspectj:aspectjweaver")
|
||||
}
|
||||
|
||||
tasks.named("compileTestJava") {
|
||||
options.nullability.checking = "tests"
|
||||
}
|
||||
|
||||
+2
-1
@@ -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() {
|
||||
|
||||
+12
-5
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user