Add nullability annotations to module/spring-boot-test-autoconfigure

See gh-46587
This commit is contained in:
Moritz Halbritter
2025-08-07 11:49:33 +02:00
parent 8b3e9f75a6
commit 3db5b57b86
48 changed files with 194 additions and 63 deletions
@@ -19,6 +19,8 @@ package org.springframework.boot.test.autoconfigure;
import java.util.List;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportMessage;
import org.springframework.boot.context.event.ApplicationFailedEvent;
@@ -89,7 +91,7 @@ class OnFailureConditionReportContextCustomizerFactory implements ContextCustomi
}
}
private static boolean shouldPrintReport(ConfigurableApplicationContext context) {
private static boolean shouldPrintReport(@Nullable ConfigurableApplicationContext context) {
return (context == null) || context.getEnvironment()
.getProperty("spring.test.print-condition-evaluation-report", Boolean.class, true);
}
@@ -18,6 +18,8 @@ package org.springframework.boot.test.autoconfigure;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.AotDetector;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.util.TestPropertyValues;
@@ -37,7 +39,7 @@ import org.springframework.test.context.TestContextAnnotationUtils;
class OverrideAutoConfigurationContextCustomizerFactory implements ContextCustomizerFactory {
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,
public @Nullable ContextCustomizer createContextCustomizer(Class<?> testClass,
List<ContextConfigurationAttributes> configurationAttributes) {
if (AotDetector.useGeneratedArtifacts()) {
return null;
@@ -59,7 +61,7 @@ class OverrideAutoConfigurationContextCustomizerFactory implements ContextCustom
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
return (obj != null) && (obj.getClass() == getClass());
}
@@ -18,6 +18,8 @@ package org.springframework.boot.test.autoconfigure;
import java.lang.annotation.Annotation;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.MergedAnnotation;
@@ -40,16 +42,17 @@ public abstract class TestSliceTestContextBootstrapper<T extends Annotation> ext
@SuppressWarnings("unchecked")
protected TestSliceTestContextBootstrapper() {
this.annotationType = (Class<T>) ResolvableType.forClass(getClass())
Class<T> annotationType = (Class<T>) ResolvableType.forClass(getClass())
.as(TestSliceTestContextBootstrapper.class)
.getGeneric(0)
.resolve();
Assert.notNull(this.annotationType, "'%s' doesn't contain type parameter of '%s'"
.formatted(getClass().getName(), TestSliceTestContextBootstrapper.class.getName()));
Assert.notNull(annotationType, "'%s' doesn't contain type parameter of '%s'".formatted(getClass().getName(),
TestSliceTestContextBootstrapper.class.getName()));
this.annotationType = annotationType;
}
@Override
protected String[] getProperties(Class<?> testClass) {
protected String @Nullable [] getProperties(Class<?> testClass) {
MergedAnnotation<T> annotation = MergedAnnotations.search(SearchStrategy.TYPE_HIERARCHY)
.withEnclosingClasses(TestContextAnnotationUtils::searchEnclosingClass)
.from(testClass)
@@ -19,6 +19,8 @@ package org.springframework.boot.test.autoconfigure.actuate.observability;
import java.util.List;
import java.util.Objects;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
@@ -50,9 +52,9 @@ class ObservabilityContextCustomizerFactory implements ContextCustomizerFactory
private static class DisableObservabilityContextCustomizer implements ContextCustomizer {
private final AutoConfigureObservability annotation;
private final @Nullable AutoConfigureObservability annotation;
DisableObservabilityContextCustomizer(AutoConfigureObservability annotation) {
DisableObservabilityContextCustomizer(@Nullable AutoConfigureObservability annotation) {
this.annotation = annotation;
}
@@ -85,7 +87,7 @@ class ObservabilityContextCustomizerFactory implements ContextCustomizerFactory
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
@@ -17,4 +17,7 @@
/**
* Auto-configuration for handling observability in tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.actuate.observability;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for core parts common to most Spring Boot applications.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.core;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Data Cassandra tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.data.cassandra;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Data Couchbase tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.data.couchbase;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Data Elasticsearch tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.data.elasticsearch;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Data JDBC tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.data.jdbc;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Data LDAP tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.data.ldap;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Data Mongo tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.data.mongo;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Data Neo4j tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.data.neo4j;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Data R2DBC tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.data.r2dbc;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Data Redis tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.data.redis;
import org.jspecify.annotations.NullMarked;
@@ -22,6 +22,8 @@ import java.util.Arrays;
import java.util.Objects;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.boot.context.TypeExcludeFilter;
import org.springframework.context.annotation.ComponentScan.Filter;
@@ -41,6 +43,7 @@ import org.springframework.util.ObjectUtils;
public abstract class AnnotationCustomizableTypeExcludeFilter extends TypeExcludeFilter
implements BeanClassLoaderAware {
@SuppressWarnings("NullAway.Init")
private ClassLoader classLoader;
@Override
@@ -113,11 +116,11 @@ public abstract class AnnotationCustomizableTypeExcludeFilter extends TypeExclud
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (getClass() != obj.getClass()) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
AnnotationCustomizableTypeExcludeFilter other = (AnnotationCustomizableTypeExcludeFilter) obj;
@@ -26,6 +26,7 @@ import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
import org.springframework.util.Assert;
/**
* {@link AnnotationCustomizableTypeExcludeFilter} that can be used to any test annotation
@@ -90,7 +91,9 @@ public abstract class StandardAnnotationCustomizableTypeExcludeFilter<A extends
protected Class<A> getAnnotationType() {
ResolvableType type = ResolvableType.forClass(StandardAnnotationCustomizableTypeExcludeFilter.class,
getClass());
return (Class<A>) type.resolveGeneric();
Class<A> generic = (Class<A>) type.resolveGeneric();
Assert.state(generic != null, "'generic' must not be null");
return generic;
}
}
@@ -22,6 +22,8 @@ import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.context.TypeExcludeFilter;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.type.classreading.MetadataReader;
@@ -70,7 +72,7 @@ class TypeExcludeFiltersContextCustomizer implements ContextCustomizer {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
return (obj != null) && (getClass() == obj.getClass())
&& this.filters.equals(((TypeExcludeFiltersContextCustomizer) obj).filters);
}
@@ -20,6 +20,8 @@ import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.AotDetector;
import org.springframework.boot.context.TypeExcludeFilter;
import org.springframework.test.context.ContextConfigurationAttributes;
@@ -27,7 +29,6 @@ import org.springframework.test.context.ContextCustomizer;
import org.springframework.test.context.ContextCustomizerFactory;
import org.springframework.test.context.TestContextAnnotationUtils;
import org.springframework.test.context.TestContextAnnotationUtils.AnnotationDescriptor;
import org.springframework.util.ObjectUtils;
/**
* {@link ContextCustomizerFactory} to support
@@ -41,17 +42,17 @@ class TypeExcludeFiltersContextCustomizerFactory implements ContextCustomizerFac
private static final Class<?>[] NO_FILTERS = {};
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,
public @Nullable ContextCustomizer createContextCustomizer(Class<?> testClass,
List<ContextConfigurationAttributes> configurationAttributes) {
if (AotDetector.useGeneratedArtifacts()) {
return null;
}
AnnotationDescriptor<TypeExcludeFilters> descriptor = TestContextAnnotationUtils
.findAnnotationDescriptor(testClass, TypeExcludeFilters.class);
Class<?>[] filterClasses = (descriptor != null) ? descriptor.getAnnotation().value() : NO_FILTERS;
if (ObjectUtils.isEmpty(filterClasses)) {
if (descriptor == null) {
return null;
}
Class<?>[] filterClasses = descriptor.getAnnotation().value();
return createContextCustomizer(descriptor.getRootDeclaringClass(), filterClasses);
}
@@ -18,4 +18,7 @@
* Helper utilities for using {@link org.springframework.boot.context.TypeExcludeFilter}
* with auto-configured tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.filter;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for GraphQL testing.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.graphql;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for GraphQL tester.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.graphql.tester;
import org.jspecify.annotations.NullMarked;
@@ -25,6 +25,7 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.AotDetector;
import org.springframework.beans.BeansException;
@@ -64,6 +65,7 @@ import org.springframework.core.env.PropertySource;
import org.springframework.core.type.MethodMetadata;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -153,7 +155,8 @@ public final class TestDatabaseAutoConfiguration {
return beanDefinition;
}
private BeanDefinitionHolder getDataSourceBeanDefinition(ConfigurableListableBeanFactory beanFactory) {
private @Nullable BeanDefinitionHolder getDataSourceBeanDefinition(
ConfigurableListableBeanFactory beanFactory) {
String[] beanNames = beanFactory.getBeanNamesForType(DataSource.class);
if (ObjectUtils.isEmpty(beanNames)) {
logger.warn("No DataSource beans found, embedded version will not be used");
@@ -228,7 +231,7 @@ public final class TestDatabaseAutoConfiguration {
return false;
}
private boolean isDynamicValuesPropertySource(PropertySource<?> propertySource) {
private boolean isDynamicValuesPropertySource(@Nullable PropertySource<?> propertySource) {
return propertySource != null
&& DYNAMIC_VALUES_PROPERTY_SOURCE_CLASS.equals(propertySource.getClass().getName());
}
@@ -242,8 +245,10 @@ public final class TestDatabaseAutoConfiguration {
static class EmbeddedDataSourceFactoryBean implements FactoryBean<DataSource>, EnvironmentAware, InitializingBean {
@SuppressWarnings("NullAway.Init")
private EmbeddedDataSourceFactory factory;
@SuppressWarnings("NullAway.Init")
private EmbeddedDatabase embeddedDatabase;
@Override
@@ -292,7 +297,9 @@ public final class TestDatabaseAutoConfiguration {
"Failed to replace DataSource with an embedded database for tests. If "
+ "you want an embedded database please put a supported one "
+ "on the classpath or tune the replace attribute of @AutoConfigureTestDatabase.");
return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(connection.getType()).build();
EmbeddedDatabaseType type = connection.getType();
Assert.state(type != null, "'type' must not be null");
return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(type).build();
}
}
@@ -17,4 +17,7 @@
/**
* Auto-configuration for JDBC tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.jdbc;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for jOOQ tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.jooq;
import org.jspecify.annotations.NullMarked;
@@ -18,10 +18,12 @@ package org.springframework.boot.test.autoconfigure.json;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import jakarta.json.bind.Jsonb;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.hint.ExecutableMode;
import org.springframework.aot.hint.MemberCategory;
@@ -49,6 +51,7 @@ import org.springframework.context.annotation.ImportRuntimeHints;
import org.springframework.context.annotation.Scope;
import org.springframework.core.ResolvableType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
/**
@@ -154,9 +157,9 @@ public final class JsonTestersAutoConfiguration {
private final Class<?> objectType;
private final M marshaller;
private final @Nullable M marshaller;
JsonTesterFactoryBean(Class<?> objectType, M marshaller) {
JsonTesterFactoryBean(Class<?> objectType, @Nullable M marshaller) {
this.objectType = objectType;
this.marshaller = marshaller;
}
@@ -232,12 +235,12 @@ public final class JsonTestersAutoConfiguration {
}
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
ReflectionHints reflection = hints.reflection();
reflection.registerType(this.tester, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
reflection.registerMethod(
ReflectionUtils.findMethod(this.tester, "initialize", Class.class, ResolvableType.class),
ExecutableMode.INVOKE);
Method method = ReflectionUtils.findMethod(this.tester, "initialize", Class.class, ResolvableType.class);
Assert.state(method != null, "'method' must not be null");
reflection.registerMethod(method, ExecutableMode.INVOKE);
}
}
@@ -245,11 +248,12 @@ public final class JsonTestersAutoConfiguration {
static class BasicJsonTesterRuntimeHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
ReflectionHints reflection = hints.reflection();
reflection.registerType(BasicJsonTester.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
reflection.registerMethod(ReflectionUtils.findMethod(BasicJsonTester.class, "initialize", Class.class),
ExecutableMode.INVOKE);
Method method = ReflectionUtils.findMethod(BasicJsonTester.class, "initialize", Class.class);
Assert.state(method != null, "'method' must not be null");
reflection.registerMethod(method, ExecutableMode.INVOKE);
}
}
@@ -17,4 +17,7 @@
/**
* Auto-configuration for JSON tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.json;
import org.jspecify.annotations.NullMarked;
@@ -19,6 +19,7 @@ package org.springframework.boot.test.autoconfigure.orm.jpa;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.PersistenceUnitUtil;
import org.jspecify.annotations.Nullable;
import org.springframework.orm.jpa.EntityManagerFactoryUtils;
import org.springframework.util.Assert;
@@ -55,7 +56,7 @@ public class TestEntityManager {
* @param entity the source entity
* @return the ID of the newly persisted entity
*/
public Object persistAndGetId(Object entity) {
public @Nullable Object persistAndGetId(Object entity) {
persist(entity);
return getId(entity);
}
@@ -72,7 +73,7 @@ public class TestEntityManager {
* @param idType the ID type
* @return the ID of the newly persisted entity
*/
public <T> T persistAndGetId(Object entity, Class<T> idType) {
public <T> @Nullable T persistAndGetId(Object entity, Class<T> idType) {
persist(entity);
return getId(entity, idType);
}
@@ -159,7 +160,7 @@ public class TestEntityManager {
* @return the found entity or {@code null} if the entity does not exist
* @see #getId(Object)
*/
public <E> E find(Class<E> entityClass, Object primaryKey) {
public <E> @Nullable E find(Class<E> entityClass, Object primaryKey) {
return getEntityManager().find(entityClass, primaryKey);
}
@@ -207,7 +208,7 @@ public class TestEntityManager {
* @return the ID of the entity or {@code null}
* @see #getId(Object, Class)
*/
public Object getId(Object entity) {
public @Nullable Object getId(Object entity) {
return this.entityManagerFactory.getPersistenceUnitUtil().getIdentifier(entity);
}
@@ -221,7 +222,7 @@ public class TestEntityManager {
* @see #getId(Object)
*/
@SuppressWarnings("unchecked")
public <T> T getId(Object entity, Class<T> idType) {
public <T> @Nullable T getId(Object entity, Class<T> idType) {
Object id = getId(entity);
Assert.isInstanceOf(idType, id, "ID mismatch:");
return (T) id;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Data JPA tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.orm.jpa;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Test auto-configuration support.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure;
import org.jspecify.annotations.NullMarked;
@@ -25,6 +25,8 @@ import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jspecify.annotations.Nullable;
import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.annotation.MergedAnnotationPredicates;
import org.springframework.core.annotation.MergedAnnotations;
@@ -152,7 +154,7 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?>
}
@Override
public Object getProperty(String name) {
public @Nullable Object getProperty(String name) {
return this.properties.get(name);
}
@@ -166,7 +168,7 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?>
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
}
@@ -19,6 +19,8 @@ package org.springframework.boot.test.autoconfigure.properties;
import java.util.Set;
import java.util.stream.Collectors;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ConfigurableApplicationContext;
@@ -57,7 +59,7 @@ class PropertyMappingContextCustomizer implements ContextCustomizer {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
return (obj != null) && (getClass() == obj.getClass())
&& this.propertySource.equals(((PropertyMappingContextCustomizer) obj).propertySource);
}
@@ -17,4 +17,7 @@
/**
* Support for mapping annotation attribute values in the Spring {@code Environment}.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.properties;
import org.jspecify.annotations.NullMarked;
@@ -16,6 +16,8 @@
package org.springframework.boot.test.autoconfigure.restdocs;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.boot.test.autoconfigure.web.servlet.MockMvcBuilderCustomizer;
@@ -36,10 +38,10 @@ public class RestDocsMockMvcBuilderCustomizer implements InitializingBean, MockM
private final MockMvcRestDocumentationConfigurer delegate;
private final RestDocumentationResultHandler resultHandler;
private final @Nullable RestDocumentationResultHandler resultHandler;
RestDocsMockMvcBuilderCustomizer(RestDocsProperties properties, MockMvcRestDocumentationConfigurer delegate,
RestDocumentationResultHandler resultHandler) {
@Nullable RestDocumentationResultHandler resultHandler) {
this.properties = properties;
this.delegate = delegate;
this.resultHandler = resultHandler;
@@ -16,6 +16,8 @@
package org.springframework.boot.test.autoconfigure.restdocs;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
@@ -32,39 +34,39 @@ public class RestDocsProperties {
/**
* The URI scheme for to use (for example http).
*/
private String uriScheme;
private @Nullable String uriScheme;
/**
* The URI host to use.
*/
private String uriHost;
private @Nullable String uriHost;
/**
* The URI port to use.
*/
private Integer uriPort;
private @Nullable Integer uriPort;
public String getUriScheme() {
public @Nullable String getUriScheme() {
return this.uriScheme;
}
public void setUriScheme(String uriScheme) {
public void setUriScheme(@Nullable String uriScheme) {
this.uriScheme = uriScheme;
}
public String getUriHost() {
public @Nullable String getUriHost() {
return this.uriHost;
}
public void setUriHost(String uriHost) {
public void setUriHost(@Nullable String uriHost) {
this.uriHost = uriHost;
}
public Integer getUriPort() {
public @Nullable Integer getUriPort() {
return this.uriPort;
}
public void setUriPort(Integer uriPort) {
public void setUriPort(@Nullable Integer uriPort) {
this.uriPort = uriPort;
}
@@ -16,6 +16,8 @@
package org.springframework.boot.test.autoconfigure.restdocs;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.core.Ordered;
import org.springframework.restdocs.ManualRestDocumentation;
@@ -72,7 +74,7 @@ public class RestDocsTestExecutionListener extends AbstractTestExecutionListener
}
}
private ManualRestDocumentation findManualRestDocumentation(TestContext testContext) {
private @Nullable ManualRestDocumentation findManualRestDocumentation(TestContext testContext) {
try {
return testContext.getApplicationContext().getBean(ManualRestDocumentation.class);
}
@@ -16,6 +16,8 @@
package org.springframework.boot.test.autoconfigure.restdocs;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.web.server.test.client.reactive.WebTestClientBuilderCustomizer;
import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentationConfigurer;
import org.springframework.test.web.reactive.server.WebTestClient;
@@ -57,7 +59,7 @@ class RestDocsWebTestClientBuilderCustomizer implements WebTestClientBuilderCust
builder.baseUrl(baseUrl);
}
private boolean isStandardPort(String scheme, Integer port) {
private boolean isStandardPort(@Nullable String scheme, @Nullable Integer port) {
if (port == null) {
return true;
}
@@ -18,11 +18,14 @@ package org.springframework.boot.test.autoconfigure.restdocs;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.restdocs.ManualRestDocumentation;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
@@ -36,10 +39,11 @@ class RestDocumentationContextProviderRegistrar implements ImportBeanDefinitionR
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
Map<String, Object> annotationAttributes = importingClassMetadata
Map<String, @Nullable Object> annotationAttributes = importingClassMetadata
.getAnnotationAttributes(AutoConfigureRestDocs.class.getName());
BeanDefinitionBuilder definitionBuilder = BeanDefinitionBuilder
.rootBeanDefinition(ManualRestDocumentation.class);
Assert.state(annotationAttributes != null, "'annotationAttributes' must not be null");
String outputDir = (String) annotationAttributes.get("outputDir");
if (StringUtils.hasText(outputDir)) {
definitionBuilder.addConstructorArgValue(outputDir);
@@ -17,4 +17,7 @@
/**
* Auto-configuration for tests using Spring REST Docs.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.restdocs;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for web clients.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.web.client;
import org.jspecify.annotations.NullMarked;
@@ -20,6 +20,8 @@ import java.time.Duration;
import java.util.Collection;
import java.util.function.Consumer;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.http.codec.CodecCustomizer;
import org.springframework.boot.web.server.test.client.reactive.WebTestClientBuilderCustomizer;
import org.springframework.http.codec.ClientCodecConfigurer;
@@ -41,7 +43,7 @@ public class SpringBootWebTestClientBuilderCustomizer implements WebTestClientBu
private final Collection<CodecCustomizer> codecCustomizers;
private Duration timeout;
private @Nullable Duration timeout;
/**
* Create a new {@code SpringBootWebTestClientBuilderCustomizer} that will configure
@@ -52,7 +54,7 @@ public class SpringBootWebTestClientBuilderCustomizer implements WebTestClientBu
this.codecCustomizers = codecCustomizers;
}
public void setTimeout(Duration timeout) {
public void setTimeout(@Nullable Duration timeout) {
this.timeout = timeout;
}
@@ -17,4 +17,7 @@
/**
* Auto-configuration for reactive web tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.web.reactive;
import org.jspecify.annotations.NullMarked;
@@ -29,6 +29,7 @@ import jakarta.servlet.Filter;
import jakarta.servlet.annotation.WebInitParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -99,7 +100,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi
}
}
private ResultHandler getPrintHandler() {
private @Nullable ResultHandler getPrintHandler() {
LinesWriter writer = getLinesWriter();
if (writer == null) {
return null;
@@ -110,7 +111,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi
return new LinesWritingResultHandler(writer);
}
private LinesWriter getLinesWriter() {
private @Nullable LinesWriter getLinesWriter() {
if (this.print == MockMvcPrint.NONE) {
return null;
}
@@ -129,8 +130,9 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi
}
private void addFilter(ConfigurableMockMvcBuilder<?> builder, AbstractFilterRegistrationBean<?> registration) {
Filter filter = registration.getFilter();
Collection<String> urls = registration.getUrlPatterns();
Filter filter = registration.getFilter();
Assert.state(filter != null, "'filter' must not be null");
builder.addFilter(filter, registration.getFilterName(), registration.getInitParameters(),
registration.determineDispatcherTypes(), StringUtils.toStringArray(urls));
}
@@ -199,7 +201,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi
}
@Override
public void printValue(String label, Object value) {
public void printValue(String label, @Nullable Object value) {
if (value != null && value.getClass().isArray()) {
value = CollectionUtils.arrayToList(value);
}
@@ -259,7 +261,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi
this.delegate.write(this.lines.get());
}
static DeferredLinesWriter get(ApplicationContext applicationContext) {
static @Nullable DeferredLinesWriter get(ApplicationContext applicationContext) {
try {
return applicationContext.getBean(BEAN_NAME, DeferredLinesWriter.class);
}
@@ -16,6 +16,8 @@
package org.springframework.boot.test.autoconfigure.web.servlet;
import org.jspecify.annotations.Nullable;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.ContextCustomizer;
import org.springframework.test.context.MergedContextConfiguration;
@@ -35,7 +37,7 @@ class WebDriverContextCustomizer implements ContextCustomizer {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
}
@@ -19,6 +19,7 @@ package org.springframework.boot.test.autoconfigure.web.servlet;
import java.util.HashMap;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.WebDriver;
import org.springframework.beans.factory.ObjectFactory;
@@ -78,12 +79,12 @@ public class WebDriverScope implements Scope {
}
@Override
public Object resolveContextualObject(String key) {
public @Nullable Object resolveContextualObject(String key) {
return null;
}
@Override
public String getConversationId() {
public @Nullable String getConversationId() {
return null;
}
@@ -137,7 +138,7 @@ public class WebDriverScope implements Scope {
* @param context the application context
* @return the web driver scope or {@code null}
*/
static WebDriverScope getFrom(ApplicationContext context) {
static @Nullable WebDriverScope getFrom(ApplicationContext context) {
if (context instanceof ConfigurableApplicationContext configurableContext) {
Scope scope = configurableContext.getBeanFactory().getRegisteredScope(NAME);
return (scope instanceof WebDriverScope webDriverScope) ? webDriverScope : null;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Spring MVC tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.web.servlet;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for web service clients.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.webservices.client;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for web service server tests.
*/
@NullMarked
package org.springframework.boot.test.autoconfigure.webservices.server;
import org.jspecify.annotations.NullMarked;