From 532ea9abc1b5972c61be4343a97439bfd6167f4e Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Wed, 10 Sep 2025 11:45:52 +0200 Subject: [PATCH] Add nullability annotations to tests in core/spring-boot-properties-migrator See gh-47263 --- core/spring-boot-properties-migrator/build.gradle | 6 +++++- .../migrator/PropertiesMigrationListenerTests.java | 3 ++- .../migrator/PropertiesMigrationReporterTests.java | 10 ++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/core/spring-boot-properties-migrator/build.gradle b/core/spring-boot-properties-migrator/build.gradle index e84abc016d6..ab8c6f5a9b1 100644 --- a/core/spring-boot-properties-migrator/build.gradle +++ b/core/spring-boot-properties-migrator/build.gradle @@ -34,4 +34,8 @@ dependencies { tasks.named("javadoc").configure { // No public or protected classes enabled = false -} \ No newline at end of file +} + +tasks.named("compileTestJava") { + options.nullability.checking = "tests" +} diff --git a/core/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationListenerTests.java b/core/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationListenerTests.java index 33a8873114b..fb4d91466d6 100644 --- a/core/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationListenerTests.java +++ b/core/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationListenerTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.context.properties.migrator; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -36,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(OutputCaptureExtension.class) class PropertiesMigrationListenerTests { - private ConfigurableApplicationContext context; + private @Nullable ConfigurableApplicationContext context; @AfterEach void closeContext() { diff --git a/core/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporterTests.java b/core/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporterTests.java index 3b61d75799b..f952f875274 100644 --- a/core/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporterTests.java +++ b/core/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporterTests.java @@ -23,6 +23,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepository; @@ -230,12 +231,13 @@ class PropertiesMigrationReporterTests { } @SuppressWarnings("unchecked") - private Origin getOrigin(PropertySource propertySource, String name) { + private @Nullable Origin getOrigin(PropertySource propertySource, String name) { return ((OriginLookup) propertySource).getOrigin(name); } @SuppressWarnings("unchecked") - private void assertMappedProperty(PropertySource propertySource, String name, Object value, Origin origin) { + private void assertMappedProperty(PropertySource propertySource, String name, Object value, + @Nullable Origin origin) { assertThat(propertySource.containsProperty(name)).isTrue(); assertThat(propertySource.getProperty(name)).isEqualTo(value); if (origin != null) { @@ -269,11 +271,11 @@ class PropertiesMigrationReporterTests { } } - private String createWarningReport(ConfigurationMetadataRepository repository) { + private @Nullable String createWarningReport(ConfigurationMetadataRepository repository) { return createAnalyzer(repository).getReport().getWarningReport(); } - private String createErrorReport(ConfigurationMetadataRepository repository) { + private @Nullable String createErrorReport(ConfigurationMetadataRepository repository) { return createAnalyzer(repository).getReport().getErrorReport(); }