mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Address deprecation warnings
This commit addresses warnings across the code base related to: - internal and public deprecations in Spring Framework - deprecated Locale constructors - deprecated URL constructors - deprecated Thread#getId method
This commit is contained in:
+3
-2
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -150,7 +151,7 @@ class YamlProcessorTests {
|
||||
|
||||
@Test
|
||||
void customTypeNotSupportedByDefault() throws Exception {
|
||||
URL url = new URL("https://localhost:9000/");
|
||||
URL url = URI.create("https://localhost:9000/").toURL();
|
||||
setYaml("value: !!java.net.URL [\"" + url + "\"]");
|
||||
assertThatExceptionOfType(ComposerException.class)
|
||||
.isThrownBy(() -> this.processor.process((properties, map) -> {}))
|
||||
@@ -161,7 +162,7 @@ class YamlProcessorTests {
|
||||
void customTypesSupportedDueToExplicitConfiguration() throws Exception {
|
||||
this.processor.setSupportedTypes(URL.class, String.class);
|
||||
|
||||
URL url = new URL("https://localhost:9000/");
|
||||
URL url = URI.create("https://localhost:9000/").toURL();
|
||||
setYaml("value: !!java.net.URL [!!java.lang.String [\"" + url + "\"]]");
|
||||
|
||||
this.processor.process((properties, map) -> {
|
||||
|
||||
+4
-4
@@ -523,7 +523,7 @@ class BeanFactoryGenericsTests {
|
||||
new ClassPathResource("genericBeanTests.xml", getClass()));
|
||||
|
||||
NamedUrlList list = bf.getBean("list", NamedUrlList.class);
|
||||
assertThat(list).containsExactly(new URL("http://localhost:8080"));
|
||||
assertThat(list).containsExactly(URI.create("http://localhost:8080").toURL());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -533,7 +533,7 @@ class BeanFactoryGenericsTests {
|
||||
new ClassPathResource("genericBeanTests.xml", getClass()));
|
||||
|
||||
NamedUrlSet set = bf.getBean("set", NamedUrlSet.class);
|
||||
assertThat(set).containsExactly(new URL("http://localhost:8080"));
|
||||
assertThat(set).containsExactly(URI.create("http://localhost:8080").toURL());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -543,7 +543,7 @@ class BeanFactoryGenericsTests {
|
||||
new ClassPathResource("genericBeanTests.xml", getClass()));
|
||||
|
||||
NamedUrlMap map = bf.getBean("map", NamedUrlMap.class);
|
||||
assertThat(map).containsExactly(entry(10, new URL("http://localhost:8080")));
|
||||
assertThat(map).containsExactly(entry(10, URI.create("http://localhost:8080").toURL()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -577,7 +577,7 @@ class BeanFactoryGenericsTests {
|
||||
new ClassPathResource("genericBeanTests.xml", getClass()));
|
||||
|
||||
UrlSet urlSet = bf.getBean("setBean", UrlSet.class);
|
||||
assertThat(urlSet).containsExactly(new URL("https://www.springframework.org"));
|
||||
assertThat(urlSet).containsExactly(URI.create("https://www.springframework.org").toURL());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
@@ -97,6 +97,7 @@ class ResourceBundleMessageSourceTests {
|
||||
doTestMessageAccess(true, false, true, true, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
protected void doTestMessageAccess(
|
||||
boolean reloadable, boolean fallbackToSystemLocale,
|
||||
boolean expectGermanFallback, boolean useCodeAsDefaultMessage, boolean alwaysUseMessageFormat) {
|
||||
@@ -406,6 +407,7 @@ class ResourceBundleMessageSourceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void reloadableResourceBundleMessageSourceFileNameCalculation() {
|
||||
ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource();
|
||||
|
||||
|
||||
+1
@@ -225,6 +225,7 @@ class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Thread.getId() on JDK 19
|
||||
void mxBeanOperationAccess() throws Exception {
|
||||
MBeanClientInterceptor interceptor = new MBeanClientInterceptor();
|
||||
interceptor.setServer(ManagementFactory.getPlatformMBeanServer());
|
||||
|
||||
+2
@@ -82,6 +82,7 @@ public abstract class AbstractDataBufferDecoder<T> extends AbstractDecoder<T> {
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public Flux<T> decode(Publisher<DataBuffer> input, ResolvableType elementType,
|
||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||
|
||||
@@ -90,6 +91,7 @@ public abstract class AbstractDataBufferDecoder<T> extends AbstractDecoder<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public Mono<T> decodeToMono(Publisher<DataBuffer> input, ResolvableType elementType,
|
||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||
|
||||
|
||||
+1
@@ -611,6 +611,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // for deprecated URL constructor on JDK 20
|
||||
private Set<ClassPathManifestEntry> getClassPathManifestEntriesFromJar(File jar) throws IOException {
|
||||
URL base = jar.toURI().toURL();
|
||||
File parent = jar.getAbsoluteFile().getParentFile();
|
||||
|
||||
@@ -132,7 +132,7 @@ public abstract class StringUtils {
|
||||
*/
|
||||
@Contract("null -> false")
|
||||
public static boolean hasLength(@Nullable CharSequence str) {
|
||||
return (str != null && !str.isEmpty()); // as of JDK 15
|
||||
return (str != null && !str.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -385,6 +385,7 @@ class ResourceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for deprecated URL constructor on JDK 20
|
||||
void filenameIsExtractedFromURL() throws Exception {
|
||||
assertThat(new UrlResource(new URL("file:test?argh")).getFilename()).isEqualTo("test");
|
||||
assertThat(new UrlResource(new URL("file:/test?argh")).getFilename()).isEqualTo("test");
|
||||
|
||||
+2
@@ -130,6 +130,7 @@ class PathMatchingResourcePatternResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for deprecated URL constructor on JDK 20
|
||||
void encodedHashtagInPath() throws IOException {
|
||||
Path rootDir = Paths.get("src/test/resources/custom%23root").toAbsolutePath();
|
||||
URL root = new URL("file:" + rootDir + "/");
|
||||
@@ -441,6 +442,7 @@ class PathMatchingResourcePatternResolverTests {
|
||||
copyClasses(LogFactory.class, "commons-logging");
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // for deprecated URL constructor on JDK 20
|
||||
private String copyClasses(Class<?> sourceClass, String destinationName) throws URISyntaxException, IOException {
|
||||
Path destination = this.temp.resolve(destinationName);
|
||||
String resourcePath = ClassUtils.convertClassNameToResourcePath(
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -991,10 +990,10 @@ class ObjectUtilsTests {
|
||||
@Test
|
||||
void nullSafeConciseToStringForURL() throws Exception {
|
||||
String url = "https://www.example.com/?foo=1&bar=2&baz=3";
|
||||
assertThat(ObjectUtils.nullSafeConciseToString(new URL(url))).isEqualTo(url);
|
||||
assertThat(ObjectUtils.nullSafeConciseToString(URI.create(url).toURL())).isEqualTo(url);
|
||||
|
||||
url += "&qux=" + "4".repeat(60);
|
||||
assertThat(ObjectUtils.nullSafeConciseToString(new URL(url)))
|
||||
assertThat(ObjectUtils.nullSafeConciseToString(URI.create(url).toURL()))
|
||||
.hasSize(truncatedLength)
|
||||
.startsWith(url.subSequence(0, 100))
|
||||
.endsWith(truncated);
|
||||
|
||||
@@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class ResourceUtilsTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for deprecated URL constructor on JDK 20
|
||||
void isJarURL() throws Exception {
|
||||
assertThat(ResourceUtils.isJarURL(new URL("jar:file:myjar.jar!/mypath"))).isTrue();
|
||||
assertThat(ResourceUtils.isJarURL(new URL(null, "zip:file:myjar.jar!/mypath", new DummyURLStreamHandler()))).isTrue();
|
||||
@@ -40,6 +41,7 @@ class ResourceUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for deprecated URL constructor on JDK 20
|
||||
void extractJarFileURL() throws Exception {
|
||||
assertThat(ResourceUtils.extractJarFileURL(new URL("jar:file:myjar.jar!/mypath"))).isEqualTo(new URL("file:myjar.jar"));
|
||||
assertThat(ResourceUtils.extractJarFileURL(new URL(null, "jar:myjar.jar!/mypath", new DummyURLStreamHandler()))).isEqualTo(new URL("file:/myjar.jar"));
|
||||
@@ -53,6 +55,7 @@ class ResourceUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for deprecated URL constructor on JDK 20
|
||||
void extractArchiveURL() throws Exception {
|
||||
assertThat(ResourceUtils.extractArchiveURL(new URL("jar:file:myjar.jar!/mypath"))).isEqualTo(new URL("file:myjar.jar"));
|
||||
assertThat(ResourceUtils.extractArchiveURL(new URL(null, "jar:myjar.jar!/mypath", new DummyURLStreamHandler()))).isEqualTo(new URL("file:/myjar.jar"));
|
||||
|
||||
@@ -734,6 +734,7 @@ class StringUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void invalidLocaleWithLocaleString() {
|
||||
assertThat(StringUtils.parseLocaleString("invalid")).isEqualTo(new Locale("invalid"));
|
||||
assertThat(StringUtils.parseLocaleString("invalidvalue")).isEqualTo(new Locale("invalidvalue"));
|
||||
@@ -742,6 +743,7 @@ class StringUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void invalidLocaleWithLanguageTag() {
|
||||
assertThat(StringUtils.parseLocale("invalid")).isEqualTo(new Locale("invalid"));
|
||||
assertThat(StringUtils.parseLocale("invalidvalue")).isEqualTo(new Locale("invalidvalue"));
|
||||
|
||||
+5
-4
@@ -17,6 +17,7 @@
|
||||
package org.springframework.mock.web;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -548,7 +549,7 @@ class MockHttpServletRequestTests {
|
||||
@Test
|
||||
void getRequestURLWithIpv6AddressViaServerNameWithoutPort() throws Exception {
|
||||
request.setServerName("[::ffff:abcd:abcd]");
|
||||
URL url = new java.net.URL(request.getRequestURL().toString());
|
||||
URL url = URI.create(request.getRequestURL().toString()).toURL();
|
||||
assertThat(url).asString().isEqualTo("http://[::ffff:abcd:abcd]");
|
||||
}
|
||||
|
||||
@@ -556,7 +557,7 @@ class MockHttpServletRequestTests {
|
||||
void getRequestURLWithIpv6AddressViaServerNameWithPort() throws Exception {
|
||||
request.setServerName("[::ffff:abcd:abcd]");
|
||||
request.setServerPort(9999);
|
||||
URL url = new java.net.URL(request.getRequestURL().toString());
|
||||
URL url = URI.create(request.getRequestURL().toString()).toURL();
|
||||
assertThat(url).asString().isEqualTo("http://[::ffff:abcd:abcd]:9999");
|
||||
}
|
||||
|
||||
@@ -571,14 +572,14 @@ class MockHttpServletRequestTests {
|
||||
@Test
|
||||
void getRequestURLWithIpv6AddressViaHostHeaderWithoutPort() throws Exception {
|
||||
request.addHeader(HOST, "[::ffff:abcd:abcd]");
|
||||
URL url = new java.net.URL(request.getRequestURL().toString());
|
||||
URL url = URI.create(request.getRequestURL().toString()).toURL();
|
||||
assertThat(url).asString().isEqualTo("http://[::ffff:abcd:abcd]");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRequestURLWithIpv6AddressViaHostHeaderWithPort() throws Exception {
|
||||
request.addHeader(HOST, "[::ffff:abcd:abcd]:9999");
|
||||
URL url = new java.net.URL(request.getRequestURL().toString());
|
||||
URL url = URI.create(request.getRequestURL().toString()).toURL();
|
||||
assertThat(url).asString().isEqualTo("http://[::ffff:abcd:abcd]:9999");
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@
|
||||
package org.springframework.test.web.servlet.htmlunit;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
|
||||
import org.htmlunit.WebRequest;
|
||||
|
||||
@@ -32,11 +32,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
abstract class AbstractWebRequestMatcherTests {
|
||||
|
||||
protected void assertMatches(WebRequestMatcher matcher, String url) throws MalformedURLException {
|
||||
assertThat(matcher.matches(new WebRequest(new URL(url)))).isTrue();
|
||||
assertThat(matcher.matches(new WebRequest(URI.create(url).toURL()))).isTrue();
|
||||
}
|
||||
|
||||
protected void assertDoesNotMatch(WebRequestMatcher matcher, String url) throws MalformedURLException {
|
||||
assertThat(matcher.matches(new WebRequest(new URL(url)))).isFalse();
|
||||
assertThat(matcher.matches(new WebRequest(URI.create(url).toURL()))).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.test.web.servlet.htmlunit;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.htmlunit.HttpWebConnection;
|
||||
@@ -79,7 +79,7 @@ class DelegatingWebConnectionTests {
|
||||
|
||||
@BeforeEach
|
||||
void setup() throws Exception {
|
||||
request = new WebRequest(new URL("http://localhost/"));
|
||||
request = new WebRequest(URI.create("http://localhost/").toURL());
|
||||
WebResponseData data = new WebResponseData("".getBytes(UTF_8), 200, "", Collections.emptyList());
|
||||
expectedResponse = new WebResponse(data, request, 100L);
|
||||
webConnection = new DelegatingWebConnection(defaultConnection,
|
||||
|
||||
+32
-28
@@ -17,7 +17,7 @@
|
||||
package org.springframework.test.web.servlet.htmlunit;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -70,7 +70,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@BeforeEach
|
||||
void setup() throws Exception {
|
||||
webRequest = new WebRequest(new URL("https://example.com/test/this/here"));
|
||||
webRequest = new WebRequest(URI.create("https://example.com/test/this/here").toURL());
|
||||
webRequest.setHttpMethod(HttpMethod.GET);
|
||||
requestBuilder = new HtmlUnitRequestBuilder(sessions, webClient, webRequest);
|
||||
}
|
||||
@@ -173,7 +173,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestContextPathUsesNoFirstSegmentWithDefault() throws MalformedURLException {
|
||||
webRequest.setUrl(new URL("https://example.com/"));
|
||||
webRequest.setUrl(URI.create("https://example.com/").toURL());
|
||||
String contextPath = requestBuilder.buildRequest(servletContext).getContextPath();
|
||||
|
||||
assertThat(contextPath).isEmpty();
|
||||
@@ -279,6 +279,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void buildRequestLocaleDa() {
|
||||
webRequest.setAdditionalHeader("Accept-Language", "da");
|
||||
|
||||
@@ -288,6 +289,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void buildRequestLocaleEnGbQ08() {
|
||||
webRequest.setAdditionalHeader("Accept-Language", "en-gb;q=0.8");
|
||||
|
||||
@@ -297,6 +299,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void buildRequestLocaleEnQ07() {
|
||||
webRequest.setAdditionalHeader("Accept-Language", "en");
|
||||
|
||||
@@ -324,6 +327,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void buildRequestLocaleMulti() {
|
||||
webRequest.setAdditionalHeader("Accept-Language", "en-gb;q=0.8, da, en;q=0.7");
|
||||
|
||||
@@ -353,7 +357,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestParameterMapFromSingleQueryParam() throws Exception {
|
||||
webRequest.setUrl(new URL("https://example.com/example/?name=value"));
|
||||
webRequest.setUrl(URI.create("https://example.com/example/?name=value").toURL());
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
@@ -364,7 +368,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
// SPR-14177
|
||||
@Test
|
||||
void buildRequestParameterMapDecodesParameterName() throws Exception {
|
||||
webRequest.setUrl(new URL("https://example.com/example/?row%5B0%5D=value"));
|
||||
webRequest.setUrl(URI.create("https://example.com/example/?row%5B0%5D=value").toURL());
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
@@ -374,7 +378,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestParameterMapDecodesParameterValue() throws Exception {
|
||||
webRequest.setUrl(new URL("https://example.com/example/?name=row%5B0%5D"));
|
||||
webRequest.setUrl(URI.create("https://example.com/example/?name=row%5B0%5D").toURL());
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
@@ -384,7 +388,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestParameterMapFromSingleQueryParamWithoutValueAndWithoutEqualsSign() throws Exception {
|
||||
webRequest.setUrl(new URL("https://example.com/example/?name"));
|
||||
webRequest.setUrl(URI.create("https://example.com/example/?name").toURL());
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
@@ -394,7 +398,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestParameterMapFromSingleQueryParamWithoutValueButWithEqualsSign() throws Exception {
|
||||
webRequest.setUrl(new URL("https://example.com/example/?name="));
|
||||
webRequest.setUrl(URI.create("https://example.com/example/?name=").toURL());
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
@@ -404,7 +408,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestParameterMapFromSingleQueryParamWithValueSetToEncodedSpace() throws Exception {
|
||||
webRequest.setUrl(new URL("https://example.com/example/?name=%20"));
|
||||
webRequest.setUrl(URI.create("https://example.com/example/?name=%20").toURL());
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
@@ -414,7 +418,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestParameterMapFromMultipleQueryParams() throws Exception {
|
||||
webRequest.setUrl(new URL("https://example.com/example/?name=value¶m2=value+2"));
|
||||
webRequest.setUrl(URI.create("https://example.com/example/?name=value¶m2=value+2").toURL());
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
@@ -432,7 +436,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestPathInfoNull() throws Exception {
|
||||
webRequest.setUrl(new URL("https://example.com/example"));
|
||||
webRequest.setUrl(URI.create("https://example.com/example").toURL());
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
@@ -441,7 +445,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestAndAntPathRequestMatcher() throws Exception {
|
||||
webRequest.setUrl(new URL("https://example.com/app/login/authenticate"));
|
||||
webRequest.setUrl(URI.create("https://example.com/app/login/authenticate").toURL());
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
@@ -460,7 +464,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
@Test
|
||||
void buildRequestQueryWithSingleQueryParam() throws Exception {
|
||||
String expectedQuery = "param=value";
|
||||
webRequest.setUrl(new URL("https://example.com/example?" + expectedQuery));
|
||||
webRequest.setUrl(URI.create("https://example.com/example?" + expectedQuery).toURL());
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
@@ -470,7 +474,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
@Test
|
||||
void buildRequestQueryWithSingleQueryParamWithoutValueAndWithoutEqualsSign() throws Exception {
|
||||
String expectedQuery = "param";
|
||||
webRequest.setUrl(new URL("https://example.com/example?" + expectedQuery));
|
||||
webRequest.setUrl(URI.create("https://example.com/example?" + expectedQuery).toURL());
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
@@ -480,7 +484,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
@Test
|
||||
void buildRequestQueryWithSingleQueryParamWithoutValueButWithEqualsSign() throws Exception {
|
||||
String expectedQuery = "param=";
|
||||
webRequest.setUrl(new URL("https://example.com/example?" + expectedQuery));
|
||||
webRequest.setUrl(URI.create("https://example.com/example?" + expectedQuery).toURL());
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
@@ -490,7 +494,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
@Test
|
||||
void buildRequestQueryWithSingleQueryParamWithValueSetToEncodedSpace() throws Exception {
|
||||
String expectedQuery = "param=%20";
|
||||
webRequest.setUrl(new URL("https://example.com/example?" + expectedQuery));
|
||||
webRequest.setUrl(URI.create("https://example.com/example?" + expectedQuery).toURL());
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
@@ -500,7 +504,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
@Test
|
||||
void buildRequestQueryWithMultipleQueryParams() throws Exception {
|
||||
String expectedQuery = "param1=value1¶m2=value2";
|
||||
webRequest.setUrl(new URL("https://example.com/example?" + expectedQuery));
|
||||
webRequest.setUrl(URI.create("https://example.com/example?" + expectedQuery).toURL());
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
@@ -551,7 +555,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestWithSchemeHttpAndDefaultPort() throws Exception {
|
||||
webRequest.setUrl(new URL("http://localhost/test"));
|
||||
webRequest.setUrl(URI.create("http://localhost/test").toURL());
|
||||
var request = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertUrlAndPorts(request, "http://localhost/test", 80, false);
|
||||
@@ -559,7 +563,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestWithSchemeHttpAndExplicitDefaultPort() throws Exception {
|
||||
webRequest.setUrl(new URL("http://localhost:80/test"));
|
||||
webRequest.setUrl(URI.create("http://localhost:80/test").toURL());
|
||||
var request = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertUrlAndPorts(request, "http://localhost/test", 80, false);
|
||||
@@ -567,13 +571,13 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestWithSchemeHttpAndExplicitPort() throws Exception {
|
||||
webRequest.setUrl(new URL("http://localhost:8081/test"));
|
||||
webRequest.setUrl(URI.create("http://localhost:8081/test").toURL());
|
||||
var request = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertUrlAndPorts(request, "http://localhost:8081/test", 8081, false);
|
||||
|
||||
// Unlikely scheme/port combination:
|
||||
webRequest.setUrl(new URL("http://localhost:443/test"));
|
||||
webRequest.setUrl(URI.create("http://localhost:443/test").toURL());
|
||||
request = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertUrlAndPorts(request, "http://localhost:443/test", 443, false);
|
||||
@@ -581,7 +585,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestWithSchemeHttpsAndDefaultPort() throws Exception {
|
||||
webRequest.setUrl(new URL("https://localhost/test"));
|
||||
webRequest.setUrl(URI.create("https://localhost/test").toURL());
|
||||
var request = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertUrlAndPorts(request, "https://localhost/test", 443, true);
|
||||
@@ -589,7 +593,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestWithSchemeHttpsAndExplicitDefaultPort() throws Exception {
|
||||
webRequest.setUrl(new URL("https://localhost:443/test"));
|
||||
webRequest.setUrl(URI.create("https://localhost:443/test").toURL());
|
||||
var request = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertUrlAndPorts(request, "https://localhost/test", 443, true);
|
||||
@@ -597,13 +601,13 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestWithSchemeHttpsAndExplicitPort() throws Exception {
|
||||
webRequest.setUrl(new URL("https://localhost:8443/test"));
|
||||
webRequest.setUrl(URI.create("https://localhost:8443/test").toURL());
|
||||
var request = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertUrlAndPorts(request, "https://localhost:8443/test", 8443, true);
|
||||
|
||||
// Unlikely scheme/port combination:
|
||||
webRequest.setUrl(new URL("https://localhost:80/test"));
|
||||
webRequest.setUrl(URI.create("https://localhost:80/test").toURL());
|
||||
request = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertUrlAndPorts(request, "https://localhost:80/test", 80, true);
|
||||
@@ -611,7 +615,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestSchemeHttp() throws Exception {
|
||||
webRequest.setUrl(new URL("http://localhost:80/test/this/here"));
|
||||
webRequest.setUrl(URI.create("http://localhost:80/test/this/here").toURL());
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getScheme()).isEqualTo("http");
|
||||
@@ -619,7 +623,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
void buildRequestSchemeHttps() throws Exception {
|
||||
webRequest.setUrl(new URL("https://example.com/"));
|
||||
webRequest.setUrl(URI.create("https://example.com/").toURL());
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getScheme()).isEqualTo("https");
|
||||
@@ -648,7 +652,7 @@ class HtmlUnitRequestBuilderTests {
|
||||
|
||||
@Test // gh-27837
|
||||
void buildRequestServletPathWithEncodedUrl() throws Exception {
|
||||
webRequest.setUrl(new URL("http://localhost/test/Fr%C3%BChling%20Sommer%20Herbst%20Winter"));
|
||||
webRequest.setUrl(URI.create("http://localhost/test/Fr%C3%BChling%20Sommer%20Herbst%20Winter").toURL());
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@
|
||||
package org.springframework.test.web.servlet.htmlunit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.htmlunit.WebClient;
|
||||
@@ -134,7 +134,7 @@ class MockMvcConnectionBuilderSupportTests {
|
||||
}
|
||||
|
||||
private WebResponse getResponse(WebConnection connection, String url) throws IOException {
|
||||
return connection.getResponse(new WebRequest(new URL(url)));
|
||||
return connection.getResponse(new WebRequest(URI.create(url).toURL()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+4
-4
@@ -17,7 +17,7 @@
|
||||
package org.springframework.test.web.servlet.htmlunit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
@@ -114,17 +114,17 @@ class MockMvcWebClientBuilderTests {
|
||||
}
|
||||
|
||||
private WebResponse getResponse(WebClient client, String url) throws IOException {
|
||||
return createResponse(client, new WebRequest(new URL(url)));
|
||||
return createResponse(client, new WebRequest(URI.create(url).toURL()));
|
||||
}
|
||||
|
||||
private WebResponse postResponse(WebClient client, String url, String body) throws IOException {
|
||||
WebRequest request = new WebRequest(new URL(url), HttpMethod.POST);
|
||||
WebRequest request = new WebRequest(URI.create(url).toURL(), HttpMethod.POST);
|
||||
request.setRequestBody(body);
|
||||
return createResponse(client, request);
|
||||
}
|
||||
|
||||
private WebResponse deleteResponse(WebClient client, String url) throws IOException {
|
||||
return createResponse(client, new WebRequest(new URL(url), HttpMethod.DELETE));
|
||||
return createResponse(client, new WebRequest(URI.create(url).toURL(), HttpMethod.DELETE));
|
||||
}
|
||||
|
||||
private WebResponse createResponse(WebClient client, WebRequest request) throws IOException {
|
||||
|
||||
+3
-3
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.test.web.servlet.htmlunit;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
@@ -49,7 +49,7 @@ class MockWebResponseBuilderTests {
|
||||
|
||||
@BeforeEach
|
||||
void setup() throws Exception {
|
||||
this.webRequest = new WebRequest(new URL("http://company.example:80/test/this/here"));
|
||||
this.webRequest = new WebRequest(URI.create("http://company.example:80/test/this/here").toURL());
|
||||
this.responseBuilder = new MockWebResponseBuilder(System.currentTimeMillis(), this.webRequest, this.response);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class MockWebResponseBuilderTests {
|
||||
void constructorWithNullResponse() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new MockWebResponseBuilder(0L,
|
||||
new WebRequest(new URL("http://company.example:80/test/this/here")), null));
|
||||
new WebRequest(URI.create("http://company.example:80/test/this/here").toURL()), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
@@ -566,6 +566,7 @@ class MockHttpServletRequestBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void locale() {
|
||||
Locale locale = new Locale("nl", "nl");
|
||||
this.builder.locale(locale);
|
||||
|
||||
+4
-4
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.test.web.servlet.samples.client.standalone.resultmatches;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -68,7 +68,7 @@ class FlashAttributeAssertionTests {
|
||||
performRequest()
|
||||
.andExpect(flash().attribute("one", "1"))
|
||||
.andExpect(flash().attribute("two", 2.222))
|
||||
.andExpect(flash().attribute("three", new URL("https://example.com")));
|
||||
.andExpect(flash().attribute("three", URI.create("https://example.com").toURL()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,7 +79,7 @@ class FlashAttributeAssertionTests {
|
||||
.andExpect(flash().attribute("three", notNullValue()))
|
||||
.andExpect(flash().attribute("one", equalTo("1")))
|
||||
.andExpect(flash().attribute("two", equalTo(2.222)))
|
||||
.andExpect(flash().attribute("three", equalTo(new URL("https://example.com"))));
|
||||
.andExpect(flash().attribute("three", equalTo(URI.create("https://example.com").toURL())));
|
||||
}
|
||||
|
||||
private ResultActions performRequest() {
|
||||
@@ -95,7 +95,7 @@ class FlashAttributeAssertionTests {
|
||||
String save(RedirectAttributes redirectAttrs) throws Exception {
|
||||
redirectAttrs.addFlashAttribute("one", "1");
|
||||
redirectAttrs.addFlashAttribute("two", 2.222);
|
||||
redirectAttrs.addFlashAttribute("three", new URL("https://example.com"));
|
||||
redirectAttrs.addFlashAttribute("three", URI.create("https://example.com").toURL());
|
||||
return "redirect:/person/1";
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.test.web.servlet.samples.standalone.resultmatchers;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -67,7 +67,7 @@ class FlashAttributeAssertionTests {
|
||||
this.mockMvc.perform(post("/persons"))
|
||||
.andExpect(flash().attribute("one", "1"))
|
||||
.andExpect(flash().attribute("two", 2.222))
|
||||
.andExpect(flash().attribute("three", new URL("https://example.com")));
|
||||
.andExpect(flash().attribute("three", URI.create("https://example.com").toURL()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,7 +78,7 @@ class FlashAttributeAssertionTests {
|
||||
.andExpect(flash().attribute("three", notNullValue()))
|
||||
.andExpect(flash().attribute("one", equalTo("1")))
|
||||
.andExpect(flash().attribute("two", equalTo(2.222)))
|
||||
.andExpect(flash().attribute("three", equalTo(new URL("https://example.com"))));
|
||||
.andExpect(flash().attribute("three", equalTo(URI.create("https://example.com").toURL())));
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ class FlashAttributeAssertionTests {
|
||||
String save(RedirectAttributes redirectAttrs) throws Exception {
|
||||
redirectAttrs.addFlashAttribute("one", "1");
|
||||
redirectAttrs.addFlashAttribute("two", 2.222);
|
||||
redirectAttrs.addFlashAttribute("three", new URL("https://example.com"));
|
||||
redirectAttrs.addFlashAttribute("three", URI.create("https://example.com").toURL());
|
||||
return "redirect:/person/1";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +110,7 @@ public class HttpEntity<T> {
|
||||
* @param headers the entity headers
|
||||
* @deprecated in favor of {@link #HttpEntity(HttpHeaders)}
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
@Deprecated(since = "7.0", forRemoval = true)
|
||||
public HttpEntity(MultiValueMap<String, String> headers) {
|
||||
this(null, headers);
|
||||
|
||||
@@ -154,6 +154,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
* @param url the URL
|
||||
* @deprecated in favor of {@link #RequestEntity(HttpHeaders, HttpMethod, URI)}
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
@Deprecated(since = "7.0", forRemoval = true)
|
||||
public RequestEntity(MultiValueMap<String, String> headers, HttpMethod method, URI url) {
|
||||
this(null, headers, method, url, null);
|
||||
@@ -167,6 +168,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
* @param url the URL
|
||||
* @deprecated in favor of {@link #RequestEntity(Object, HttpHeaders, HttpMethod, URI)}
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
@Deprecated(since = "7.0", forRemoval = true)
|
||||
public RequestEntity(
|
||||
@Nullable T body, @Nullable MultiValueMap<String, String> headers,
|
||||
|
||||
@@ -141,6 +141,7 @@ public class ResponseEntity<T> extends HttpEntity<T> {
|
||||
* @param status the status code
|
||||
* @deprecated in favor of {@link #ResponseEntity(HttpHeaders, HttpStatusCode)}
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
@Deprecated(since = "7.0", forRemoval = true)
|
||||
public ResponseEntity(MultiValueMap<String, String> headers, HttpStatusCode status) {
|
||||
this(null, headers, status);
|
||||
@@ -154,6 +155,7 @@ public class ResponseEntity<T> extends HttpEntity<T> {
|
||||
* @since 5.3.2
|
||||
* @deprecated in favor of {@link #ResponseEntity(Object, HttpHeaders, int)}
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
@Deprecated(since = "7.0", forRemoval = true)
|
||||
public ResponseEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers, int rawStatus) {
|
||||
this(body, headers, HttpStatusCode.valueOf(rawStatus));
|
||||
|
||||
@@ -332,6 +332,7 @@ class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void dateOtherLocale() {
|
||||
Locale defaultLocale = Locale.getDefault();
|
||||
try {
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ class SimpleClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTest
|
||||
|
||||
@Test
|
||||
void deleteWithoutBodyDoesNotRaiseException() throws Exception {
|
||||
HttpURLConnection connection = new TestHttpURLConnection(new URL("https://example.com"));
|
||||
HttpURLConnection connection = new TestHttpURLConnection(URI.create("https://example.com").toURL());
|
||||
((SimpleClientHttpRequestFactory) this.factory).prepareConnection(connection, "DELETE");
|
||||
SimpleClientHttpRequest request = new SimpleClientHttpRequest(connection, 4096);
|
||||
request.execute();
|
||||
|
||||
+6
@@ -141,6 +141,7 @@ class CookieLocaleResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void setAndResolveLocale() {
|
||||
resolver.setLocale(request, response, new Locale("nl", ""));
|
||||
|
||||
@@ -161,6 +162,7 @@ class CookieLocaleResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void setAndResolveLocaleContext() {
|
||||
resolver.setLocaleContext(request, response, new SimpleLocaleContext(new Locale("nl", "")));
|
||||
|
||||
@@ -176,6 +178,7 @@ class CookieLocaleResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void setAndResolveLocaleContextWithTimeZone() {
|
||||
resolver.setLocaleContext(request, response,
|
||||
new SimpleTimeZoneAwareLocaleContext(new Locale("nl", ""), TimeZone.getTimeZone("GMT+1")));
|
||||
@@ -209,6 +212,7 @@ class CookieLocaleResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void setAndResolveLocaleWithCountry() {
|
||||
resolver.setLocale(request, response, new Locale("de", "AT"));
|
||||
|
||||
@@ -231,6 +235,7 @@ class CookieLocaleResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void setAndResolveLocaleWithCountryAsLegacyJava() {
|
||||
resolver.setLanguageTagCompliant(false);
|
||||
resolver.setLocale(request, response, new Locale("de", "AT"));
|
||||
@@ -254,6 +259,7 @@ class CookieLocaleResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void customCookie() {
|
||||
resolver = new CookieLocaleResolver("LanguageKoek");
|
||||
resolver.setCookieDomain(".springframework.org");
|
||||
|
||||
+2
@@ -60,7 +60,9 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
class SelectTagTests extends AbstractFormTagTests {
|
||||
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
private static final Locale LOCALE_AT = new Locale("de", "AT");
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
private static final Locale LOCALE_NL = new Locale("nl", "NL");
|
||||
|
||||
private SelectTag tag;
|
||||
|
||||
+1
@@ -131,6 +131,7 @@ class GroovyMarkupViewTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
|
||||
void renderI18nTemplate() throws Exception {
|
||||
Map<String, Object> model = Map.of("name", "Spring");
|
||||
MockHttpServletResponse response = renderViewWithModel("i18n.tpl", model, Locale.FRANCE);
|
||||
|
||||
Reference in New Issue
Block a user