Nullability fine-tuning around declaration inconsistencies
Issue: SPR-15720 Issue: SPR-15792
This commit is contained in:
@@ -37,6 +37,7 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpRange;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.reactive.AbstractServerHttpRequest;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MimeType;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
@@ -58,15 +59,15 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
|
||||
private final MultiValueMap<String, HttpCookie> cookies;
|
||||
|
||||
@Nullable
|
||||
private final InetSocketAddress remoteAddress;
|
||||
|
||||
private final Flux<DataBuffer> body;
|
||||
|
||||
|
||||
private MockServerHttpRequest(HttpMethod httpMethod, URI uri, String contextPath,
|
||||
private MockServerHttpRequest(HttpMethod httpMethod, URI uri, @Nullable String contextPath,
|
||||
HttpHeaders headers, MultiValueMap<String, HttpCookie> cookies,
|
||||
InetSocketAddress remoteAddress,
|
||||
Publisher<? extends DataBuffer> body) {
|
||||
@Nullable InetSocketAddress remoteAddress, Publisher<? extends DataBuffer> body) {
|
||||
|
||||
super(uri, contextPath, headers);
|
||||
this.httpMethod = httpMethod;
|
||||
@@ -87,6 +88,7 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public InetSocketAddress getRemoteAddress() {
|
||||
return this.remoteAddress;
|
||||
}
|
||||
@@ -351,20 +353,20 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
|
||||
private static final DataBufferFactory BUFFER_FACTORY = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
private final HttpMethod method;
|
||||
|
||||
private final URI url;
|
||||
|
||||
@Nullable
|
||||
private String contextPath;
|
||||
|
||||
private final HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
private final MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>();
|
||||
|
||||
@Nullable
|
||||
private InetSocketAddress remoteAddress;
|
||||
|
||||
|
||||
public DefaultBodyBuilder(HttpMethod method, URI url) {
|
||||
this.method = method;
|
||||
this.url = url;
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.mock.web;
|
||||
|
||||
import javax.servlet.SessionCookieConfig;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Mock implementation of the {@link javax.servlet.SessionCookieConfig} interface.
|
||||
*
|
||||
@@ -27,12 +29,16 @@ import javax.servlet.SessionCookieConfig;
|
||||
*/
|
||||
public class MockSessionCookieConfig implements SessionCookieConfig {
|
||||
|
||||
@Nullable
|
||||
private String name;
|
||||
|
||||
@Nullable
|
||||
private String domain;
|
||||
|
||||
@Nullable
|
||||
private String path;
|
||||
|
||||
@Nullable
|
||||
private String comment;
|
||||
|
||||
private boolean httpOnly;
|
||||
@@ -43,41 +49,45 @@ public class MockSessionCookieConfig implements SessionCookieConfig {
|
||||
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
public void setName(@Nullable String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDomain(String domain) {
|
||||
public void setDomain(@Nullable String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getDomain() {
|
||||
return this.domain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPath(String path) {
|
||||
public void setPath(@Nullable String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComment(String comment) {
|
||||
public void setComment(@Nullable String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getComment() {
|
||||
return this.comment;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,7 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestContext;
|
||||
import org.springframework.test.context.TestContextManager;
|
||||
@@ -99,6 +100,7 @@ public abstract class AbstractJUnit4SpringContextTests implements ApplicationCon
|
||||
* The {@link ApplicationContext} that was injected into this test instance
|
||||
* via {@link #setApplicationContext(ApplicationContext)}.
|
||||
*/
|
||||
@Nullable
|
||||
protected ApplicationContext applicationContext;
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener;
|
||||
@@ -100,8 +101,9 @@ public abstract class AbstractTransactionalJUnit4SpringContextTests extends Abst
|
||||
* The {@code JdbcTemplate} that this base class manages, available to subclasses.
|
||||
* @since 3.2
|
||||
*/
|
||||
protected JdbcTemplate jdbcTemplate;
|
||||
protected final JdbcTemplate jdbcTemplate = new JdbcTemplate();
|
||||
|
||||
@Nullable
|
||||
private String sqlScriptEncoding;
|
||||
|
||||
|
||||
@@ -111,7 +113,7 @@ public abstract class AbstractTransactionalJUnit4SpringContextTests extends Abst
|
||||
*/
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.jdbcTemplate.setDataSource(dataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,6 +206,7 @@ public abstract class AbstractTransactionalJUnit4SpringContextTests extends Abst
|
||||
protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException {
|
||||
DataSource ds = this.jdbcTemplate.getDataSource();
|
||||
Assert.state(ds != null, "No DataSource set");
|
||||
Assert.state(this.applicationContext != null, "No ApplicationContext set");
|
||||
Resource resource = this.applicationContext.getResource(sqlResourcePath);
|
||||
new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(ds);
|
||||
}
|
||||
|
||||
@@ -80,22 +80,18 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
|
||||
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
@Nullable
|
||||
private BootstrapContext bootstrapContext;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setBootstrapContext(BootstrapContext bootstrapContext) {
|
||||
this.bootstrapContext = bootstrapContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BootstrapContext getBootstrapContext() {
|
||||
Assert.state(this.bootstrapContext != null, "No BootstrapContext set");
|
||||
return this.bootstrapContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener;
|
||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||
@@ -84,8 +85,9 @@ public abstract class AbstractTransactionalTestNGSpringContextTests extends Abst
|
||||
* The {@code JdbcTemplate} that this base class manages, available to subclasses.
|
||||
* @since 3.2
|
||||
*/
|
||||
protected JdbcTemplate jdbcTemplate;
|
||||
protected final JdbcTemplate jdbcTemplate = new JdbcTemplate();
|
||||
|
||||
@Nullable
|
||||
private String sqlScriptEncoding;
|
||||
|
||||
|
||||
@@ -95,7 +97,7 @@ public abstract class AbstractTransactionalTestNGSpringContextTests extends Abst
|
||||
*/
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.jdbcTemplate.setDataSource(dataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -166,7 +166,7 @@ public class WebMergedContextConfiguration extends MergedContextConfiguration {
|
||||
* {@link #getContextLoader() ContextLoaders}.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return (this == other || (super.equals(other) &&
|
||||
this.resourceBasePath.equals(((WebMergedContextConfiguration) other).resourceBasePath)));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,6 +38,7 @@ public class DefaultRequestExpectation implements RequestExpectation {
|
||||
|
||||
private final List<RequestMatcher> requestMatchers = new LinkedList<>();
|
||||
|
||||
@Nullable
|
||||
private ResponseCreator responseCreator;
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,6 +22,7 @@ import com.gargoylesoftware.htmlunit.WebConnection;
|
||||
import org.openqa.selenium.Capabilities;
|
||||
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -39,6 +40,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class WebConnectionHtmlUnitDriver extends HtmlUnitDriver {
|
||||
|
||||
@Nullable
|
||||
private WebClient webClient;
|
||||
|
||||
|
||||
@@ -92,16 +94,17 @@ public class WebConnectionHtmlUnitDriver extends HtmlUnitDriver {
|
||||
* @since 4.3
|
||||
*/
|
||||
public WebClient getWebClient() {
|
||||
Assert.state(this.webClient != null, "No WebClient set");
|
||||
return this.webClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link WebConnection} to be used with the {@link WebClient}.
|
||||
* @param webConnection the {@code WebConnection} to use (never {@code null})
|
||||
* @param webConnection the {@code WebConnection} to use
|
||||
*/
|
||||
public void setWebConnection(WebConnection webConnection) {
|
||||
Assert.notNull(webConnection, "WebConnection must not be null");
|
||||
this.webClient.setWebConnection(webConnection);
|
||||
getWebClient().setWebConnection(webConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +112,7 @@ public class WebConnectionHtmlUnitDriver extends HtmlUnitDriver {
|
||||
* @return the current {@code WebConnection}
|
||||
*/
|
||||
public WebConnection getWebConnection() {
|
||||
return this.webClient.getWebConnection();
|
||||
return getWebClient().getWebConnection();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.hamcrest.Matcher;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.hamcrest.core.StringStartsWith;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.test.util.JsonPathExpectationsHelper;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.ResultMatcher;
|
||||
@@ -46,6 +47,7 @@ public class JsonPathResultMatchers {
|
||||
|
||||
private final JsonPathExpectationsHelper jsonPathHelper;
|
||||
|
||||
@Nullable
|
||||
private String prefix;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user