From c4405104a818ed44feb297b967dbd2cd7d9bdda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Tue, 9 Jan 2024 09:55:49 +0100 Subject: [PATCH] Polish --- .../springframework/http/HttpEntityTests.java | 6 +- .../http/HttpHeadersTests.java | 22 +++--- .../springframework/http/HttpMethodTests.java | 4 +- .../springframework/http/HttpRangeTests.java | 34 ++++----- .../http/MediaTypeFactoryTests.java | 8 +-- .../springframework/http/MediaTypeTests.java | 56 +++++++-------- .../http/ResponseCookieTests.java | 10 +-- .../client/AbstractMockWebServerTests.java | 8 +-- ...ufferingClientHttpRequestFactoryTests.java | 5 +- ...rceptingClientHttpRequestFactoryTests.java | 4 +- ...erceptingStreamingHttpComponentsTests.java | 6 +- .../JdkClientHttpRequestFactoryTests.java | 8 +-- .../JettyClientHttpRequestFactoryTests.java | 6 +- .../client/MultipartBodyBuilderTests.java | 6 +- .../OkHttp3ClientHttpRequestFactoryTests.java | 6 +- ...torNettyClientHttpRequestFactoryTests.java | 6 +- .../SimpleClientHttpRequestFactoryTests.java | 12 ++-- .../client/SimpleClientHttpResponseTests.java | 4 +- .../reactive/ClientHttpConnectorTests.java | 4 +- .../reactive/ReactorResourceFactoryTests.java | 4 +- .../InterceptingHttpAccessorTests.java | 15 ++-- .../codec/CancelWithoutDemandCodecTests.java | 18 ++--- .../codec/EncoderHttpMessageWriterTests.java | 2 +- .../codec/FormHttpMessageReaderTests.java | 20 +++--- .../codec/FormHttpMessageWriterTests.java | 8 +-- .../codec/ResourceHttpMessageReaderTests.java | 2 +- .../codec/ResourceHttpMessageWriterTests.java | 14 ++-- ...ServerSentEventHttpMessageReaderTests.java | 2 +- .../codec/cbor/Jackson2CborDecoderTests.java | 8 +-- .../codec/cbor/Jackson2CborEncoderTests.java | 10 +-- .../codec/json/Jackson2JsonDecoderTests.java | 24 +++---- .../codec/json/Jackson2JsonEncoderTests.java | 22 +++--- .../codec/json/Jackson2SmileDecoderTests.java | 8 +-- .../codec/json/Jackson2SmileEncoderTests.java | 12 ++-- .../codec/json/Jackson2TokenizerTests.java | 20 +++--- .../codec/json/JacksonCsvEncoderTests.java | 5 +- .../DefaultPartHttpMessageReaderTests.java | 3 +- .../MultipartHttpMessageWriterTests.java | 6 +- .../PartEventHttpMessageReaderTests.java | 30 ++++---- .../PartEventHttpMessageWriterTests.java | 4 +- .../multipart/PartHttpMessageWriterTests.java | 4 +- .../codec/protobuf/ProtobufDecoderTests.java | 8 +-- .../codec/protobuf/ProtobufEncoderTests.java | 8 +-- .../support/ClientCodecConfigurerTests.java | 18 ++--- .../support/ServerCodecConfigurerTests.java | 18 ++--- .../http/codec/xml/Jaxb2HelperTests.java | 4 +- .../http/codec/xml/Jaxb2XmlDecoderTests.java | 24 +++---- .../http/codec/xml/Jaxb2XmlEncoderTests.java | 14 ++-- .../http/codec/xml/XmlEventDecoderTests.java | 16 ++--- .../ByteArrayHttpMessageConverterTests.java | 18 ++--- .../FormHttpMessageConverterTests.java | 28 ++++---- .../converter/HttpMessageConverterTests.java | 18 +++-- ...jectToStringHttpMessageConverterTests.java | 30 ++++---- .../ResourceHttpMessageConverterTests.java | 12 ++-- ...sourceRegionHttpMessageConverterTests.java | 24 +++---- .../StringHttpMessageConverterTests.java | 4 +- .../AtomFeedHttpMessageConverterTests.java | 18 ++--- .../RssChannelHttpMessageConverterTests.java | 14 ++-- .../converter/json/GsonFactoryBeanTests.java | 24 +++---- .../json/GsonHttpMessageConverterTests.java | 26 +++---- .../Jackson2ObjectMapperBuilderTests.java | 22 +++--- .../Jackson2ObjectMapperFactoryBeanTests.java | 42 +++++------ .../json/JsonbHttpMessageConverterTests.java | 24 +++---- ...pingJackson2HttpMessageConverterTests.java | 49 +++++++------ .../json/SpringHandlerInstantiatorTests.java | 18 ++--- .../ProtobufHttpMessageConverterTests.java | 4 +- ...ufJsonFormatHttpMessageConverterTests.java | 18 ++--- ...ackson2SmileHttpMessageConverterTests.java | 12 ++-- ...b2CollectionHttpMessageConverterTests.java | 12 ++-- ...2RootElementHttpMessageConverterTests.java | 30 ++++---- ...gJackson2XmlHttpMessageConverterTests.java | 25 ++++--- .../MarshallingHttpMessageConverterTests.java | 20 +++--- .../xml/SourceHttpMessageConverterTests.java | 38 +++++----- .../server/DefaultPathContainerTests.java | 2 +- .../server/ServletServerHttpRequestTests.java | 15 ++-- .../ServletServerHttpResponseTests.java | 4 +- .../reactive/AsyncIntegrationTests.java | 3 +- .../reactive/ChannelSendOperatorTests.java | 25 +++---- .../ContextPathCompositeHandlerTests.java | 12 ++-- .../reactive/CookieIntegrationTests.java | 7 +- .../reactive/EchoHandlerIntegrationTests.java | 5 +- .../ErrorHandlerIntegrationTests.java | 5 +- .../server/reactive/HeadersAdaptersTests.java | 7 +- .../reactive/ListenerReadPublisherTests.java | 6 +- .../reactive/ListenerWriteProcessorTests.java | 4 +- .../RandomHandlerIntegrationTests.java | 3 +- .../reactive/ReactorUriHelperTests.java | 6 +- .../ServerHttpRequestIntegrationTests.java | 3 +- .../reactive/ServerHttpRequestTests.java | 24 +++---- .../ServerHttpsRequestIntegrationTests.java | 4 +- .../WriteOnlyHandlerIntegrationTests.java | 3 +- .../reactive/ZeroCopyIntegrationTests.java | 3 +- .../web/ErrorResponseExceptionTests.java | 2 +- ...HeaderContentNegotiationStrategyTests.java | 8 +-- ...appingContentNegotiationStrategyTests.java | 12 ++-- ...ngMediaTypeFileExtensionResolverTests.java | 13 ++-- ...ensionContentNegotiationStrategyTests.java | 9 ++- .../web/bind/EscapedErrorsTests.java | 6 +- .../MethodArgumentNotValidExceptionTests.java | 2 +- .../bind/ServletRequestDataBinderTests.java | 30 ++++---- .../web/bind/ServletRequestUtilsTests.java | 14 ++-- ...rollerMappingReflectiveProcessorTests.java | 6 +- .../DefaultDataBinderFactoryTests.java | 2 +- .../support/WebExchangeDataBinderTests.java | 26 +++---- .../support/WebRequestDataBinderTests.java | 42 +++++------ .../DefaultResponseErrorHandlerTests.java | 16 ++--- .../ExtractingResponseErrorHandlerTests.java | 18 ++--- .../HttpMessageConverterExtractorTests.java | 11 ++- .../client/HttpStatusCodeExceptionTests.java | 6 +- .../client/RestClientIntegrationTests.java | 3 +- .../client/RestClientObservationTests.java | 3 +- .../client/RestTemplateIntegrationTests.java | 32 ++++----- .../client/RestTemplateObservationTests.java | 3 +- .../web/client/RestTemplateTests.java | 11 ++- .../ContextLoaderInitializerTests.java | 8 +-- .../RequestAndSessionScopedBeanTests.java | 6 +- .../request/RequestContextListenerTests.java | 18 ++--- .../context/request/RequestScopeTests.java | 22 +++--- .../request/RequestScopedProxyTests.java | 20 +++--- .../ServletRequestAttributesTests.java | 34 ++++----- .../request/ServletWebRequestTests.java | 21 +++--- .../context/request/SessionScopeTests.java | 20 +++--- .../WebApplicationContextScopeTests.java | 10 +-- .../request/async/DeferredResultTests.java | 18 ++--- .../StandardServletAsyncWebRequestTests.java | 32 ++++----- .../async/WebAsyncManagerErrorTests.java | 33 +++++---- .../request/async/WebAsyncManagerTests.java | 12 ++-- .../async/WebAsyncManagerTimeoutTests.java | 28 ++++---- ...ationConfigWebApplicationContextTests.java | 8 +-- .../support/ServletContextResourceTests.java | 4 +- .../web/context/support/Spr8510Tests.java | 18 ++--- .../SpringBeanAutowiringSupportTests.java | 6 +- .../StandardServletEnvironmentTests.java | 4 +- .../web/cors/CorsUtilsTests.java | 12 ++-- .../web/cors/DefaultCorsProcessorTests.java | 60 ++++++++-------- .../web/cors/reactive/CorsUtilsTests.java | 12 ++-- .../web/cors/reactive/CorsWebFilterTests.java | 18 +++-- .../reactive/DefaultCorsProcessorTests.java | 60 ++++++++-------- .../filter/CharacterEncodingFilterTests.java | 16 ++--- .../web/filter/CompositeFilterTests.java | 12 ++-- .../ContentCachingResponseWrapperTests.java | 2 +- .../web/filter/CorsFilterTests.java | 2 +- .../filter/DelegatingFilterProxyTests.java | 36 +++++----- .../web/filter/FormContentFilterTests.java | 55 +++++++------- .../filter/ForwardedHeaderFilterTests.java | 2 +- .../filter/HiddenHttpMethodFilterTests.java | 10 +-- .../web/filter/OncePerRequestFilterTests.java | 9 ++- .../filter/RelativeRedirectFilterTests.java | 2 +- .../web/filter/RequestContextFilterTests.java | 12 ++-- .../ServerHttpObservationFilterTests.java | 20 +++--- .../filter/ShallowEtagHeaderFilterTests.java | 22 +++--- .../reactive/HiddenHttpMethodFilterTests.java | 16 ++--- .../jsf/DelegatingNavigationHandlerTests.java | 8 +-- .../web/jsf/DelegatingPhaseListenerTests.java | 8 +-- .../web/method/ControllerAdviceBeanTests.java | 40 +++++------ .../web/method/HandlerMethodTests.java | 2 +- .../web/method/HandlerTypePredicateTests.java | 6 +- ...ookieValueMethodArgumentResolverTests.java | 14 ++-- .../ErrorsMethodArgumentResolverTests.java | 14 ++-- .../ExceptionHandlerMethodResolverTests.java | 25 ++++--- ...ssionValueMethodArgumentResolverTests.java | 13 ++-- .../InitBinderDataBinderFactoryTests.java | 18 ++--- .../annotation/MapMethodProcessorTests.java | 14 ++-- .../ModelAttributeMethodProcessorTests.java | 32 ++++----- .../annotation/ModelFactoryOrderingTests.java | 6 +- .../method/annotation/ModelFactoryTests.java | 28 ++++---- .../annotation/ModelMethodProcessorTests.java | 14 ++-- ...tHeaderMapMethodArgumentResolverTests.java | 14 ++-- ...uestHeaderMethodArgumentResolverTests.java | 9 ++- ...stParamMapMethodArgumentResolverTests.java | 10 +-- ...questParamMethodArgumentResolverTests.java | 60 ++++++++-------- .../SessionAttributesHandlerTests.java | 12 ++-- ...rMethodArgumentResolverCompositeTests.java | 14 ++-- ...ethodReturnValueHandlerCompositeTests.java | 4 +- ...HandlerMethodValidationExceptionTests.java | 2 +- .../support/InvocableHandlerMethodTests.java | 22 +++--- .../support/ModelAndViewContainerTests.java | 12 ++-- .../ByteArrayMultipartFileEditorTests.java | 16 ++--- ...faultMultipartHttpServletRequestTests.java | 2 +- ...uestPartServletServerHttpRequestTests.java | 26 +++---- ...StandardServletMultipartResolverTests.java | 8 +-- ...erverWebExchangeCheckNotModifiedTests.java | 4 +- .../DefaultServerWebExchangeTests.java | 8 +-- .../adapter/WebHttpHandlerBuilderTests.java | 2 +- .../ExceptionHandlingWebHandlerTests.java | 2 +- .../handler/FilteringWebHandlerTests.java | 14 ++-- .../ResponseStatusExceptionHandlerTests.java | 2 +- ...cceptHeaderLocaleContextResolverTests.java | 30 ++++---- .../i18n/FixedLocaleContextResolverTests.java | 10 +-- .../CookieWebSessionIdResolverTests.java | 8 +-- .../DefaultWebSessionManagerTests.java | 2 +- .../session/InMemoryWebSessionStoreTests.java | 14 ++-- .../session/WebSessionIntegrationTests.java | 4 +- .../invoker/HttpServiceMethodTests.java | 6 +- .../ContentCachingRequestWrapperTests.java | 4 +- .../util/DefaultUriBuilderFactoryTests.java | 32 ++++----- .../HtmlCharacterEntityReferencesTests.java | 11 +-- .../web/util/HtmlUtilsTests.java | 4 +- .../web/util/JavaScriptUtilsTests.java | 12 ++-- .../web/util/NestedServletExceptionTests.java | 8 +-- .../ServletContextPropertyUtilsTests.java | 8 +-- .../util/ServletRequestPathUtilsTests.java | 2 +- .../web/util/TagUtilsTests.java | 26 +++---- .../web/util/UriComponentsBuilderTests.java | 2 +- .../web/util/UriUtilsTests.java | 30 ++++---- .../web/util/WebUtilsTests.java | 4 +- .../util/pattern/PathPatternParserTests.java | 44 ++++++------ .../pattern/PathPatternRouteMatcherTests.java | 8 +-- .../web/util/pattern/PathPatternTests.java | 72 +++++++++---------- 209 files changed, 1487 insertions(+), 1551 deletions(-) diff --git a/spring-web/src/test/java/org/springframework/http/HttpEntityTests.java b/spring-web/src/test/java/org/springframework/http/HttpEntityTests.java index 62ae61e55d80..7e0736b8f0db 100644 --- a/spring-web/src/test/java/org/springframework/http/HttpEntityTests.java +++ b/spring-web/src/test/java/org/springframework/http/HttpEntityTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -28,7 +28,7 @@ /** * @author Arjen Poutsma */ -public class HttpEntityTests { +class HttpEntityTests { @Test void noHeaders() { @@ -104,7 +104,7 @@ void responseEntity() { } @Test - void requestEntity() throws Exception { + void requestEntity() { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); String body = "foo"; diff --git a/spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java b/spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java index f1c1eae8cbfa..18696a7a1609 100644 --- a/spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java +++ b/spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java @@ -18,7 +18,6 @@ import java.net.InetSocketAddress; import java.net.URI; -import java.net.URISyntaxException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.time.ZoneId; @@ -53,7 +52,7 @@ * @author Juergen Hoeller * @author Sam Brannen */ -public class HttpHeadersTests { +class HttpHeadersTests { private final HttpHeaders headers = new HttpHeaders(); @@ -152,7 +151,7 @@ void contentType() { } @Test - void location() throws URISyntaxException { + void location() { URI location = URI.create("https://www.example.com/hotels"); headers.setLocation(location); assertThat(headers.getLocation()).as("Invalid Location header").isEqualTo(location); @@ -201,7 +200,7 @@ void illegalETag() { void ifMatch() { String ifMatch = "\"v2.6\""; headers.setIfMatch(ifMatch); - assertThat(headers.getIfMatch()).element(0).as("Invalid If-Match header").isEqualTo(ifMatch); + assertThat(headers.getIfMatch()).containsExactly(ifMatch); assertThat(headers.getFirst("If-Match")).as("Invalid If-Match header").isEqualTo("\"v2.6\""); } @@ -215,8 +214,7 @@ void ifMatchIllegalHeader() { void ifMatchMultipleHeaders() { headers.add(HttpHeaders.IF_MATCH, "\"v2,0\""); headers.add(HttpHeaders.IF_MATCH, "W/\"v2,1\", \"v2,2\""); - assertThat(headers.get(HttpHeaders.IF_MATCH)).element(0).as("Invalid If-Match header").isEqualTo("\"v2,0\""); - assertThat(headers.get(HttpHeaders.IF_MATCH)).element(1).as("Invalid If-Match header").isEqualTo("W/\"v2,1\", \"v2,2\""); + assertThat(headers.get(HttpHeaders.IF_MATCH)).containsExactly("\"v2,0\"", "W/\"v2,1\", \"v2,2\""); assertThat(headers.getIfMatch()).contains("\"v2,0\"", "W/\"v2,1\"", "\"v2,2\""); } @@ -224,7 +222,7 @@ void ifMatchMultipleHeaders() { void ifNoneMatch() { String ifNoneMatch = "\"v2.6\""; headers.setIfNoneMatch(ifNoneMatch); - assertThat(headers.getIfNoneMatch()).element(0).as("Invalid If-None-Match header").isEqualTo(ifNoneMatch); + assertThat(headers.getIfNoneMatch()).containsExactly(ifNoneMatch); assertThat(headers.getFirst("If-None-Match")).as("Invalid If-None-Match header").isEqualTo("\"v2.6\""); } @@ -232,7 +230,7 @@ void ifNoneMatch() { void ifNoneMatchWildCard() { String ifNoneMatch = "*"; headers.setIfNoneMatch(ifNoneMatch); - assertThat(headers.getIfNoneMatch()).element(0).as("Invalid If-None-Match header").isEqualTo(ifNoneMatch); + assertThat(headers.getIfNoneMatch()).containsExactly(ifNoneMatch); assertThat(headers.getFirst("If-None-Match")).as("Invalid If-None-Match header").isEqualTo("*"); } @@ -492,7 +490,7 @@ void acceptLanguage() { } @Test // SPR-15603 - void acceptLanguageWithEmptyValue() throws Exception { + void acceptLanguageWithEmptyValue() { this.headers.set(HttpHeaders.ACCEPT_LANGUAGE, ""); assertThat(this.headers.getAcceptLanguageAsLocales()).isEqualTo(Collections.emptyList()); } @@ -657,7 +655,7 @@ void keySetRemovalChecks() { assertThat(headers.containsKey("Alpha")).as("Alpha should have been removed").isFalse(); assertThat(headers.containsKey("Bravo")).as("Bravo should be present").isTrue(); assertThat(headers.keySet()).containsOnly("Bravo"); - assertThat(headers.entrySet()).containsOnly(entry("Bravo", Arrays.asList("banana"))); + assertThat(headers.entrySet()).containsOnly(entry("Bravo", List.of("banana"))); } @Test @@ -671,7 +669,7 @@ void removalFromKeySetRemovesEntryFromUnderlyingMap() { headers.keySet().removeIf(key -> key.equals(headerName)); assertThat(headers).isEmpty(); headers.add(headerName, headerValue); - assertThat(headers.get(headerName)).element(0).isEqualTo(headerValue); + assertThat(headers.get(headerName)).containsExactly(headerValue); } @Test @@ -685,7 +683,7 @@ void removalFromEntrySetRemovesEntryFromUnderlyingMap() { headers.entrySet().removeIf(entry -> entry.getKey().equals(headerName)); assertThat(headers).isEmpty(); headers.add(headerName, headerValue); - assertThat(headers.get(headerName)).element(0).isEqualTo(headerValue); + assertThat(headers.get(headerName)).containsExactly(headerValue); } @Test diff --git a/spring-web/src/test/java/org/springframework/http/HttpMethodTests.java b/spring-web/src/test/java/org/springframework/http/HttpMethodTests.java index ee92695ac912..055149ea53e1 100644 --- a/spring-web/src/test/java/org/springframework/http/HttpMethodTests.java +++ b/spring-web/src/test/java/org/springframework/http/HttpMethodTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 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. @@ -26,7 +26,7 @@ class HttpMethodTests { @Test - public void comparison() { + void comparison() { HttpMethod method1 = HttpMethod.valueOf("FOO"); HttpMethod method2 = HttpMethod.valueOf("FOO"); HttpMethod method3 = HttpMethod.valueOf("BAR"); diff --git a/spring-web/src/test/java/org/springframework/http/HttpRangeTests.java b/spring-web/src/test/java/org/springframework/http/HttpRangeTests.java index fea668d423d1..7ca6e91f231d 100644 --- a/spring-web/src/test/java/org/springframework/http/HttpRangeTests.java +++ b/spring-web/src/test/java/org/springframework/http/HttpRangeTests.java @@ -38,63 +38,63 @@ * @author Rossen Stoyanchev * @author Brian Clozel */ -public class HttpRangeTests { +class HttpRangeTests { @Test - public void invalidFirstPosition() { + void invalidFirstPosition() { assertThatIllegalArgumentException().isThrownBy(() -> HttpRange.createByteRange(-1)); } @Test - public void invalidLastLessThanFirst() { + void invalidLastLessThanFirst() { assertThatIllegalArgumentException().isThrownBy(() -> HttpRange.createByteRange(10, 9)); } @Test - public void invalidSuffixLength() { + void invalidSuffixLength() { assertThatIllegalArgumentException().isThrownBy(() -> HttpRange.createSuffixRange(-1)); } @Test - public void byteRange() { + void byteRange() { HttpRange range = HttpRange.createByteRange(0, 499); assertThat(range.getRangeStart(1000)).isEqualTo(0); assertThat(range.getRangeEnd(1000)).isEqualTo(499); } @Test - public void byteRangeWithoutLastPosition() { + void byteRangeWithoutLastPosition() { HttpRange range = HttpRange.createByteRange(9500); assertThat(range.getRangeStart(10000)).isEqualTo(9500); assertThat(range.getRangeEnd(10000)).isEqualTo(9999); } @Test - public void byteRangeOfZeroLength() { + void byteRangeOfZeroLength() { HttpRange range = HttpRange.createByteRange(9500, 9500); assertThat(range.getRangeStart(10000)).isEqualTo(9500); assertThat(range.getRangeEnd(10000)).isEqualTo(9500); } @Test - public void suffixRange() { + void suffixRange() { HttpRange range = HttpRange.createSuffixRange(500); assertThat(range.getRangeStart(1000)).isEqualTo(500); assertThat(range.getRangeEnd(1000)).isEqualTo(999); } @Test - public void suffixRangeShorterThanRepresentation() { + void suffixRangeShorterThanRepresentation() { HttpRange range = HttpRange.createSuffixRange(500); assertThat(range.getRangeStart(350)).isEqualTo(0); assertThat(range.getRangeEnd(350)).isEqualTo(349); } @Test - public void parseRanges() { + void parseRanges() { List ranges = HttpRange.parseRanges("bytes=0-0,500-,-1"); assertThat(ranges).hasSize(3); assertThat(ranges.get(0).getRangeStart(1000)).isEqualTo(0); @@ -106,7 +106,7 @@ public void parseRanges() { } @Test - public void parseRangesValidations() { + void parseRangesValidations() { // 1. At limit.. StringBuilder atLimit = new StringBuilder("bytes=0-0"); @@ -126,7 +126,7 @@ public void parseRangesValidations() { } @Test - public void rangeToString() { + void rangeToString() { List ranges = new ArrayList<>(); ranges.add(HttpRange.createByteRange(0, 499)); ranges.add(HttpRange.createByteRange(9500)); @@ -135,7 +135,7 @@ public void rangeToString() { } @Test - public void toResourceRegion() { + void toResourceRegion() { byte[] bytes = "Spring Framework".getBytes(StandardCharsets.UTF_8); ByteArrayResource resource = new ByteArrayResource(bytes); HttpRange range = HttpRange.createByteRange(0, 5); @@ -146,7 +146,7 @@ public void toResourceRegion() { } @Test - public void toResourceRegionInputStreamResource() { + void toResourceRegionInputStreamResource() { InputStreamResource resource = mock(); HttpRange range = HttpRange.createByteRange(0, 9); assertThatIllegalArgumentException().isThrownBy(() -> @@ -154,7 +154,7 @@ public void toResourceRegionInputStreamResource() { } @Test - public void toResourceRegionIllegalLength() { + void toResourceRegionIllegalLength() { ByteArrayResource resource = mock(); given(resource.contentLength()).willReturn(-1L); HttpRange range = HttpRange.createByteRange(0, 9); @@ -162,7 +162,7 @@ public void toResourceRegionIllegalLength() { } @Test - public void toResourceRegionExceptionLength() throws IOException { + void toResourceRegionExceptionLength() throws IOException { InputStreamResource resource = mock(); given(resource.contentLength()).willThrow(IOException.class); HttpRange range = HttpRange.createByteRange(0, 9); @@ -178,7 +178,7 @@ public void toResourceRegionStartingAtResourceByteCount() { } @Test - public void toResourceRegionsValidations() { + void toResourceRegionsValidations() { byte[] bytes = "12345".getBytes(StandardCharsets.UTF_8); ByteArrayResource resource = new ByteArrayResource(bytes); diff --git a/spring-web/src/test/java/org/springframework/http/MediaTypeFactoryTests.java b/spring-web/src/test/java/org/springframework/http/MediaTypeFactoryTests.java index 8840e8789c58..ce825c3af4ca 100644 --- a/spring-web/src/test/java/org/springframework/http/MediaTypeFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/http/MediaTypeFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -25,10 +25,10 @@ /** * @author Arjen Poutsma */ -public class MediaTypeFactoryTests { +class MediaTypeFactoryTests { @Test - public void getMediaType() { + void getMediaType() { assertThat(MediaTypeFactory.getMediaType("file.xml")).contains(MediaType.APPLICATION_XML); assertThat(MediaTypeFactory.getMediaType("file.js")).contains(MediaType.parseMediaType("application/javascript")); assertThat(MediaTypeFactory.getMediaType("file.css")).contains(MediaType.parseMediaType("text/css")); @@ -36,7 +36,7 @@ public void getMediaType() { } @Test - public void nullParameter() { + void nullParameter() { assertThat(MediaTypeFactory.getMediaType((String) null)).isNotPresent(); assertThat(MediaTypeFactory.getMediaType((Resource) null)).isNotPresent(); assertThat(MediaTypeFactory.getMediaTypes(null)).isEmpty(); diff --git a/spring-web/src/test/java/org/springframework/http/MediaTypeTests.java b/spring-web/src/test/java/org/springframework/http/MediaTypeTests.java index c2b5ba204729..ff9a2055511c 100644 --- a/spring-web/src/test/java/org/springframework/http/MediaTypeTests.java +++ b/spring-web/src/test/java/org/springframework/http/MediaTypeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -40,35 +40,35 @@ * @author Juergen Hoeller * @author Sam Brannen */ -public class MediaTypeTests { +class MediaTypeTests { @Test - public void testToString() throws Exception { + void testToString() { MediaType mediaType = new MediaType("text", "plain", 0.7); String result = mediaType.toString(); assertThat(result).as("Invalid toString() returned").isEqualTo("text/plain;q=0.7"); } @Test - public void slashInType() { + void slashInType() { assertThatIllegalArgumentException().isThrownBy(() -> new MediaType("text/plain")); } @Test - public void slashInSubtype() { + void slashInSubtype() { assertThatIllegalArgumentException().isThrownBy(() -> new MediaType("text", "/")); } @Test - public void getDefaultQualityValue() { + void getDefaultQualityValue() { MediaType mediaType = new MediaType("text", "plain"); assertThat(mediaType.getQualityValue()).as("Invalid quality value").isCloseTo(1D, within(0D)); } @Test - public void parseMediaType() throws Exception { + void parseMediaType() { String s = "audio/*; q=0.2"; MediaType mediaType = MediaType.parseMediaType(s); assertThat(mediaType.getType()).as("Invalid type").isEqualTo("audio"); @@ -77,73 +77,73 @@ public void parseMediaType() throws Exception { } @Test - public void parseMediaTypeNoSubtype() { + void parseMediaTypeNoSubtype() { assertThatExceptionOfType(InvalidMediaTypeException.class).isThrownBy(() -> MediaType.parseMediaType("audio")); } @Test - public void parseMediaTypeNoSubtypeSlash() { + void parseMediaTypeNoSubtypeSlash() { assertThatExceptionOfType(InvalidMediaTypeException.class).isThrownBy(() -> MediaType.parseMediaType("audio/")); } @Test - public void parseMediaTypeTypeRange() { + void parseMediaTypeTypeRange() { assertThatExceptionOfType(InvalidMediaTypeException.class).isThrownBy(() -> MediaType.parseMediaType("*/json")); } @Test - public void parseMediaTypeIllegalType() { + void parseMediaTypeIllegalType() { assertThatExceptionOfType(InvalidMediaTypeException.class).isThrownBy(() -> MediaType.parseMediaType("audio(/basic")); } @Test - public void parseMediaTypeIllegalSubtype() { + void parseMediaTypeIllegalSubtype() { assertThatExceptionOfType(InvalidMediaTypeException.class).isThrownBy(() -> MediaType.parseMediaType("audio/basic)")); } @Test - public void parseMediaTypeEmptyParameterAttribute() { + void parseMediaTypeEmptyParameterAttribute() { assertThatExceptionOfType(InvalidMediaTypeException.class).isThrownBy(() -> MediaType.parseMediaType("audio/*;=value")); } @Test - public void parseMediaTypeEmptyParameterValue() { + void parseMediaTypeEmptyParameterValue() { assertThatExceptionOfType(InvalidMediaTypeException.class).isThrownBy(() -> MediaType.parseMediaType("audio/*;attr=")); } @Test - public void parseMediaTypeIllegalParameterAttribute() { + void parseMediaTypeIllegalParameterAttribute() { assertThatExceptionOfType(InvalidMediaTypeException.class).isThrownBy(() -> MediaType.parseMediaType("audio/*;attr<=value")); } @Test - public void parseMediaTypeIllegalParameterValue() { + void parseMediaTypeIllegalParameterValue() { assertThatExceptionOfType(InvalidMediaTypeException.class).isThrownBy(() -> MediaType.parseMediaType("audio/*;attr=v>alue")); } @Test - public void parseMediaTypeIllegalQualityFactor() { + void parseMediaTypeIllegalQualityFactor() { assertThatExceptionOfType(InvalidMediaTypeException.class).isThrownBy(() -> MediaType.parseMediaType("audio/basic;q=1.1")); } @Test - public void parseMediaTypeIllegalCharset() { + void parseMediaTypeIllegalCharset() { assertThatExceptionOfType(InvalidMediaTypeException.class).isThrownBy(() -> MediaType.parseMediaType("text/html; charset=foo-bar")); } @Test - public void parseURLConnectionMediaType() throws Exception { + void parseURLConnectionMediaType() { String s = "*; q=.2"; MediaType mediaType = MediaType.parseMediaType(s); assertThat(mediaType.getType()).as("Invalid type").isEqualTo("*"); @@ -152,7 +152,7 @@ public void parseURLConnectionMediaType() throws Exception { } @Test - public void parseMediaTypes() throws Exception { + void parseMediaTypes() { String s = "text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c"; List mediaTypes = MediaType.parseMediaTypes(s); assertThat(mediaTypes).as("No media types returned").isNotNull(); @@ -171,7 +171,7 @@ public void parseMediaTypesWithTrailingComma() { } @Test - public void compareTo() { + void compareTo() { MediaType audioBasic = new MediaType("audio", "basic"); MediaType audio = new MediaType("audio"); MediaType audioWave = new MediaType("audio", "wave"); @@ -206,7 +206,7 @@ public void compareTo() { } @Test - public void compareToConsistentWithEquals() { + void compareToConsistentWithEquals() { MediaType m1 = MediaType.parseMediaType("text/html; q=0.7; charset=iso-8859-1"); MediaType m2 = MediaType.parseMediaType("text/html; charset=iso-8859-1; q=0.7"); @@ -222,7 +222,7 @@ public void compareToConsistentWithEquals() { } @Test - public void compareToCaseSensitivity() { + void compareToCaseSensitivity() { MediaType m1 = new MediaType("audio", "basic"); MediaType m2 = new MediaType("Audio", "Basic"); assertThat(m1.compareTo(m2)).as("Invalid comparison result").isEqualTo(0); @@ -280,7 +280,7 @@ void isLessSpecific() { } @Test - public void specificityComparator() throws Exception { + void specificityComparator() { MediaType audioBasic = new MediaType("audio", "basic"); MediaType audioWave = new MediaType("audio", "wave"); MediaType audio = new MediaType("audio"); @@ -388,7 +388,7 @@ public void sortBySpecificityUnrelated() { } @Test - public void qualityComparator() throws Exception { + void qualityComparator() { MediaType audioBasic = new MediaType("audio", "basic"); MediaType audioWave = new MediaType("audio", "wave"); MediaType audio = new MediaType("audio"); @@ -495,7 +495,7 @@ public void sortByQualityUnrelated() { } @Test - public void testWithConversionService() { + void testWithConversionService() { ConversionService conversionService = new DefaultConversionService(); assertThat(conversionService.canConvert(String.class, MediaType.class)).isTrue(); MediaType mediaType = MediaType.parseMediaType("application/xml"); @@ -503,7 +503,7 @@ public void testWithConversionService() { } @Test - public void isConcrete() { + void isConcrete() { assertThat(MediaType.TEXT_PLAIN.isConcrete()).as("text/plain not concrete").isTrue(); assertThat(MediaType.ALL.isConcrete()).as("*/* concrete").isFalse(); assertThat(new MediaType("text", "*").isConcrete()).as("text/* concrete").isFalse(); @@ -518,7 +518,7 @@ void serialize() throws Exception { } @Test - public void sortBySpecificity() { + void sortBySpecificity() { MediaType audioBasic = new MediaType("audio", "basic"); MediaType audio = new MediaType("audio"); MediaType audio03 = new MediaType("audio", "*", 0.3); diff --git a/spring-web/src/test/java/org/springframework/http/ResponseCookieTests.java b/spring-web/src/test/java/org/springframework/http/ResponseCookieTests.java index a74aaf073f06..444b0dd26e2b 100644 --- a/spring-web/src/test/java/org/springframework/http/ResponseCookieTests.java +++ b/spring-web/src/test/java/org/springframework/http/ResponseCookieTests.java @@ -28,10 +28,10 @@ * * @author Rossen Stoyanchev */ -public class ResponseCookieTests { +class ResponseCookieTests { @Test - public void basic() { + void basic() { assertThat(ResponseCookie.from("id", null).build().toString()).isEqualTo("id="); assertThat(ResponseCookie.from("id", "1fWa").build().toString()).isEqualTo("id=1fWa"); @@ -46,7 +46,7 @@ public void basic() { } @Test - public void nameChecks() { + void nameChecks() { Arrays.asList("id", "i.d.", "i-d", "+id", "i*d", "i$d", "#id") .forEach(name -> ResponseCookie.from(name, "value").build()); @@ -57,7 +57,7 @@ public void nameChecks() { } @Test - public void valueChecks() { + void valueChecks() { Arrays.asList("1fWa", "", null, "1f=Wa", "1f-Wa", "1f/Wa", "1.f.W.a.") .forEach(value -> ResponseCookie.from("id", value).build()); @@ -68,7 +68,7 @@ public void valueChecks() { } @Test - public void domainChecks() { + void domainChecks() { Arrays.asList("abc", "abc.org", "abc-def.org", "abc3.org", ".abc.org") .forEach(domain -> ResponseCookie.from("n", "v").domain(domain).build()); diff --git a/spring-web/src/test/java/org/springframework/http/client/AbstractMockWebServerTests.java b/spring-web/src/test/java/org/springframework/http/client/AbstractMockWebServerTests.java index 2c52cdf23ea0..c2237dd61d84 100644 --- a/spring-web/src/test/java/org/springframework/http/client/AbstractMockWebServerTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/AbstractMockWebServerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -45,7 +45,7 @@ public abstract class AbstractMockWebServerTests { new MediaType("text", "plain", Collections.singletonMap("charset", "UTF-8")); @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { this.server = new MockWebServer(); this.server.setDispatcher(new TestDispatcher()); this.server.start(); @@ -54,13 +54,13 @@ public void setUp() throws Exception { } @AfterEach - public void tearDown() throws Exception { + void tearDown() throws Exception { this.server.shutdown(); } protected class TestDispatcher extends Dispatcher { @Override - public MockResponse dispatch(RecordedRequest request) throws InterruptedException { + public MockResponse dispatch(RecordedRequest request) { try { if (request.getPath().equals("/echo")) { assertThat(request.getHeader("Host")) diff --git a/spring-web/src/test/java/org/springframework/http/client/BufferingClientHttpRequestFactoryTests.java b/spring-web/src/test/java/org/springframework/http/client/BufferingClientHttpRequestFactoryTests.java index 3f0a595ddf8d..4716e351af4c 100644 --- a/spring-web/src/test/java/org/springframework/http/client/BufferingClientHttpRequestFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/BufferingClientHttpRequestFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -17,6 +17,7 @@ package org.springframework.http.client; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import org.junit.jupiter.api.Test; @@ -43,7 +44,7 @@ void repeatableRead() throws Exception { request.getHeaders().add(headerName, headerValue1); String headerValue2 = "value2"; request.getHeaders().add(headerName, headerValue2); - byte[] body = "Hello World".getBytes("UTF-8"); + byte[] body = "Hello World".getBytes(StandardCharsets.UTF_8); request.getHeaders().setContentLength(body.length); FileCopyUtils.copy(body, request.getBody()); try (ClientHttpResponse response = request.execute()) { diff --git a/spring-web/src/test/java/org/springframework/http/client/InterceptingClientHttpRequestFactoryTests.java b/spring-web/src/test/java/org/springframework/http/client/InterceptingClientHttpRequestFactoryTests.java index fa1ceab6b66f..27c1b3b778ae 100644 --- a/spring-web/src/test/java/org/springframework/http/client/InterceptingClientHttpRequestFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/InterceptingClientHttpRequestFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -101,7 +101,7 @@ void changeHeaders() throws Exception { requestMock = new MockClientHttpRequest() { @Override - protected ClientHttpResponse executeInternal() throws IOException { + protected ClientHttpResponse executeInternal() { List headerValues = getHeaders().get(headerName); assertThat(headerValues).hasSize(2); assertThat(headerValues).element(0).isEqualTo(headerValue); diff --git a/spring-web/src/test/java/org/springframework/http/client/InterceptingStreamingHttpComponentsTests.java b/spring-web/src/test/java/org/springframework/http/client/InterceptingStreamingHttpComponentsTests.java index d84bbb74006a..030f995d9610 100644 --- a/spring-web/src/test/java/org/springframework/http/client/InterceptingStreamingHttpComponentsTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/InterceptingStreamingHttpComponentsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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,7 +23,7 @@ /** * @author Juergen Hoeller */ -public class InterceptingStreamingHttpComponentsTests extends AbstractHttpRequestFactoryTests { +class InterceptingStreamingHttpComponentsTests extends AbstractHttpRequestFactoryTests { @Override protected ClientHttpRequestFactory createRequestFactory() { @@ -33,7 +33,7 @@ protected ClientHttpRequestFactory createRequestFactory() { @Override @Test - public void httpMethods() throws Exception { + void httpMethods() throws Exception { super.httpMethods(); assertHttpMethod("patch", HttpMethod.PATCH); } diff --git a/spring-web/src/test/java/org/springframework/http/client/JdkClientHttpRequestFactoryTests.java b/spring-web/src/test/java/org/springframework/http/client/JdkClientHttpRequestFactoryTests.java index 45a6bb5dc591..675637c0d8a9 100644 --- a/spring-web/src/test/java/org/springframework/http/client/JdkClientHttpRequestFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/JdkClientHttpRequestFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -33,7 +33,7 @@ /** * @author Marten Deinum */ -public class JdkClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests { +class JdkClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests { @Nullable private static String originalPropertyValue; @@ -61,13 +61,13 @@ protected ClientHttpRequestFactory createRequestFactory() { @Override @Test - public void httpMethods() throws Exception { + void httpMethods() throws Exception { super.httpMethods(); assertHttpMethod("patch", HttpMethod.PATCH); } @Test - public void customizeDisallowedHeaders() throws IOException { + void customizeDisallowedHeaders() throws IOException { ClientHttpRequest request = this.factory.createRequest(URI.create(this.baseUrl + "/status/299"), HttpMethod.PUT); request.getHeaders().set("Expect", "299"); diff --git a/spring-web/src/test/java/org/springframework/http/client/JettyClientHttpRequestFactoryTests.java b/spring-web/src/test/java/org/springframework/http/client/JettyClientHttpRequestFactoryTests.java index 83e6981634e2..e66728b4c88f 100644 --- a/spring-web/src/test/java/org/springframework/http/client/JettyClientHttpRequestFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/JettyClientHttpRequestFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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,7 +23,7 @@ /** * @author Arjen Poutsma */ -public class JettyClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests { +class JettyClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests { @Override protected ClientHttpRequestFactory createRequestFactory() { @@ -32,7 +32,7 @@ protected ClientHttpRequestFactory createRequestFactory() { @Override @Test - public void httpMethods() throws Exception { + void httpMethods() throws Exception { super.httpMethods(); assertHttpMethod("patch", HttpMethod.PATCH); } diff --git a/spring-web/src/test/java/org/springframework/http/client/MultipartBodyBuilderTests.java b/spring-web/src/test/java/org/springframework/http/client/MultipartBodyBuilderTests.java index cdbae58f7832..95653da2d393 100644 --- a/spring-web/src/test/java/org/springframework/http/client/MultipartBodyBuilderTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/MultipartBodyBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -35,10 +35,10 @@ /** * @author Arjen Poutsma */ -public class MultipartBodyBuilderTests { +class MultipartBodyBuilderTests { @Test - public void builder() { + void builder() { MultipartBodyBuilder builder = new MultipartBodyBuilder(); diff --git a/spring-web/src/test/java/org/springframework/http/client/OkHttp3ClientHttpRequestFactoryTests.java b/spring-web/src/test/java/org/springframework/http/client/OkHttp3ClientHttpRequestFactoryTests.java index 106db136fd1f..8ebc5397fad9 100644 --- a/spring-web/src/test/java/org/springframework/http/client/OkHttp3ClientHttpRequestFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/OkHttp3ClientHttpRequestFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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,7 +23,7 @@ /** * @author Roy Clarkson */ -public class OkHttp3ClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests { +class OkHttp3ClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests { @SuppressWarnings("removal") @Override @@ -33,7 +33,7 @@ protected ClientHttpRequestFactory createRequestFactory() { @Override @Test - public void httpMethods() throws Exception { + void httpMethods() throws Exception { super.httpMethods(); assertHttpMethod("patch", HttpMethod.PATCH); } diff --git a/spring-web/src/test/java/org/springframework/http/client/ReactorNettyClientHttpRequestFactoryTests.java b/spring-web/src/test/java/org/springframework/http/client/ReactorNettyClientHttpRequestFactoryTests.java index 689eb08668ec..bff1f3ea353f 100644 --- a/spring-web/src/test/java/org/springframework/http/client/ReactorNettyClientHttpRequestFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/ReactorNettyClientHttpRequestFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -29,7 +29,7 @@ * @author Arjen Poutsma * @author Sebastien Deleuze */ -public class ReactorNettyClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests { +class ReactorNettyClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests { @Override protected ClientHttpRequestFactory createRequestFactory() { @@ -38,7 +38,7 @@ protected ClientHttpRequestFactory createRequestFactory() { @Override @Test - public void httpMethods() throws Exception { + void httpMethods() throws Exception { super.httpMethods(); assertHttpMethod("patch", HttpMethod.PATCH); } diff --git a/spring-web/src/test/java/org/springframework/http/client/SimpleClientHttpRequestFactoryTests.java b/spring-web/src/test/java/org/springframework/http/client/SimpleClientHttpRequestFactoryTests.java index 00984e7bff3b..7d15d2b61ffc 100644 --- a/spring-web/src/test/java/org/springframework/http/client/SimpleClientHttpRequestFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/SimpleClientHttpRequestFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -47,14 +47,14 @@ protected ClientHttpRequestFactory createRequestFactory() { @Override @Test - public void httpMethods() throws Exception { + void httpMethods() throws Exception { super.httpMethods(); assertThatExceptionOfType(ProtocolException.class).isThrownBy(() -> assertHttpMethod("patch", HttpMethod.PATCH)); } @Test - public void prepareConnectionWithRequestBody() throws Exception { + void prepareConnectionWithRequestBody() throws Exception { URI uri = new URI("https://example.com"); testRequestBodyAllowed(uri, "GET", false); testRequestBodyAllowed(uri, "HEAD", false); @@ -72,7 +72,7 @@ private void testRequestBodyAllowed(URI uri, String httpMethod, boolean allowed) } @Test - public void deleteWithoutBodyDoesNotRaiseException() throws Exception { + void deleteWithoutBodyDoesNotRaiseException() throws Exception { HttpURLConnection connection = new TestHttpURLConnection(new URL("https://example.com")); ((SimpleClientHttpRequestFactory) this.factory).prepareConnection(connection, "DELETE"); SimpleClientHttpRequest request = new SimpleClientHttpRequest(connection, 4096); @@ -125,7 +125,7 @@ public TestHttpURLConnection(URL uri) { } @Override - public void connect() throws IOException { + public void connect() { } @Override @@ -138,7 +138,7 @@ public boolean usingProxy() { } @Override - public InputStream getInputStream() throws IOException { + public InputStream getInputStream() { return new ByteArrayInputStream(new byte[0]); } } diff --git a/spring-web/src/test/java/org/springframework/http/client/SimpleClientHttpResponseTests.java b/spring-web/src/test/java/org/springframework/http/client/SimpleClientHttpResponseTests.java index 3a525ca1cf94..1dd50d93cd25 100644 --- a/spring-web/src/test/java/org/springframework/http/client/SimpleClientHttpResponseTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/SimpleClientHttpResponseTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -39,7 +39,7 @@ * @author Brian Clozel * @author Juergen Hoeller */ -public class SimpleClientHttpResponseTests { +class SimpleClientHttpResponseTests { private final HttpURLConnection connection = mock(); diff --git a/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java b/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java index 827ba44dbd34..d3ee539b9c42 100644 --- a/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -59,7 +59,7 @@ /** * @author Arjen Poutsma */ -public class ClientHttpConnectorTests { +class ClientHttpConnectorTests { private static final int BUF_SIZE = 1024; diff --git a/spring-web/src/test/java/org/springframework/http/client/reactive/ReactorResourceFactoryTests.java b/spring-web/src/test/java/org/springframework/http/client/reactive/ReactorResourceFactoryTests.java index 7e1b963a434e..4fa6220c6488 100644 --- a/spring-web/src/test/java/org/springframework/http/client/reactive/ReactorResourceFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/reactive/ReactorResourceFactoryTests.java @@ -38,7 +38,7 @@ * @author Rossen Stoyanchev * @author Sebastien Deleuze */ -public class ReactorResourceFactoryTests { +class ReactorResourceFactoryTests { private final ReactorResourceFactory resourceFactory = new ReactorResourceFactory(); @@ -156,7 +156,7 @@ void externalResources() { this.resourceFactory.destroy(); - // Not managed (destroy has no impact).. + // Not managed (destroy has no impact) verifyNoMoreInteractions(this.connectionProvider, this.loopResources); } diff --git a/spring-web/src/test/java/org/springframework/http/client/support/InterceptingHttpAccessorTests.java b/spring-web/src/test/java/org/springframework/http/client/support/InterceptingHttpAccessorTests.java index 17035e0b060c..f9c65f1ebfca 100644 --- a/spring-web/src/test/java/org/springframework/http/client/support/InterceptingHttpAccessorTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/support/InterceptingHttpAccessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -35,11 +35,10 @@ * * @author Brian Clozel */ -public class InterceptingHttpAccessorTests { +class InterceptingHttpAccessorTests { @Test - public void getInterceptors() { - @SuppressWarnings("resource") + void getInterceptors() { TestInterceptingHttpAccessor accessor = new TestInterceptingHttpAccessor(); List interceptors = Arrays.asList( new SecondClientHttpRequestInterceptor(), @@ -55,12 +54,12 @@ public void getInterceptors() { } - private class TestInterceptingHttpAccessor extends InterceptingHttpAccessor { + private static class TestInterceptingHttpAccessor extends InterceptingHttpAccessor { } @Order(1) - private class FirstClientHttpRequestInterceptor implements ClientHttpRequestInterceptor { + private static class FirstClientHttpRequestInterceptor implements ClientHttpRequestInterceptor { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) { @@ -69,7 +68,7 @@ public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttp } - private class SecondClientHttpRequestInterceptor implements ClientHttpRequestInterceptor, Ordered { + private static class SecondClientHttpRequestInterceptor implements ClientHttpRequestInterceptor, Ordered { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) { @@ -83,7 +82,7 @@ public int getOrder() { } - private class ThirdClientHttpRequestInterceptor implements ClientHttpRequestInterceptor { + private static class ThirdClientHttpRequestInterceptor implements ClientHttpRequestInterceptor { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) { diff --git a/spring-web/src/test/java/org/springframework/http/codec/CancelWithoutDemandCodecTests.java b/spring-web/src/test/java/org/springframework/http/codec/CancelWithoutDemandCodecTests.java index 533bfe0e7890..eed700ecb3ec 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/CancelWithoutDemandCodecTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/CancelWithoutDemandCodecTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -53,13 +53,13 @@ * Test scenarios for data buffer leaks. * @author Rossen Stoyanchev */ -public class CancelWithoutDemandCodecTests { +class CancelWithoutDemandCodecTests { private final LeakAwareDataBufferFactory bufferFactory = new LeakAwareDataBufferFactory(); @AfterEach - public void tearDown() throws Exception { + void tearDown() { this.bufferFactory.checkForLeaks(); } @@ -83,7 +83,7 @@ public void cancelWithJackson() { MediaType.APPLICATION_JSON, Collections.emptyMap()); BaseSubscriber subscriber = new ZeroDemandSubscriber(); - flux.subscribe(subscriber); // Assume sync execution (e.g. encoding with Flux.just).. + flux.subscribe(subscriber); // Assume sync execution (e.g. encoding with Flux.just) subscriber.cancel(); } @@ -96,7 +96,7 @@ public void cancelWithJaxb2() { MediaType.APPLICATION_XML, Collections.emptyMap()); BaseSubscriber subscriber = new ZeroDemandSubscriber(); - flux.subscribe(subscriber); // Assume sync execution (e.g. encoding with Flux.just).. + flux.subscribe(subscriber); // Assume sync execution (e.g. encoding with Flux.just) subscriber.cancel(); } @@ -110,12 +110,12 @@ public void cancelWithProtobufEncoder() { MediaType.APPLICATION_PROTOBUF, Collections.emptyMap()); BaseSubscriber subscriber = new ZeroDemandSubscriber(); - flux.subscribe(subscriber); // Assume sync execution (e.g. encoding with Flux.just).. + flux.subscribe(subscriber); // Assume sync execution (e.g. encoding with Flux.just) subscriber.cancel(); } @Test // gh-22731 - public void cancelWithProtobufDecoder() throws InterruptedException { + public void cancelWithProtobufDecoder() { ProtobufDecoder decoder = new ProtobufDecoder(); Mono input = Mono.fromCallable(() -> { @@ -187,7 +187,7 @@ public boolean isCommitted() { public Mono writeWith(Publisher body) { Flux flux = Flux.from(body); BaseSubscriber subscriber = new ZeroDemandSubscriber(); - flux.subscribe(subscriber); // Assume sync execution (e.g. encoding with Flux.just).. + flux.subscribe(subscriber); // Assume sync execution (e.g. encoding with Flux.just) subscriber.cancel(); return Mono.empty(); } @@ -196,7 +196,7 @@ public Mono writeWith(Publisher body) { public Mono writeAndFlushWith(Publisher> body) { Flux flux = Flux.from(body).concatMap(Flux::from); BaseSubscriber subscriber = new ZeroDemandSubscriber(); - flux.subscribe(subscriber); // Assume sync execution (e.g. encoding with Flux.just).. + flux.subscribe(subscriber); // Assume sync execution (e.g. encoding with Flux.just) subscriber.cancel(); return Mono.empty(); } diff --git a/spring-web/src/test/java/org/springframework/http/codec/EncoderHttpMessageWriterTests.java b/spring-web/src/test/java/org/springframework/http/codec/EncoderHttpMessageWriterTests.java index 8ff86275bf8d..eff738c3c9f0 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/EncoderHttpMessageWriterTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/EncoderHttpMessageWriterTests.java @@ -188,7 +188,7 @@ void emptyBodyWritten() { void isStreamingMediaType() throws InvocationTargetException, IllegalAccessException { configureEncoder(TEXT_HTML); MediaType streamingMediaType = new MediaType(TEXT_PLAIN, Collections.singletonMap("streaming", "true")); - given(this.encoder.getStreamingMediaTypes()).willReturn(Arrays.asList(streamingMediaType)); + given(this.encoder.getStreamingMediaTypes()).willReturn(List.of(streamingMediaType)); HttpMessageWriter writer = new EncoderHttpMessageWriter<>(this.encoder); Method method = ReflectionUtils.findMethod(writer.getClass(), "isStreamingMediaType", MediaType.class); diff --git a/spring-web/src/test/java/org/springframework/http/codec/FormHttpMessageReaderTests.java b/spring-web/src/test/java/org/springframework/http/codec/FormHttpMessageReaderTests.java index 63128000b312..bbec03d2dae1 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/FormHttpMessageReaderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/FormHttpMessageReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -41,13 +41,13 @@ /** * @author Sebastien Deleuze */ -public class FormHttpMessageReaderTests extends AbstractLeakCheckingTests { +class FormHttpMessageReaderTests extends AbstractLeakCheckingTests { private final FormHttpMessageReader reader = new FormHttpMessageReader(); @Test - public void canRead() { + void canRead() { assertThat(this.reader.canRead( ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, String.class), MediaType.APPLICATION_FORM_URLENCODED)).isTrue(); @@ -74,7 +74,7 @@ public void canRead() { } @Test - public void readFormAsMono() { + void readFormAsMono() { String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3"; MockServerHttpRequest request = request(body); MultiValueMap result = this.reader.readMono(null, request, null).block(); @@ -82,14 +82,12 @@ public void readFormAsMono() { assertThat(result).as("Invalid result").hasSize(3); assertThat(result.getFirst("name 1")).as("Invalid result").isEqualTo("value 1"); List values = result.get("name 2"); - assertThat(values).as("Invalid result").hasSize(2); - assertThat(values).element(0).as("Invalid result").isEqualTo("value 2+1"); - assertThat(values).element(1).as("Invalid result").isEqualTo("value 2+2"); + assertThat(values).as("Invalid result").containsExactly("value 2+1", "value 2+2"); assertThat(result.getFirst("name 3")).as("Invalid result").isNull(); } @Test - public void readFormAsFlux() { + void readFormAsFlux() { String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3"; MockServerHttpRequest request = request(body); MultiValueMap result = this.reader.read(null, request, null).single().block(); @@ -97,14 +95,12 @@ public void readFormAsFlux() { assertThat(result).as("Invalid result").hasSize(3); assertThat(result.getFirst("name 1")).as("Invalid result").isEqualTo("value 1"); List values = result.get("name 2"); - assertThat(values).as("Invalid result").hasSize(2); - assertThat(values).element(0).as("Invalid result").isEqualTo("value 2+1"); - assertThat(values).element(1).as("Invalid result").isEqualTo("value 2+2"); + assertThat(values).as("Invalid result").containsExactly("value 2+1", "value 2+2"); assertThat(result.getFirst("name 3")).as("Invalid result").isNull(); } @Test - public void readFormError() { + void readFormError() { DataBuffer fooBuffer = stringBuffer("name=value"); Flux body = Flux.just(fooBuffer).concatWith(Flux.error(new RuntimeException())); diff --git a/spring-web/src/test/java/org/springframework/http/codec/FormHttpMessageWriterTests.java b/spring-web/src/test/java/org/springframework/http/codec/FormHttpMessageWriterTests.java index 66854934781a..e51b297db2fe 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/FormHttpMessageWriterTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/FormHttpMessageWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -39,13 +39,13 @@ /** * @author Sebastien Deleuze */ -public class FormHttpMessageWriterTests extends AbstractLeakCheckingTests { +class FormHttpMessageWriterTests extends AbstractLeakCheckingTests { private final FormHttpMessageWriter writer = new FormHttpMessageWriter(); @Test - public void canWrite() { + void canWrite() { assertThat(this.writer.canWrite( ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, String.class), MediaType.APPLICATION_FORM_URLENCODED)).isTrue(); @@ -73,7 +73,7 @@ public void canWrite() { } @Test - public void writeForm() { + void writeForm() { MultiValueMap body = new LinkedMultiValueMap<>(); body.set("name 1", "value 1"); body.add("name 2", "value 2+1"); diff --git a/spring-web/src/test/java/org/springframework/http/codec/ResourceHttpMessageReaderTests.java b/spring-web/src/test/java/org/springframework/http/codec/ResourceHttpMessageReaderTests.java index 4c7b4dd7df7d..517fc1abeaae 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/ResourceHttpMessageReaderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/ResourceHttpMessageReaderTests.java @@ -40,7 +40,7 @@ * * @author Rossen Stoyanchev */ -public class ResourceHttpMessageReaderTests extends AbstractLeakCheckingTests { +class ResourceHttpMessageReaderTests extends AbstractLeakCheckingTests { private final ResourceHttpMessageReader reader = new ResourceHttpMessageReader(); diff --git a/spring-web/src/test/java/org/springframework/http/codec/ResourceHttpMessageWriterTests.java b/spring-web/src/test/java/org/springframework/http/codec/ResourceHttpMessageWriterTests.java index e5c0a4668a65..d341150185a6 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/ResourceHttpMessageWriterTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/ResourceHttpMessageWriterTests.java @@ -48,7 +48,7 @@ * @author Brian Clozel * @author Rossen Stoyanchev */ -public class ResourceHttpMessageWriterTests { +class ResourceHttpMessageWriterTests { private static final Map HINTS = Collections.emptyMap(); @@ -63,13 +63,13 @@ public class ResourceHttpMessageWriterTests { @Test @SuppressWarnings({ "unchecked", "rawtypes" }) - public void getWritableMediaTypes() throws Exception { + public void getWritableMediaTypes() { assertThat((List) this.writer.getWritableMediaTypes()) .containsExactlyInAnyOrder(MimeTypeUtils.APPLICATION_OCTET_STREAM, MimeTypeUtils.ALL); } @Test - public void writeResourceServer() throws Exception { + void writeResourceServer() { testWrite(get("/").build()); @@ -82,7 +82,7 @@ public void writeResourceServer() throws Exception { } @Test - public void writeResourceClient() throws Exception { + void writeResourceClient() { MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, "/"); Mono mono = this.writer.write(this.input, ResolvableType.forClass(Resource.class), TEXT_PLAIN, request, HINTS); @@ -97,7 +97,7 @@ public void writeResourceClient() throws Exception { } @Test - public void writeSingleRegion() throws Exception { + void writeSingleRegion() { testWrite(get("/").range(of(0, 5)).build()); @@ -109,7 +109,7 @@ public void writeSingleRegion() throws Exception { } @Test - public void writeMultipleRegions() throws Exception { + void writeMultipleRegions() { testWrite(get("/").range(of(0,5), of(7,15), of(17,20), of(22,38)).build()); @@ -148,7 +148,7 @@ public void writeMultipleRegions() throws Exception { } @Test - public void invalidRange() throws Exception { + void invalidRange() { testWrite(get("/").header(HttpHeaders.RANGE, "invalid").build()); diff --git a/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageReaderTests.java b/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageReaderTests.java index 53384e90ace9..f2b9c7eaf3f8 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageReaderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageReaderTests.java @@ -44,7 +44,7 @@ */ class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingTests { - private Jackson2JsonDecoder jsonDecoder = new Jackson2JsonDecoder(); + private final Jackson2JsonDecoder jsonDecoder = new Jackson2JsonDecoder(); private ServerSentEventHttpMessageReader reader = new ServerSentEventHttpMessageReader(this.jsonDecoder); diff --git a/spring-web/src/test/java/org/springframework/http/codec/cbor/Jackson2CborDecoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/cbor/Jackson2CborDecoderTests.java index 9232e7455f4d..c640b3ba538e 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/cbor/Jackson2CborDecoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/cbor/Jackson2CborDecoderTests.java @@ -40,7 +40,7 @@ * * @author Sebastien Deleuze */ -public class Jackson2CborDecoderTests extends AbstractDecoderTests { +class Jackson2CborDecoderTests extends AbstractDecoderTests { private static final MimeType CBOR_MIME_TYPE = new MimeType("application", "cbor"); @@ -56,7 +56,7 @@ public Jackson2CborDecoderTests() { @Override @Test - public void canDecode() { + protected void canDecode() { assertThat(decoder.canDecode(ResolvableType.forClass(Pojo.class), CBOR_MIME_TYPE)).isTrue(); assertThat(decoder.canDecode(ResolvableType.forClass(Pojo.class), null)).isTrue(); @@ -66,7 +66,7 @@ public void canDecode() { @Override @Test - public void decode() { + protected void decode() { Flux input = Flux.just(this.pojo1, this.pojo2) .map(this::writeObject) .flatMap(this::dataBuffer); @@ -90,7 +90,7 @@ private byte[] writeObject(Object o) { @Override @Test - public void decodeToMono() { + protected void decodeToMono() { List expected = Arrays.asList(pojo1, pojo2); Flux input = Flux.just(expected) diff --git a/spring-web/src/test/java/org/springframework/http/codec/cbor/Jackson2CborEncoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/cbor/Jackson2CborEncoderTests.java index 37065b1a9f5f..ba041018f597 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/cbor/Jackson2CborEncoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/cbor/Jackson2CborEncoderTests.java @@ -43,7 +43,7 @@ * * @author Sebastien Deleuze */ -public class Jackson2CborEncoderTests extends AbstractLeakCheckingTests { +class Jackson2CborEncoderTests extends AbstractLeakCheckingTests { private static final MimeType CBOR_MIME_TYPE = new MimeType("application", "cbor"); @@ -66,7 +66,7 @@ private Consumer pojoConsumer(Pojo expected) { } @Test - public void canEncode() { + void canEncode() { ResolvableType pojoType = ResolvableType.forClass(Pojo.class); assertThat(this.encoder.canEncode(pojoType, CBOR_MIME_TYPE)).isTrue(); assertThat(this.encoder.canEncode(pojoType, null)).isTrue(); @@ -76,7 +76,7 @@ public void canEncode() { } @Test - public void canNotEncode() { + void canNotEncode() { assertThat(this.encoder.canEncode(ResolvableType.forClass(String.class), null)).isFalse(); assertThat(this.encoder.canEncode(ResolvableType.forClass(Pojo.class), APPLICATION_XML)).isFalse(); @@ -85,14 +85,14 @@ public void canNotEncode() { } @Test - public void encode() { + void encode() { Pojo value = new Pojo("foo", "bar"); DataBuffer result = encoder.encodeValue(value, this.bufferFactory, ResolvableType.forClass(Pojo.class), CBOR_MIME_TYPE, null); pojoConsumer(value).accept(result); } @Test - public void encodeStream() { + void encodeStream() { Pojo pojo1 = new Pojo("foo", "bar"); Pojo pojo2 = new Pojo("foofoo", "barbar"); Pojo pojo3 = new Pojo("foofoofoo", "barbarbar"); diff --git a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java index 2edcd6090311..fb90638aeedd 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java @@ -62,7 +62,7 @@ * @author Sebastien Deleuze * @author Rossen Stoyanchev */ -public class Jackson2JsonDecoderTests extends AbstractDecoderTests { +class Jackson2JsonDecoderTests extends AbstractDecoderTests { private final Pojo pojo1 = new Pojo("f1", "b1"); @@ -94,7 +94,7 @@ public void canDecode() { } @Test - public void canDecodeWithObjectMapperRegistrationForType() { + void canDecodeWithObjectMapperRegistrationForType() { MediaType halJsonMediaType = MediaType.parseMediaType("application/hal+json"); MediaType halFormsJsonMediaType = MediaType.parseMediaType("application/prs.hal-forms+json"); @@ -124,7 +124,7 @@ public void canDecodeWithProvidedMimeType() { } @Test - public void decodableMimeTypesIsImmutable() { + void decodableMimeTypesIsImmutable() { MimeType textJavascript = new MimeType("text", "javascript", StandardCharsets.UTF_8); Jackson2JsonDecoder decoder = new Jackson2JsonDecoder(new ObjectMapper(), textJavascript); @@ -133,7 +133,7 @@ public void decodableMimeTypesIsImmutable() { } @Test - public void decodableMimeTypesWithObjectMapperRegistration() { + void decodableMimeTypesWithObjectMapperRegistration() { MimeType mimeType1 = MediaType.parseMediaType("application/hal+json"); MimeType mimeType2 = new MimeType("text", "javascript", StandardCharsets.UTF_8); @@ -146,7 +146,7 @@ public void decodableMimeTypesWithObjectMapperRegistration() { @Override @Test - public void decode() { + protected void decode() { Flux input = Flux.concat( stringBuffer("[{\"bar\":\"b1\",\"foo\":\"f1\"},"), stringBuffer("{\"bar\":\"b2\",\"foo\":\"f2\"}]")); @@ -159,7 +159,7 @@ public void decode() { @Override @Test - public void decodeToMono() { + protected void decodeToMono() { Flux input = Flux.concat( stringBuffer("[{\"bar\":\"b1\",\"foo\":\"f1\"},"), stringBuffer("{\"bar\":\"b2\",\"foo\":\"f2\"}]")); @@ -174,14 +174,14 @@ public void decodeToMono() { @Test - public void decodeEmptyArrayToFlux() { + void decodeEmptyArrayToFlux() { Flux input = Flux.from(stringBuffer("[]")); testDecode(input, Pojo.class, StepVerifier.LastStep::verifyComplete); } @Test - public void fieldLevelJsonView() { + void fieldLevelJsonView() { Flux input = Flux.from(stringBuffer( "{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}")); @@ -198,7 +198,7 @@ public void fieldLevelJsonView() { } @Test - public void classLevelJsonView() { + void classLevelJsonView() { Flux input = Flux.from(stringBuffer( "{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}")); @@ -216,7 +216,7 @@ public void classLevelJsonView() { } @Test - public void invalidData() { + void invalidData() { Flux input = Flux.from(stringBuffer("{\"foofoo\": \"foofoo\", \"barbar\": \"barbar\"")); testDecode(input, Pojo.class, step -> step.verifyError(DecodingException.class)); } @@ -243,7 +243,7 @@ public void noDefaultConstructor() { } @Test - public void codecException() { + void codecException() { Flux input = Flux.from(stringBuffer("[")); ResolvableType elementType = ResolvableType.forClass(BeanWithNoDefaultConstructor.class); Flux flux = new Jackson2JsonDecoder().decode(input, elementType, null, Collections.emptyMap()); @@ -261,7 +261,7 @@ public void customDeserializer() { } @Test - public void bigDecimalFlux() { + void bigDecimalFlux() { Flux input = stringBuffer("[ 1E+2 ]").flux(); testDecode(input, BigDecimal.class, step -> step diff --git a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonEncoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonEncoderTests.java index dbdca0ea99a5..cc8400a0a30a 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonEncoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonEncoderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -56,7 +56,7 @@ /** * @author Sebastien Deleuze */ -public class Jackson2JsonEncoderTests extends AbstractEncoderTests { +class Jackson2JsonEncoderTests extends AbstractEncoderTests { public Jackson2JsonEncoderTests() { super(new Jackson2JsonEncoder()); @@ -111,7 +111,7 @@ public void canEncodeWithCustomMimeType() { } @Test - public void encodableMimeTypesIsImmutable() { + void encodableMimeTypesIsImmutable() { MimeType textJavascript = new MimeType("text", "javascript", StandardCharsets.UTF_8); Jackson2JsonEncoder encoder = new Jackson2JsonEncoder(new ObjectMapper(), textJavascript); @@ -120,7 +120,7 @@ public void encodableMimeTypesIsImmutable() { } @Test - public void canNotEncode() { + void canNotEncode() { assertThat(this.encoder.canEncode(ResolvableType.forClass(String.class), null)).isFalse(); assertThat(this.encoder.canEncode(ResolvableType.forClass(Pojo.class), APPLICATION_XML)).isFalse(); @@ -129,7 +129,7 @@ public void canNotEncode() { } @Test - public void encodeNonStream() { + void encodeNonStream() { Flux input = Flux.just( new Pojo("foo", "bar"), new Pojo("foofoo", "barbar"), @@ -145,7 +145,7 @@ public void encodeNonStream() { } @Test - public void encodeNonStreamEmpty() { + void encodeNonStreamEmpty() { testEncode(Flux.empty(), Pojo.class, step -> step .consumeNextWith(expectString("[")) .consumeNextWith(expectString("]")) @@ -164,7 +164,7 @@ void encodeNonStreamWithErrorAsFirstSignal() { } @Test - public void encodeWithType() { + void encodeWithType() { Flux input = Flux.just(new Foo(), new Bar()); testEncode(input, ParentClass.class, step -> step @@ -195,7 +195,7 @@ public void encodeStreamWithCustomStreamingType() { } @Test - public void fieldLevelJsonView() { + void fieldLevelJsonView() { JacksonViewBean bean = new JacksonViewBean(); bean.setWithView1("with"); bean.setWithView2("with"); @@ -212,7 +212,7 @@ public void fieldLevelJsonView() { } @Test - public void classLevelJsonView() { + void classLevelJsonView() { JacksonViewBean bean = new JacksonViewBean(); bean.setWithView1("with"); bean.setWithView2("with"); @@ -229,7 +229,7 @@ public void classLevelJsonView() { } @Test - public void jacksonValue() { + void jacksonValue() { JacksonViewBean bean = new JacksonViewBean(); bean.setWithView1("with"); bean.setWithView2("with"); @@ -287,7 +287,7 @@ public void encodeWithFlushAfterWriteOff() { } @Test - public void encodeAscii() { + void encodeAscii() { Mono input = Mono.just(new Pojo("foo", "bar")); MimeType mimeType = new MimeType("application", "json", StandardCharsets.US_ASCII); diff --git a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2SmileDecoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2SmileDecoderTests.java index ba70e3a98875..9e46efc9ae5c 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2SmileDecoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2SmileDecoderTests.java @@ -39,7 +39,7 @@ * * @author Sebastien Deleuze */ -public class Jackson2SmileDecoderTests extends AbstractDecoderTests { +class Jackson2SmileDecoderTests extends AbstractDecoderTests { private static final MimeType SMILE_MIME_TYPE = new MimeType("application", "x-jackson-smile"); private static final MimeType STREAM_SMILE_MIME_TYPE = new MimeType("application", "stream+x-jackson-smile"); @@ -56,7 +56,7 @@ public Jackson2SmileDecoderTests() { @Override @Test - public void canDecode() { + protected void canDecode() { assertThat(decoder.canDecode(ResolvableType.forClass(Pojo.class), SMILE_MIME_TYPE)).isTrue(); assertThat(decoder.canDecode(ResolvableType.forClass(Pojo.class), STREAM_SMILE_MIME_TYPE)).isTrue(); assertThat(decoder.canDecode(ResolvableType.forClass(Pojo.class), null)).isTrue(); @@ -67,7 +67,7 @@ public void canDecode() { @Override @Test - public void decode() { + protected void decode() { Flux input = Flux.just(this.pojo1, this.pojo2) .map(this::writeObject) .flatMap(this::dataBuffer); @@ -91,7 +91,7 @@ private byte[] writeObject(Object o) { @Override @Test - public void decodeToMono() { + protected void decodeToMono() { List expected = Arrays.asList(pojo1, pojo2); Flux input = Flux.just(expected) diff --git a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2SmileEncoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2SmileEncoderTests.java index 9b74ae6c2abb..1a7523dbeca6 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2SmileEncoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2SmileEncoderTests.java @@ -46,7 +46,7 @@ * * @author Sebastien Deleuze */ -public class Jackson2SmileEncoderTests extends AbstractEncoderTests { +class Jackson2SmileEncoderTests extends AbstractEncoderTests { private static final MimeType SMILE_MIME_TYPE = new MimeType("application", "x-jackson-smile"); private static final MimeType STREAM_SMILE_MIME_TYPE = new MimeType("application", "stream+x-jackson-smile"); @@ -62,7 +62,7 @@ public Jackson2SmileEncoderTests() { @Override @Test - public void canEncode() { + protected void canEncode() { ResolvableType pojoType = ResolvableType.forClass(Pojo.class); assertThat(this.encoder.canEncode(pojoType, SMILE_MIME_TYPE)).isTrue(); assertThat(this.encoder.canEncode(pojoType, STREAM_SMILE_MIME_TYPE)).isTrue(); @@ -73,7 +73,7 @@ public void canEncode() { } @Test - public void canNotEncode() { + void canNotEncode() { assertThat(this.encoder.canEncode(ResolvableType.forClass(String.class), null)).isFalse(); assertThat(this.encoder.canEncode(ResolvableType.forClass(Pojo.class), APPLICATION_XML)).isFalse(); @@ -83,7 +83,7 @@ public void canNotEncode() { @Override @Test - public void encode() { + protected void encode() { List list = Arrays.asList( new Pojo("foo", "bar"), new Pojo("foofoo", "barbar"), @@ -108,13 +108,13 @@ public void encode() { } @Test - public void encodeError() { + void encodeError() { Mono input = Mono.error(new InputException()); testEncode(input, Pojo.class, step -> step.expectError(InputException.class).verify()); } @Test - public void encodeAsStream() { + void encodeAsStream() { Pojo pojo1 = new Pojo("foo", "bar"); Pojo pojo2 = new Pojo("foofoo", "barbar"); Pojo pojo3 = new Pojo("foofoofoo", "barbarbar"); diff --git a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2TokenizerTests.java b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2TokenizerTests.java index 2dfc5153cf67..8fde04fed7b6 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2TokenizerTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2TokenizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -54,7 +54,7 @@ * @author Rossen Stoyanchev * @author Juergen Hoeller */ -public class Jackson2TokenizerTests extends AbstractLeakCheckingTests { +class Jackson2TokenizerTests extends AbstractLeakCheckingTests { private JsonFactory jsonFactory; @@ -62,14 +62,14 @@ public class Jackson2TokenizerTests extends AbstractLeakCheckingTests { @BeforeEach - public void createParser() { + void createParser() { this.jsonFactory = new JsonFactory(); this.objectMapper = new ObjectMapper(this.jsonFactory); } @Test - public void doNotTokenizeArrayElements() { + void doNotTokenizeArrayElements() { testTokenize( singletonList("{\"foo\": \"foofoo\", \"bar\": \"barbar\"}"), singletonList("{\"foo\": \"foofoo\", \"bar\": \"barbar\"}"), false); @@ -118,7 +118,7 @@ public void doNotTokenizeArrayElements() { } @Test - public void tokenizeArrayElements() { + void tokenizeArrayElements() { testTokenize( singletonList("{\"foo\": \"foofoo\", \"bar\": \"barbar\"}"), singletonList("{\"foo\": \"foofoo\", \"bar\": \"barbar\"}"), true); @@ -251,7 +251,7 @@ private void testTokenize(List input, List output, boolean token } @Test - public void testLimit() { + void testLimit() { List source = asList( "[", "{", "\"id\":1,\"name\":\"Dan\"", "},", @@ -272,7 +272,7 @@ public void testLimit() { } @Test - public void testLimitTokenized() { + void testLimitTokenized() { List source = asList( "[", @@ -298,7 +298,7 @@ public void testLimitTokenized() { } @Test - public void errorInStream() { + void errorInStream() { DataBuffer buffer = stringBuffer("{\"id\":1,\"name\":"); Flux source = Flux.just(buffer).concatWith(Flux.error(new RuntimeException())); Flux result = Jackson2Tokenizer.tokenize(source, this.jsonFactory, this.objectMapper, true, @@ -321,7 +321,7 @@ public void jsonEOFExceptionIsWrappedAsDecodingError() { } @Test - public void useBigDecimalForFloats() { + void useBigDecimalForFloats() { Flux source = Flux.just(stringBuffer("1E+2")); Flux tokens = Jackson2Tokenizer.tokenize( source, this.jsonFactory, this.objectMapper, false, true, -1); @@ -344,7 +344,7 @@ public void useBigDecimalForFloats() { // gh-31747 @Test - public void compositeNettyBuffer() { + void compositeNettyBuffer() { ByteBufAllocator allocator = UnpooledByteBufAllocator.DEFAULT; ByteBuf firstByteBuf = allocator.buffer(); firstByteBuf.writeBytes("{\"foo\": \"foofoo\"".getBytes(StandardCharsets.UTF_8)); diff --git a/spring-web/src/test/java/org/springframework/http/codec/json/JacksonCsvEncoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/json/JacksonCsvEncoderTests.java index 9e4f90b4fc29..686aceb073df 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/json/JacksonCsvEncoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/json/JacksonCsvEncoderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -24,6 +24,7 @@ import com.fasterxml.jackson.dataformat.csv.CsvMapper; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; +import reactor.test.StepVerifier.LastStep; import org.springframework.core.ResolvableType; import org.springframework.core.testfixture.codec.AbstractEncoderTests; @@ -70,7 +71,7 @@ public void encode() throws Exception { // this test did not fail directly but logged a NullPointerException dropped by the reactive pipeline void encodeEmptyFlux() { Flux input = Flux.empty(); - testEncode(input, Pojo.class, step -> step.verifyComplete()); + testEncode(input, Pojo.class, LastStep::verifyComplete); } static class JacksonCsvEncoder extends AbstractJackson2Encoder { diff --git a/spring-web/src/test/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReaderTests.java b/spring-web/src/test/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReaderTests.java index 24c4af12f759..4c10a24e1d71 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReaderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -435,7 +435,6 @@ protected void hookOnNext(DataBuffer buffer) { @interface ParameterizedDefaultPartHttpMessageReaderTest { } - @SuppressWarnings("removal") static Stream messageReaders() { DefaultPartHttpMessageReader inMemory = new DefaultPartHttpMessageReader(); inMemory.setMaxInMemorySize(1000); diff --git a/spring-web/src/test/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriterTests.java b/spring-web/src/test/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriterTests.java index 7240dbc79273..841926d9684a 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriterTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriterTests.java @@ -56,7 +56,7 @@ * @author Sebastien Deleuze * @author Rossen Stoyanchev */ -public class MultipartHttpMessageWriterTests extends AbstractLeakCheckingTests { +class MultipartHttpMessageWriterTests extends AbstractLeakCheckingTests { private final MultipartHttpMessageWriter writer = new MultipartHttpMessageWriter(ClientCodecConfigurer.create().getWriters()); @@ -65,7 +65,7 @@ public class MultipartHttpMessageWriterTests extends AbstractLeakCheckingTests { @Test - public void canWrite() { + void canWrite() { assertThat(this.writer.canWrite( ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, Object.class), MediaType.MULTIPART_FORM_DATA)).isTrue(); @@ -88,7 +88,7 @@ public void canWrite() { } @Test - public void writeMultipartFormData() throws Exception { + void writeMultipartFormData() throws Exception { Resource logo = new ClassPathResource("/org/springframework/http/converter/logo.jpg"); Resource utf8 = new ClassPathResource("/org/springframework/http/converter/logo.jpg") { @Override diff --git a/spring-web/src/test/java/org/springframework/http/codec/multipart/PartEventHttpMessageReaderTests.java b/spring-web/src/test/java/org/springframework/http/codec/multipart/PartEventHttpMessageReaderTests.java index 67e1768ae8a4..11de6ab281a5 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/multipart/PartEventHttpMessageReaderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/multipart/PartEventHttpMessageReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -59,13 +59,13 @@ class PartEventHttpMessageReaderTests { private final PartEventHttpMessageReader reader = new PartEventHttpMessageReader(); @Test - public void canRead() { + void canRead() { assertThat(this.reader.canRead(forClass(PartEvent.class), MediaType.MULTIPART_FORM_DATA)).isTrue(); assertThat(this.reader.canRead(forClass(PartEvent.class), null)).isTrue(); } @Test - public void simple() { + void simple() { MockServerHttpRequest request = createRequest( new ClassPathResource("simple.multipart", getClass()), "simple-boundary"); @@ -79,7 +79,7 @@ public void simple() { } @Test - public void noHeaders() { + void noHeaders() { MockServerHttpRequest request = createRequest( new ClassPathResource("no-header.multipart", getClass()), "boundary"); Flux result = this.reader.read(forClass(PartEvent.class), request, emptyMap()); @@ -90,7 +90,7 @@ public void noHeaders() { } @Test - public void noEndBoundary() { + void noEndBoundary() { MockServerHttpRequest request = createRequest( new ClassPathResource("no-end-boundary.multipart", getClass()), "boundary"); @@ -102,7 +102,7 @@ public void noEndBoundary() { } @Test - public void garbage() { + void garbage() { MockServerHttpRequest request = createRequest( new ClassPathResource("garbage-1.multipart", getClass()), "boundary"); @@ -115,7 +115,7 @@ public void garbage() { @Test - public void noEndHeader() { + void noEndHeader() { MockServerHttpRequest request = createRequest( new ClassPathResource("no-end-header.multipart", getClass()), "boundary"); Flux result = this.reader.read(forClass(PartEvent.class), request, emptyMap()); @@ -126,7 +126,7 @@ public void noEndHeader() { } @Test - public void noEndBody() { + void noEndBody() { MockServerHttpRequest request = createRequest( new ClassPathResource("no-end-body.multipart", getClass()), "boundary"); Flux result = this.reader.read(forClass(PartEvent.class), request, emptyMap()); @@ -137,7 +137,7 @@ public void noEndBody() { } @Test - public void noBody() { + void noBody() { MockServerHttpRequest request = createRequest( new ClassPathResource("no-body.multipart", getClass()), "boundary"); Flux result = this.reader.read(forClass(PartEvent.class), request, emptyMap()); @@ -150,7 +150,7 @@ public void noBody() { @Test - public void cancel() { + void cancel() { MockServerHttpRequest request = createRequest( new ClassPathResource("simple.multipart", getClass()), "simple-boundary"); Flux result = this.reader.read(forClass(PartEvent.class), request, emptyMap()); @@ -164,7 +164,7 @@ public void cancel() { @Test - public void firefox() { + void firefox() { MockServerHttpRequest request = createRequest(new ClassPathResource("firefox.multipart", getClass()), "---------------------------18399284482060392383840973206"); @@ -186,7 +186,7 @@ public void firefox() { } @Test - public void chrome() { + void chrome() { MockServerHttpRequest request = createRequest(new ClassPathResource("chrome.multipart", getClass()), "----WebKitFormBoundaryEveBLvRT65n21fwU"); @@ -207,7 +207,7 @@ public void chrome() { } @Test - public void safari() { + void safari() { MockServerHttpRequest request = createRequest(new ClassPathResource("safari.multipart", getClass()), "----WebKitFormBoundaryG8fJ50opQOML0oGD"); @@ -275,7 +275,7 @@ void formPartTooLarge() { } @Test - public void utf8Headers() { + void utf8Headers() { MockServerHttpRequest request = createRequest( new ClassPathResource("utf8.multipart", getClass()), "\"simple-boundary\""); @@ -288,7 +288,7 @@ public void utf8Headers() { } @Test - public void exceedHeaderLimit() { + void exceedHeaderLimit() { Flux body = DataBufferUtils .readByteChannel((new ClassPathResource("files.multipart", getClass()))::readableChannel, bufferFactory, 282); diff --git a/spring-web/src/test/java/org/springframework/http/codec/multipart/PartEventHttpMessageWriterTests.java b/spring-web/src/test/java/org/springframework/http/codec/multipart/PartEventHttpMessageWriterTests.java index 32ac0b7a0c11..971a3543cfac 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/multipart/PartEventHttpMessageWriterTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/multipart/PartEventHttpMessageWriterTests.java @@ -43,7 +43,7 @@ * * @author Arjen Poutsma */ -public class PartEventHttpMessageWriterTests extends AbstractLeakCheckingTests { +class PartEventHttpMessageWriterTests extends AbstractLeakCheckingTests { private final PartEventHttpMessageWriter writer = new PartEventHttpMessageWriter(); @@ -51,7 +51,7 @@ public class PartEventHttpMessageWriterTests extends AbstractLeakCheckingTests { @Test - public void canWrite() { + void canWrite() { assertThat(this.writer.canWrite(ResolvableType.forClass(PartEvent.class), MediaType.MULTIPART_FORM_DATA)).isTrue(); assertThat(this.writer.canWrite(ResolvableType.forClass(FilePartEvent.class), MediaType.MULTIPART_FORM_DATA)).isTrue(); assertThat(this.writer.canWrite(ResolvableType.forClass(FormPartEvent.class), MediaType.MULTIPART_FORM_DATA)).isTrue(); diff --git a/spring-web/src/test/java/org/springframework/http/codec/multipart/PartHttpMessageWriterTests.java b/spring-web/src/test/java/org/springframework/http/codec/multipart/PartHttpMessageWriterTests.java index 9c0853b56d01..96cb8b2844ab 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/multipart/PartHttpMessageWriterTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/multipart/PartHttpMessageWriterTests.java @@ -43,7 +43,7 @@ * @author Rossen Stoyanchev * @since 5.3 */ -public class PartHttpMessageWriterTests extends AbstractLeakCheckingTests { +class PartHttpMessageWriterTests extends AbstractLeakCheckingTests { private final PartHttpMessageWriter writer = new PartHttpMessageWriter(); @@ -51,7 +51,7 @@ public class PartHttpMessageWriterTests extends AbstractLeakCheckingTests { @Test - public void canWrite() { + void canWrite() { assertThat(this.writer.canWrite(ResolvableType.forClass(Part.class), MediaType.MULTIPART_FORM_DATA)).isTrue(); assertThat(this.writer.canWrite(ResolvableType.forClass(Part.class), MediaType.MULTIPART_MIXED)).isTrue(); assertThat(this.writer.canWrite(ResolvableType.forClass(Part.class), MediaType.MULTIPART_RELATED)).isTrue(); diff --git a/spring-web/src/test/java/org/springframework/http/codec/protobuf/ProtobufDecoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/protobuf/ProtobufDecoderTests.java index 0db7ede2cea3..bb3336e5e1c1 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/protobuf/ProtobufDecoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/protobuf/ProtobufDecoderTests.java @@ -45,7 +45,7 @@ * * @author Sebastien Deleuze */ -public class ProtobufDecoderTests extends AbstractDecoderTests { +class ProtobufDecoderTests extends AbstractDecoderTests { private final SecondMsg secondMsg = SecondMsg.newBuilder().setBlah(123).build(); @@ -61,7 +61,7 @@ public ProtobufDecoderTests() { @Test - public void extensionRegistryNull() { + void extensionRegistryNull() { assertThatIllegalArgumentException().isThrownBy(() -> new ProtobufDecoder(null)); } @@ -86,7 +86,7 @@ public void decodeToMono() { } @Test - public void decodeChunksToMono() { + void decodeChunksToMono() { byte[] full = this.testMsg1.toByteArray(); byte[] chunk1 = Arrays.copyOfRange(full, 0, full.length / 2); byte[] chunk2 = Arrays.copyOfRange(full, chunk1.length, full.length); @@ -211,7 +211,7 @@ public void decodeMergedChunks() throws IOException { } @Test - public void exceedMaxSize() { + void exceedMaxSize() { this.decoder.setMaxMessageSize(1); Mono input = dataBuffer(this.testMsg1); diff --git a/spring-web/src/test/java/org/springframework/http/codec/protobuf/ProtobufEncoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/protobuf/ProtobufEncoderTests.java index b603ba045914..f24ff88370e6 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/protobuf/ProtobufEncoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/protobuf/ProtobufEncoderTests.java @@ -41,7 +41,7 @@ * * @author Sebastien Deleuze */ -public class ProtobufEncoderTests extends AbstractEncoderTests { +class ProtobufEncoderTests extends AbstractEncoderTests { private static final MimeType PROTOBUF_MIME_TYPE = new MimeType("application", "x-protobuf"); @@ -58,7 +58,7 @@ public ProtobufEncoderTests() { @Override @Test - public void canEncode() { + protected void canEncode() { assertThat(this.encoder.canEncode(forClass(Msg.class), null)).isTrue(); assertThat(this.encoder.canEncode(forClass(Msg.class), PROTOBUF_MIME_TYPE)).isTrue(); assertThat(this.encoder.canEncode(forClass(Msg.class), MediaType.APPLICATION_OCTET_STREAM)).isTrue(); @@ -68,7 +68,7 @@ public void canEncode() { @Override @Test - public void encode() { + protected void encode() { Mono input = Mono.just(this.msg1); testEncodeAll(input, Msg.class, step -> step @@ -88,7 +88,7 @@ public void encode() { } @Test - public void encodeStream() { + void encodeStream() { Flux input = Flux.just(this.msg1, this.msg2); testEncodeAll(input, Msg.class, step -> step diff --git a/spring-web/src/test/java/org/springframework/http/codec/support/ClientCodecConfigurerTests.java b/spring-web/src/test/java/org/springframework/http/codec/support/ClientCodecConfigurerTests.java index b5d77fdb5ada..59ee9c5496ad 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/support/ClientCodecConfigurerTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/support/ClientCodecConfigurerTests.java @@ -86,7 +86,7 @@ * * @author Rossen Stoyanchev */ -public class ClientCodecConfigurerTests { +class ClientCodecConfigurerTests { private final ClientCodecConfigurer configurer = new DefaultClientCodecConfigurer(); @@ -94,7 +94,7 @@ public class ClientCodecConfigurerTests { @Test - public void defaultReaders() { + void defaultReaders() { List> readers = this.configurer.getReaders(); assertThat(readers).hasSize(20); assertThat(getNextDecoder(readers).getClass()).isEqualTo(ByteArrayDecoder.class); @@ -121,7 +121,7 @@ public void defaultReaders() { } @Test - public void defaultWriters() { + void defaultWriters() { List> writers = this.configurer.getWriters(); assertThat(writers).hasSize(18); assertThat(getNextEncoder(writers).getClass()).isEqualTo(ByteArrayEncoder.class); @@ -145,7 +145,7 @@ public void defaultWriters() { } @Test - public void jackson2CodecCustomization() { + void jackson2CodecCustomization() { Jackson2JsonDecoder decoder = new Jackson2JsonDecoder(); Jackson2JsonEncoder encoder = new Jackson2JsonEncoder(); this.configurer.defaultCodecs().jackson2JsonDecoder(decoder); @@ -166,7 +166,7 @@ public void jackson2CodecCustomization() { } @Test - public void objectMapperCustomization() { + void objectMapperCustomization() { ObjectMapper objectMapper = new ObjectMapper(); this.configurer.defaultCodecs().configureDefaultCodec(codec -> { if (codec instanceof Jackson2CodecSupport) { @@ -188,7 +188,7 @@ public void objectMapperCustomization() { } @Test - public void maxInMemorySize() { + void maxInMemorySize() { int size = 99; this.configurer.defaultCodecs().maxInMemorySize(size); List> readers = this.configurer.getReaders(); @@ -220,7 +220,7 @@ public void maxInMemorySize() { } @Test - public void enableLoggingRequestDetails() { + void enableLoggingRequestDetails() { this.configurer.defaultCodecs().enableLoggingRequestDetails(true); List> writers = this.configurer.getWriters(); @@ -233,7 +233,7 @@ public void enableLoggingRequestDetails() { } @Test - public void clonedConfigurer() { + void clonedConfigurer() { ClientCodecConfigurer clone = this.configurer.clone(); Jackson2JsonDecoder jackson2Decoder = new Jackson2JsonDecoder(); @@ -269,7 +269,7 @@ public void cloneShouldNotDropMultipartCodecs() { } @Test - public void cloneShouldNotBeImpactedByChangesToOriginal() { + void cloneShouldNotBeImpactedByChangesToOriginal() { ClientCodecConfigurer clone = this.configurer.clone(); diff --git a/spring-web/src/test/java/org/springframework/http/codec/support/ServerCodecConfigurerTests.java b/spring-web/src/test/java/org/springframework/http/codec/support/ServerCodecConfigurerTests.java index b696504c6b11..1915ff3e866b 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/support/ServerCodecConfigurerTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/support/ServerCodecConfigurerTests.java @@ -84,7 +84,7 @@ * * @author Rossen Stoyanchev */ -public class ServerCodecConfigurerTests { +class ServerCodecConfigurerTests { private final ServerCodecConfigurer configurer = new DefaultServerCodecConfigurer(); @@ -92,7 +92,7 @@ public class ServerCodecConfigurerTests { @Test - public void defaultReaders() { + void defaultReaders() { List> readers = this.configurer.getReaders(); assertThat(readers).hasSize(19); assertThat(getNextDecoder(readers).getClass()).isEqualTo(ByteArrayDecoder.class); @@ -117,7 +117,7 @@ public void defaultReaders() { } @Test - public void defaultWriters() { + void defaultWriters() { List> writers = this.configurer.getWriters(); assertThat(writers).hasSize(19); assertThat(getNextEncoder(writers).getClass()).isEqualTo(ByteArrayEncoder.class); @@ -142,7 +142,7 @@ public void defaultWriters() { } @Test - public void jackson2EncoderOverride() { + void jackson2EncoderOverride() { Jackson2JsonDecoder decoder = new Jackson2JsonDecoder(); Jackson2JsonEncoder encoder = new Jackson2JsonEncoder(); this.configurer.defaultCodecs().jackson2JsonDecoder(decoder); @@ -159,7 +159,7 @@ public void jackson2EncoderOverride() { } @Test - public void maxInMemorySize() { + void maxInMemorySize() { int size = 99; this.configurer.defaultCodecs().maxInMemorySize(size); @@ -190,7 +190,7 @@ public void maxInMemorySize() { } @Test - public void maxInMemorySizeWithCustomCodecs() { + void maxInMemorySizeWithCustomCodecs() { int size = 99; this.configurer.defaultCodecs().maxInMemorySize(size); @@ -212,7 +212,7 @@ public void maxInMemorySizeWithCustomCodecs() { } @Test - public void enableRequestLoggingDetails() { + void enableRequestLoggingDetails() { this.configurer.defaultCodecs().enableLoggingRequestDetails(true); List> readers = this.configurer.getReaders(); @@ -226,7 +226,7 @@ public void enableRequestLoggingDetails() { } @Test - public void enableRequestLoggingDetailsWithCustomCodecs() { + void enableRequestLoggingDetailsWithCustomCodecs() { this.configurer.registerDefaults(false); this.configurer.defaultCodecs().enableLoggingRequestDetails(true); @@ -241,7 +241,7 @@ public void enableRequestLoggingDetailsWithCustomCodecs() { } @Test - public void cloneConfigurer() { + void cloneConfigurer() { ServerCodecConfigurer clone = this.configurer.clone(); MultipartHttpMessageReader reader = new MultipartHttpMessageReader(new DefaultPartHttpMessageReader()); diff --git a/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2HelperTests.java b/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2HelperTests.java index 75b0a2a9fe87..658a1c73d94b 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2HelperTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2HelperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -37,7 +37,7 @@ class Jaxb2HelperTests { @Test - public void toExpectedQName() { + void toExpectedQName() { assertThat(Jaxb2Helper.toQNames(Pojo.class)).containsExactly(new QName("pojo")); assertThat(Jaxb2Helper.toQNames(TypePojo.class)).containsExactly(new QName("pojo")); diff --git a/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlDecoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlDecoderTests.java index 8c3a2cf8bc62..eced23b5dd1e 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlDecoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlDecoderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -46,7 +46,7 @@ /** * @author Sebastien Deleuze */ -public class Jaxb2XmlDecoderTests extends AbstractLeakCheckingTests { +class Jaxb2XmlDecoderTests extends AbstractLeakCheckingTests { private static final String POJO_ROOT = "" + "" + @@ -76,7 +76,7 @@ public class Jaxb2XmlDecoderTests extends AbstractLeakCheckingTests { @Test - public void canDecode() { + void canDecode() { assertThat(this.decoder.canDecode(ResolvableType.forClass(Pojo.class), MediaType.APPLICATION_XML)).isTrue(); assertThat(this.decoder.canDecode(ResolvableType.forClass(Pojo.class), @@ -90,7 +90,7 @@ public void canDecode() { } @Test - public void splitOneBranches() { + void splitOneBranches() { Flux xmlEvents = this.xmlEventDecoder.decode(toDataBufferMono(POJO_ROOT), null, null, HINTS); Flux> result = Jaxb2Helper.split(xmlEvents, Set.of(new QName("pojo"))); @@ -111,7 +111,7 @@ public void splitOneBranches() { } @Test - public void splitMultipleBranches() { + void splitMultipleBranches() { Flux xmlEvents = this.xmlEventDecoder.decode(toDataBufferMono(POJO_CHILD), null, null, HINTS); Flux> result = Jaxb2Helper.split(xmlEvents, Set.of(new QName("pojo"))); @@ -159,7 +159,7 @@ private static void assertCharacters(XMLEvent event, String expectedData) { } @Test - public void decodeSingleXmlRootElement() { + void decodeSingleXmlRootElement() { Mono source = toDataBufferMono(POJO_ROOT); Mono output = this.decoder.decodeToMono(source, ResolvableType.forClass(Pojo.class), null, HINTS); @@ -170,7 +170,7 @@ public void decodeSingleXmlRootElement() { } @Test - public void decodeSingleXmlTypeElement() { + void decodeSingleXmlTypeElement() { Mono source = toDataBufferMono(POJO_ROOT); Mono output = this.decoder.decodeToMono(source, ResolvableType.forClass(TypePojo.class), null, HINTS); @@ -181,7 +181,7 @@ public void decodeSingleXmlTypeElement() { } @Test - public void decodeMultipleXmlRootElement() { + void decodeMultipleXmlRootElement() { Mono source = toDataBufferMono(POJO_CHILD); Flux output = this.decoder.decode(source, ResolvableType.forClass(Pojo.class), null, HINTS); @@ -193,7 +193,7 @@ public void decodeMultipleXmlRootElement() { } @Test - public void decodeMultipleXmlTypeElement() { + void decodeMultipleXmlTypeElement() { Mono source = toDataBufferMono(POJO_CHILD); Flux output = this.decoder.decode(source, ResolvableType.forClass(TypePojo.class), null, HINTS); @@ -205,7 +205,7 @@ public void decodeMultipleXmlTypeElement() { } @Test - public void decodeXmlSeeAlso() { + void decodeXmlSeeAlso() { Mono source = toDataBufferMono(POJO_CHILD); Flux output = this.decoder.decode(source, ResolvableType.forClass(Parent.class), null, HINTS); @@ -218,7 +218,7 @@ public void decodeXmlSeeAlso() { } @Test - public void decodeError() { + void decodeError() { Flux source = Flux.concat( toDataBufferMono(""), Flux.error(new RuntimeException())); @@ -240,7 +240,7 @@ public void decodeErrorWithXmlNotWellFormed() { } @Test - public void decodeNonUtf8() { + void decodeNonUtf8() { String xml = "" + "føø" + "bär" + diff --git a/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlEncoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlEncoderTests.java index e134ed57cea3..6cde0d5bca80 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlEncoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlEncoderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -46,7 +46,7 @@ * @author Sebastien Deleuze * @author Arjen Poutsma */ -public class Jaxb2XmlEncoderTests extends AbstractEncoderTests { +class Jaxb2XmlEncoderTests extends AbstractEncoderTests { public Jaxb2XmlEncoderTests() { super(new Jaxb2XmlEncoder()); @@ -54,7 +54,7 @@ public Jaxb2XmlEncoderTests() { @Override @Test - public void canEncode() { + protected void canEncode() { assertThat(this.encoder.canEncode(forClass(Pojo.class), MediaType.APPLICATION_XML)).isTrue(); assertThat(this.encoder.canEncode(forClass(Pojo.class), MediaType.TEXT_XML)).isTrue(); assertThat(this.encoder.canEncode(forClass(Pojo.class), new MediaType("application", "foo+xml"))).isTrue(); @@ -69,7 +69,7 @@ public void canEncode() { @Override @Test - public void encode() { + protected void encode() { Mono input = Mono.just(new Pojo("foofoo", "barbar")); testEncode(input, Pojo.class, step -> step @@ -80,7 +80,7 @@ public void encode() { } @Test - public void encodeJaxbElement() { + void encodeJaxbElement() { Mono> input = Mono.just(new JAXBElement<>(new QName("baz"), Pojo.class, new Pojo("foofoo", "barbar"))); @@ -92,13 +92,13 @@ public void encodeJaxbElement() { } @Test - public void encodeError() { + void encodeError() { Flux input = Flux.error(RuntimeException::new); testEncode(input, Pojo.class, step -> step.expectError(RuntimeException.class).verify()); } @Test - public void encodeElementsWithCommonType() { + void encodeElementsWithCommonType() { Mono input = Mono.just(new Container()); testEncode(input, Pojo.class, step -> step diff --git a/spring-web/src/test/java/org/springframework/http/codec/xml/XmlEventDecoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/xml/XmlEventDecoderTests.java index cf48d090fa48..354970da2707 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/xml/XmlEventDecoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/xml/XmlEventDecoderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -35,7 +35,7 @@ /** * @author Arjen Poutsma */ -public class XmlEventDecoderTests extends AbstractLeakCheckingTests { +class XmlEventDecoderTests extends AbstractLeakCheckingTests { private static final String XML = "" + "" + @@ -43,11 +43,11 @@ public class XmlEventDecoderTests extends AbstractLeakCheckingTests { "barbar" + ""; - private XmlEventDecoder decoder = new XmlEventDecoder(); + private final XmlEventDecoder decoder = new XmlEventDecoder(); @Test - public void toXMLEventsAalto() { + void toXMLEventsAalto() { Flux events = this.decoder.decode(stringBufferMono(XML), null, null, Collections.emptyMap()); @@ -67,7 +67,7 @@ public void toXMLEventsAalto() { } @Test - public void toXMLEventsNonAalto() { + void toXMLEventsNonAalto() { decoder.useAalto = false; Flux events = @@ -89,7 +89,7 @@ public void toXMLEventsNonAalto() { } @Test - public void toXMLEventsWithLimit() { + void toXMLEventsWithLimit() { this.decoder.setMaxInMemorySize(6); @@ -111,7 +111,7 @@ public void toXMLEventsWithLimit() { } @Test - public void decodeErrorAalto() { + void decodeErrorAalto() { Flux source = Flux.concat( stringBufferMono(""), Flux.error(new RuntimeException())); @@ -127,7 +127,7 @@ public void decodeErrorAalto() { } @Test - public void decodeErrorNonAalto() { + void decodeErrorNonAalto() { decoder.useAalto = false; Flux source = Flux.concat( diff --git a/spring-web/src/test/java/org/springframework/http/converter/ByteArrayHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/ByteArrayHttpMessageConverterTests.java index a701f9db3703..846bde65d52a 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/ByteArrayHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/ByteArrayHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -28,30 +28,30 @@ import static org.assertj.core.api.Assertions.assertThat; /** @author Arjen Poutsma */ -public class ByteArrayHttpMessageConverterTests { +class ByteArrayHttpMessageConverterTests { private ByteArrayHttpMessageConverter converter; @BeforeEach - public void setUp() { + void setUp() { converter = new ByteArrayHttpMessageConverter(); } @Test - public void canRead() { + void canRead() { assertThat(converter.canRead(byte[].class, new MediaType("application", "octet-stream"))).isTrue(); } @Test - public void canWrite() { + void canWrite() { assertThat(converter.canWrite(byte[].class, new MediaType("application", "octet-stream"))).isTrue(); assertThat(converter.canWrite(byte[].class, MediaType.ALL)).isTrue(); } @Test - public void read() throws IOException { + void read() throws IOException { byte[] body = new byte[]{0x1, 0x2}; MockHttpInputMessage inputMessage = new MockHttpInputMessage(body); inputMessage.getHeaders().setContentType(new MediaType("application", "octet-stream")); @@ -60,7 +60,7 @@ public void read() throws IOException { } @Test - public void readWithContentLengthHeaderSet() throws IOException { + void readWithContentLengthHeaderSet() throws IOException { byte[] body = new byte[]{0x1, 0x2, 0x3, 0x4, 0x5}; MockHttpInputMessage inputMessage = new MockHttpInputMessage(body); inputMessage.getHeaders().setContentType(new MediaType("application", "octet-stream")); @@ -70,7 +70,7 @@ public void readWithContentLengthHeaderSet() throws IOException { } @Test - public void write() throws IOException { + void write() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); byte[] body = new byte[]{0x1, 0x2}; converter.write(body, null, outputMessage); @@ -80,7 +80,7 @@ public void write() throws IOException { } @Test - public void repeatableWrites() throws IOException { + void repeatableWrites() throws IOException { MockHttpOutputMessage outputMessage1 = new MockHttpOutputMessage(); byte[] body = new byte[]{0x1, 0x2}; assertThat(converter.supportsRepeatableWrites(body)).isTrue(); diff --git a/spring-web/src/test/java/org/springframework/http/converter/FormHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/FormHttpMessageConverterTests.java index 62de0aeeadd2..cf1c9c1a8da8 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/FormHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/FormHttpMessageConverterTests.java @@ -64,13 +64,13 @@ * @author Sam Brannen * @author Sebastien Deleuze */ -public class FormHttpMessageConverterTests { +class FormHttpMessageConverterTests { private final FormHttpMessageConverter converter = new AllEncompassingFormHttpMessageConverter(); @Test - public void canRead() { + void canRead() { assertCanRead(MultiValueMap.class, null); assertCanRead(APPLICATION_FORM_URLENCODED); @@ -79,7 +79,7 @@ public void canRead() { } @Test - public void cannotReadMultipart() { + void cannotReadMultipart() { // Without custom multipart types supported asssertCannotReadMultipart(); @@ -88,7 +88,7 @@ public void cannotReadMultipart() { } @Test - public void canWrite() { + void canWrite() { assertCanWrite(APPLICATION_FORM_URLENCODED); assertCanWrite(MULTIPART_FORM_DATA); assertCanWrite(MULTIPART_MIXED); @@ -99,7 +99,7 @@ public void canWrite() { } @Test - public void setSupportedMediaTypes() { + void setSupportedMediaTypes() { this.converter.setSupportedMediaTypes(List.of(MULTIPART_FORM_DATA)); assertCannotWrite(MULTIPART_MIXED); @@ -108,7 +108,7 @@ public void setSupportedMediaTypes() { } @Test - public void addSupportedMediaTypes() { + void addSupportedMediaTypes() { this.converter.setSupportedMediaTypes(List.of(MULTIPART_FORM_DATA)); assertCannotWrite(MULTIPART_MIXED); @@ -117,7 +117,7 @@ public void addSupportedMediaTypes() { } @Test - public void readForm() throws Exception { + void readForm() throws Exception { String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3"; MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.ISO_8859_1)); inputMessage.getHeaders().setContentType( @@ -127,14 +127,12 @@ public void readForm() throws Exception { assertThat(result).as("Invalid result").hasSize(3); assertThat(result.getFirst("name 1")).as("Invalid result").isEqualTo("value 1"); List values = result.get("name 2"); - assertThat(values).as("Invalid result").hasSize(2); - assertThat(values).element(0).as("Invalid result").isEqualTo("value 2+1"); - assertThat(values).element(1).as("Invalid result").isEqualTo("value 2+2"); + assertThat(values).as("Invalid result").containsExactly("value 2+1", "value 2+2"); assertThat(result.getFirst("name 3")).as("Invalid result").isNull(); } @Test - public void writeForm() throws IOException { + void writeForm() throws IOException { MultiValueMap body = new LinkedMultiValueMap<>(); body.set("name 1", "value 1"); body.add("name 2", "value 2+1"); @@ -152,7 +150,7 @@ public void writeForm() throws IOException { } @Test - public void writeMultipart() throws Exception { + void writeMultipart() throws Exception { MultiValueMap parts = new LinkedMultiValueMap<>(); parts.add("name 1", "value 1"); @@ -230,7 +228,7 @@ public String getFilename() { } @Test - public void writeMultipartWithSourceHttpMessageConverter() throws Exception { + void writeMultipartWithSourceHttpMessageConverter() throws Exception { converter.setPartConverters(List.of( new StringHttpMessageConverter(), @@ -356,7 +354,7 @@ public void writeMultipartOrder() throws Exception { } @Test - public void writeMultipartCharset() throws Exception { + void writeMultipartCharset() throws Exception { MultiValueMap parts = new LinkedMultiValueMap<>(); Resource logo = new ClassPathResource("/org/springframework/http/converter/logo.jpg"); parts.add("logo", logo); @@ -436,7 +434,7 @@ public String getContentType() { } @Override - public InputStream getInputStream() throws IOException { + public InputStream getInputStream() { return new ByteArrayInputStream(body); } diff --git a/spring-web/src/test/java/org/springframework/http/converter/HttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/HttpMessageConverterTests.java index b149b729d8d7..7bdc10f9e9a3 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/HttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/HttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -16,8 +16,6 @@ package org.springframework.http.converter; -import java.io.IOException; - import org.junit.jupiter.api.Test; import org.springframework.http.HttpInputMessage; @@ -32,11 +30,11 @@ * @author Arjen Poutsma * @author Rossen Stoyanchev */ -public class HttpMessageConverterTests { +class HttpMessageConverterTests { @Test - public void canRead() { + void canRead() { MediaType mediaType = new MediaType("foo", "bar"); HttpMessageConverter converter = new MyHttpMessageConverter<>(mediaType); @@ -46,7 +44,7 @@ public void canRead() { } @Test - public void canReadWithWildcardSubtype() { + void canReadWithWildcardSubtype() { MediaType mediaType = new MediaType("foo"); HttpMessageConverter converter = new MyHttpMessageConverter<>(mediaType); @@ -56,7 +54,7 @@ public void canReadWithWildcardSubtype() { } @Test - public void canWrite() { + void canWrite() { MediaType mediaType = new MediaType("foo", "bar"); HttpMessageConverter converter = new MyHttpMessageConverter<>(mediaType); @@ -66,7 +64,7 @@ public void canWrite() { } @Test - public void canWriteWithWildcardInSupportedSubtype() { + void canWriteWithWildcardInSupportedSubtype() { MediaType mediaType = new MediaType("foo"); HttpMessageConverter converter = new MyHttpMessageConverter<>(mediaType); @@ -89,13 +87,13 @@ protected boolean supports(Class clazz) { @Override protected T readInternal(Class clazz, HttpInputMessage inputMessage) - throws IOException, HttpMessageNotReadableException { + throws HttpMessageNotReadableException { throw new AssertionError("Not expected"); } @Override protected void writeInternal(T t, HttpOutputMessage outputMessage) - throws IOException, HttpMessageNotWritableException { + throws HttpMessageNotWritableException { throw new AssertionError("Not expected"); } } diff --git a/spring-web/src/test/java/org/springframework/http/converter/ObjectToStringHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/ObjectToStringHttpMessageConverterTests.java index 6e6780fba732..a54caff27c24 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/ObjectToStringHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/ObjectToStringHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -43,7 +43,7 @@ * @author Dmitry Katsubo * @author Rossen Stoyanchev */ -public class ObjectToStringHttpMessageConverterTests { +class ObjectToStringHttpMessageConverterTests { private ObjectToStringHttpMessageConverter converter; @@ -53,7 +53,7 @@ public class ObjectToStringHttpMessageConverterTests { @BeforeEach - public void setup() { + void setup() { ConversionService conversionService = new DefaultConversionService(); this.converter = new ObjectToStringHttpMessageConverter(conversionService); @@ -63,7 +63,7 @@ public void setup() { @Test - public void canRead() { + void canRead() { assertThat(this.converter.canRead(Math.class, null)).isFalse(); assertThat(this.converter.canRead(Resource.class, null)).isFalse(); @@ -76,7 +76,7 @@ public void canRead() { } @Test - public void canWrite() { + void canWrite() { assertThat(this.converter.canWrite(Math.class, null)).isFalse(); assertThat(this.converter.canWrite(Resource.class, null)).isFalse(); @@ -91,14 +91,14 @@ public void canWrite() { } @Test - public void defaultCharset() throws IOException { + void defaultCharset() throws IOException { this.converter.write(5, null, response); assertThat(servletResponse.getCharacterEncoding()).isEqualTo("ISO-8859-1"); } @Test - public void defaultCharsetModified() throws IOException { + void defaultCharsetModified() throws IOException { ConversionService cs = new DefaultConversionService(); ObjectToStringHttpMessageConverter converter = new ObjectToStringHttpMessageConverter(cs, StandardCharsets.UTF_16); converter.write((byte) 31, null, this.response); @@ -107,7 +107,7 @@ public void defaultCharsetModified() throws IOException { } @Test - public void writeAcceptCharset() throws IOException { + void writeAcceptCharset() throws IOException { this.converter.setWriteAcceptCharset(true); this.converter.write(new Date(), null, this.response); @@ -115,7 +115,7 @@ public void writeAcceptCharset() throws IOException { } @Test - public void writeAcceptCharsetTurnedOff() throws IOException { + void writeAcceptCharsetTurnedOff() throws IOException { this.converter.setWriteAcceptCharset(false); this.converter.write(new Date(), null, this.response); @@ -123,7 +123,7 @@ public void writeAcceptCharsetTurnedOff() throws IOException { } @Test - public void read() throws IOException { + void read() throws IOException { Short shortValue = (short) 781; MockHttpServletRequest request = new MockHttpServletRequest(); request.setContentType(MediaType.TEXT_PLAIN_VALUE); @@ -134,19 +134,19 @@ public void read() throws IOException { request = new MockHttpServletRequest(); request.setContentType(MediaType.TEXT_PLAIN_VALUE); request.setCharacterEncoding("UTF-16"); - request.setContent(floatValue.toString().getBytes("UTF-16")); + request.setContent(floatValue.toString().getBytes(StandardCharsets.UTF_16)); assertThat(this.converter.read(Float.class, new ServletServerHttpRequest(request))).isEqualTo(floatValue); Long longValue = 55819182821331L; request = new MockHttpServletRequest(); request.setContentType(MediaType.TEXT_PLAIN_VALUE); request.setCharacterEncoding("UTF-8"); - request.setContent(longValue.toString().getBytes("UTF-8")); + request.setContent(longValue.toString().getBytes(StandardCharsets.UTF_8)); assertThat(this.converter.read(Long.class, new ServletServerHttpRequest(request))).isEqualTo(longValue); } @Test - public void write() throws IOException { + void write() throws IOException { this.converter.write((byte) -8, null, this.response); assertThat(this.servletResponse.getCharacterEncoding()).isEqualTo("ISO-8859-1"); @@ -156,7 +156,7 @@ public void write() throws IOException { } @Test - public void writeUtf16() throws IOException { + void writeUtf16() throws IOException { MediaType contentType = new MediaType("text", "plain", StandardCharsets.UTF_16); this.converter.write(958, contentType, this.response); @@ -168,7 +168,7 @@ public void writeUtf16() throws IOException { } @Test - public void testConversionServiceRequired() { + void testConversionServiceRequired() { assertThatIllegalArgumentException().isThrownBy(() -> new ObjectToStringHttpMessageConverter(null)); } diff --git a/spring-web/src/test/java/org/springframework/http/converter/ResourceHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/ResourceHttpMessageConverterTests.java index 942918dfd3ec..596d791a6823 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/ResourceHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/ResourceHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -45,24 +45,24 @@ * @author Kazuki Shimizu * @author Brian Clozel */ -public class ResourceHttpMessageConverterTests { +class ResourceHttpMessageConverterTests { private final ResourceHttpMessageConverter converter = new ResourceHttpMessageConverter(); @Test - public void canReadResource() { + void canReadResource() { assertThat(converter.canRead(Resource.class, new MediaType("application", "octet-stream"))).isTrue(); } @Test - public void canWriteResource() { + void canWriteResource() { assertThat(converter.canWrite(Resource.class, new MediaType("application", "octet-stream"))).isTrue(); assertThat(converter.canWrite(Resource.class, MediaType.ALL)).isTrue(); } @Test - public void shouldReadImageResource() throws IOException { + void shouldReadImageResource() throws IOException { byte[] body = FileCopyUtils.copyToByteArray(getClass().getResourceAsStream("logo.jpg")); MockHttpInputMessage inputMessage = new MockHttpInputMessage(body); inputMessage.getHeaders().setContentType(MediaType.IMAGE_JPEG); @@ -101,7 +101,7 @@ public void shouldNotReadInputStreamResource() throws IOException { } @Test - public void shouldWriteImageResource() throws IOException { + void shouldWriteImageResource() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); Resource body = new ClassPathResource("logo.jpg", getClass()); converter.write(body, null, outputMessage); diff --git a/spring-web/src/test/java/org/springframework/http/converter/ResourceRegionHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/ResourceRegionHttpMessageConverterTests.java index 03523b6708b2..e538f9013cf0 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/ResourceRegionHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/ResourceRegionHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -44,12 +44,12 @@ * * @author Brian Clozel */ -public class ResourceRegionHttpMessageConverterTests { +class ResourceRegionHttpMessageConverterTests { private final ResourceRegionHttpMessageConverter converter = new ResourceRegionHttpMessageConverter(); @Test - public void canReadResource() { + void canReadResource() { assertThat(converter.canRead(Resource.class, MediaType.APPLICATION_OCTET_STREAM)).isFalse(); assertThat(converter.canRead(Resource.class, MediaType.ALL)).isFalse(); assertThat(converter.canRead(List.class, MediaType.APPLICATION_OCTET_STREAM)).isFalse(); @@ -57,14 +57,14 @@ public void canReadResource() { } @Test - public void canWriteResource() { + void canWriteResource() { assertThat(converter.canWrite(ResourceRegion.class, null, MediaType.APPLICATION_OCTET_STREAM)).isTrue(); assertThat(converter.canWrite(ResourceRegion.class, null, MediaType.ALL)).isTrue(); assertThat(converter.canWrite(Object.class, null, MediaType.ALL)).isFalse(); } @Test - public void canWriteResourceCollection() { + void canWriteResourceCollection() { Type resourceRegionList = new ParameterizedTypeReference>() {}.getType(); assertThat(converter.canWrite(resourceRegionList, null, MediaType.APPLICATION_OCTET_STREAM)).isTrue(); assertThat(converter.canWrite(resourceRegionList, null, MediaType.ALL)).isTrue(); @@ -76,7 +76,7 @@ public void canWriteResourceCollection() { } @Test - public void shouldWritePartialContentByteRange() throws Exception { + void shouldWritePartialContentByteRange() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); Resource body = new ClassPathResource("byterangeresource.txt", getClass()); ResourceRegion region = HttpRange.createByteRange(0, 5).toResourceRegion(body); @@ -85,13 +85,12 @@ public void shouldWritePartialContentByteRange() throws Exception { HttpHeaders headers = outputMessage.getHeaders(); assertThat(headers.getContentType()).isEqualTo(MediaType.TEXT_PLAIN); assertThat(headers.getContentLength()).isEqualTo(6L); - assertThat(headers.get(HttpHeaders.CONTENT_RANGE)).hasSize(1); - assertThat(headers.get(HttpHeaders.CONTENT_RANGE)).element(0).isEqualTo("bytes 0-5/39"); + assertThat(headers.get(HttpHeaders.CONTENT_RANGE)).containsExactly("bytes 0-5/39"); assertThat(outputMessage.getBodyAsString(StandardCharsets.UTF_8)).isEqualTo("Spring"); } @Test - public void shouldWritePartialContentByteRangeNoEnd() throws Exception { + void shouldWritePartialContentByteRangeNoEnd() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); Resource body = new ClassPathResource("byterangeresource.txt", getClass()); ResourceRegion region = HttpRange.createByteRange(7).toResourceRegion(body); @@ -100,13 +99,12 @@ public void shouldWritePartialContentByteRangeNoEnd() throws Exception { HttpHeaders headers = outputMessage.getHeaders(); assertThat(headers.getContentType()).isEqualTo(MediaType.TEXT_PLAIN); assertThat(headers.getContentLength()).isEqualTo(32L); - assertThat(headers.get(HttpHeaders.CONTENT_RANGE)).hasSize(1); - assertThat(headers.get(HttpHeaders.CONTENT_RANGE)).element(0).isEqualTo("bytes 7-38/39"); + assertThat(headers.get(HttpHeaders.CONTENT_RANGE)).containsExactly("bytes 7-38/39"); assertThat(outputMessage.getBodyAsString(StandardCharsets.UTF_8)).isEqualTo("Framework test resource content."); } @Test - public void partialContentMultipleByteRanges() throws Exception { + void partialContentMultipleByteRanges() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); Resource body = new ClassPathResource("byterangeresource.txt", getClass()); List rangeList = HttpRange.parseRanges("bytes=0-5,7-15,17-20,22-38"); @@ -145,7 +143,7 @@ public void partialContentMultipleByteRanges() throws Exception { } @Test - public void partialContentMultipleByteRangesInRandomOrderAndOverlapping() throws Exception { + void partialContentMultipleByteRangesInRandomOrderAndOverlapping() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); Resource body = new ClassPathResource("byterangeresource.txt", getClass()); List rangeList = HttpRange.parseRanges("bytes=7-15,0-5,17-20,20-29"); diff --git a/spring-web/src/test/java/org/springframework/http/converter/StringHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/StringHttpMessageConverterTests.java index 2885aec9a9e0..6240b1e464da 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/StringHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/StringHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -172,7 +172,7 @@ void writeWithWildCardMediaType() throws IOException { } @Test - public void repeatableWrites() throws IOException { + void repeatableWrites() throws IOException { MockHttpOutputMessage outputMessage1 = new MockHttpOutputMessage(); String body = "Hello World"; assertThat(converter.supportsRepeatableWrites(body)).isTrue(); diff --git a/spring-web/src/test/java/org/springframework/http/converter/feed/AtomFeedHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/feed/AtomFeedHttpMessageConverterTests.java index 6df1114dd242..b9309583e446 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/feed/AtomFeedHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/feed/AtomFeedHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -42,7 +42,7 @@ /** * @author Arjen Poutsma */ -public class AtomFeedHttpMessageConverterTests { +class AtomFeedHttpMessageConverterTests { private static final MediaType ATOM_XML_UTF8 = new MediaType(MediaType.APPLICATION_ATOM_XML, StandardCharsets.UTF_8); @@ -52,25 +52,25 @@ public class AtomFeedHttpMessageConverterTests { @BeforeEach - public void setUp() { + void setUp() { converter = new AtomFeedHttpMessageConverter(); } @Test - public void canRead() { + void canRead() { assertThat(converter.canRead(Feed.class, MediaType.APPLICATION_ATOM_XML)).isTrue(); assertThat(converter.canRead(Feed.class, ATOM_XML_UTF8)).isTrue(); } @Test - public void canWrite() { + void canWrite() { assertThat(converter.canWrite(Feed.class, MediaType.APPLICATION_ATOM_XML)).isTrue(); assertThat(converter.canWrite(Feed.class, ATOM_XML_UTF8)).isTrue(); } @Test - public void read() throws IOException { + void read() throws IOException { InputStream inputStream = getClass().getResourceAsStream("atom.xml"); MockHttpInputMessage inputMessage = new MockHttpInputMessage(inputStream); inputMessage.getHeaders().setContentType(ATOM_XML_UTF8); @@ -90,7 +90,7 @@ public void read() throws IOException { } @Test - public void write() throws IOException { + void write() throws IOException { Feed feed = new Feed("atom_1.0"); feed.setTitle("title"); @@ -122,7 +122,7 @@ public void write() throws IOException { } @Test - public void writeOtherCharset() throws IOException { + void writeOtherCharset() throws IOException { Feed feed = new Feed("atom_1.0"); feed.setTitle("title"); String encoding = "ISO-8859-1"; @@ -137,7 +137,7 @@ public void writeOtherCharset() throws IOException { } @Test - public void writeOtherContentTypeParameters() throws IOException { + void writeOtherContentTypeParameters() throws IOException { MockHttpOutputMessage message = new MockHttpOutputMessage(); MediaType contentType = new MediaType("application", "atom+xml", singletonMap("type", "feed")); converter.write(new Feed("atom_1.0"), contentType, message); diff --git a/spring-web/src/test/java/org/springframework/http/converter/feed/RssChannelHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/feed/RssChannelHttpMessageConverterTests.java index feb24f197a06..5d0d7788e037 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/feed/RssChannelHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/feed/RssChannelHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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,7 +38,7 @@ /** * @author Arjen Poutsma */ -public class RssChannelHttpMessageConverterTests { +class RssChannelHttpMessageConverterTests { private static final MediaType RSS_XML_UTF8 = new MediaType(MediaType.APPLICATION_RSS_XML, StandardCharsets.UTF_8); @@ -46,7 +46,7 @@ public class RssChannelHttpMessageConverterTests { @Test - public void canReadAndWrite() { + void canReadAndWrite() { assertThat(converter.canRead(Channel.class, MediaType.APPLICATION_RSS_XML)).isTrue(); assertThat(converter.canRead(Channel.class, RSS_XML_UTF8)).isTrue(); @@ -55,7 +55,7 @@ public void canReadAndWrite() { } @Test - public void read() throws IOException { + void read() throws IOException { InputStream inputStream = getClass().getResourceAsStream("rss.xml"); MockHttpInputMessage inputMessage = new MockHttpInputMessage(inputStream); inputMessage.getHeaders().setContentType(RSS_XML_UTF8); @@ -75,7 +75,7 @@ public void read() throws IOException { } @Test - public void write() throws IOException { + void write() throws IOException { Channel channel = new Channel("rss_2.0"); channel.setTitle("title"); channel.setLink("https://example.com"); @@ -108,7 +108,7 @@ public void write() throws IOException { } @Test - public void writeOtherCharset() throws IOException { + void writeOtherCharset() throws IOException { Channel channel = new Channel("rss_2.0"); channel.setTitle("title"); channel.setLink("https://example.com"); @@ -129,7 +129,7 @@ public void writeOtherCharset() throws IOException { } @Test - public void writeOtherContentTypeParameters() throws IOException { + void writeOtherContentTypeParameters() throws IOException { Channel channel = new Channel("rss_2.0"); channel.setTitle("title"); channel.setLink("https://example.com"); diff --git a/spring-web/src/test/java/org/springframework/http/converter/json/GsonFactoryBeanTests.java b/spring-web/src/test/java/org/springframework/http/converter/json/GsonFactoryBeanTests.java index 79f1b44a0ff2..1f8e8baef82e 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/json/GsonFactoryBeanTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/json/GsonFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -37,7 +37,7 @@ class GsonFactoryBeanTests { @Test - void serializeNulls() throws Exception { + void serializeNulls() { this.factory.setSerializeNulls(true); this.factory.afterPropertiesSet(); Gson gson = this.factory.getObject(); @@ -47,7 +47,7 @@ void serializeNulls() throws Exception { } @Test - void serializeNullsFalse() throws Exception { + void serializeNullsFalse() { this.factory.setSerializeNulls(false); this.factory.afterPropertiesSet(); Gson gson = this.factory.getObject(); @@ -57,7 +57,7 @@ void serializeNullsFalse() throws Exception { } @Test - void prettyPrinting() throws Exception { + void prettyPrinting() { this.factory.setPrettyPrinting(true); this.factory.afterPropertiesSet(); Gson gson = this.factory.getObject(); @@ -67,7 +67,7 @@ void prettyPrinting() throws Exception { } @Test - void prettyPrintingFalse() throws Exception { + void prettyPrintingFalse() { this.factory.setPrettyPrinting(false); this.factory.afterPropertiesSet(); Gson gson = this.factory.getObject(); @@ -78,7 +78,7 @@ void prettyPrintingFalse() throws Exception { } @Test - void disableHtmlEscaping() throws Exception { + void disableHtmlEscaping() { this.factory.setDisableHtmlEscaping(true); this.factory.afterPropertiesSet(); Gson gson = this.factory.getObject(); @@ -89,7 +89,7 @@ void disableHtmlEscaping() throws Exception { } @Test - void disableHtmlEscapingFalse() throws Exception { + void disableHtmlEscapingFalse() { this.factory.setDisableHtmlEscaping(false); this.factory.afterPropertiesSet(); Gson gson = this.factory.getObject(); @@ -100,7 +100,7 @@ void disableHtmlEscapingFalse() throws Exception { } @Test - void customizeDateFormatPattern() throws Exception { + void customizeDateFormatPattern() { this.factory.setDateFormatPattern(DATE_FORMAT); this.factory.afterPropertiesSet(); Gson gson = this.factory.getObject(); @@ -117,7 +117,7 @@ void customizeDateFormatPattern() throws Exception { } @Test - void customizeDateFormatNone() throws Exception { + void customizeDateFormatNone() { this.factory.afterPropertiesSet(); Gson gson = this.factory.getObject(); DateBean bean = new DateBean(); @@ -134,7 +134,7 @@ void customizeDateFormatNone() throws Exception { } @Test - void base64EncodeByteArrays() throws Exception { + void base64EncodeByteArrays() { this.factory.setBase64EncodeByteArrays(true); this.factory.afterPropertiesSet(); Gson gson = this.factory.getObject(); @@ -145,7 +145,7 @@ void base64EncodeByteArrays() throws Exception { } @Test - void base64EncodeByteArraysDisableHtmlEscaping() throws Exception { + void base64EncodeByteArraysDisableHtmlEscaping() { this.factory.setBase64EncodeByteArrays(true); this.factory.setDisableHtmlEscaping(true); this.factory.afterPropertiesSet(); @@ -157,7 +157,7 @@ void base64EncodeByteArraysDisableHtmlEscaping() throws Exception { } @Test - void base64EncodeByteArraysFalse() throws Exception { + void base64EncodeByteArraysFalse() { this.factory.setBase64EncodeByteArrays(false); this.factory.afterPropertiesSet(); Gson gson = this.factory.getObject(); diff --git a/spring-web/src/test/java/org/springframework/http/converter/json/GsonHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/json/GsonHttpMessageConverterTests.java index 33c095af69c6..038491a1962b 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/json/GsonHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/json/GsonHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -45,31 +45,31 @@ * @author Roy Clarkson * @author Juergen Hoeller */ -public class GsonHttpMessageConverterTests { +class GsonHttpMessageConverterTests { private final GsonHttpMessageConverter converter = new GsonHttpMessageConverter(); @Test - public void canRead() { + void canRead() { assertThat(this.converter.canRead(MyBean.class, new MediaType("application", "json"))).isTrue(); assertThat(this.converter.canRead(Map.class, new MediaType("application", "json"))).isTrue(); } @Test - public void canWrite() { + void canWrite() { assertThat(this.converter.canWrite(MyBean.class, new MediaType("application", "json"))).isTrue(); assertThat(this.converter.canWrite(Map.class, new MediaType("application", "json"))).isTrue(); } @Test - public void canReadAndWriteMicroformats() { + void canReadAndWriteMicroformats() { assertThat(this.converter.canRead(MyBean.class, new MediaType("application", "vnd.test-micro-type+json"))).isTrue(); assertThat(this.converter.canWrite(MyBean.class, new MediaType("application", "vnd.test-micro-type+json"))).isTrue(); } @Test - public void readTyped() throws IOException { + void readTyped() throws IOException { String body = "{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," + "\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}"; MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8)); @@ -90,7 +90,7 @@ public void readTyped() throws IOException { public void readUntyped() throws IOException { String body = "{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," + "\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}"; - MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8")); + MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(new MediaType("application", "json")); HashMap result = (HashMap) this.converter.read(HashMap.class, inputMessage); assertThat(result.get("string")).isEqualTo("Foo"); @@ -113,7 +113,7 @@ public void readUntyped() throws IOException { } @Test - public void write() throws IOException { + void write() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MyBean body = new MyBean(); body.setString("Foo"); @@ -136,7 +136,7 @@ public void write() throws IOException { } @Test - public void writeWithBaseType() throws IOException { + void writeWithBaseType() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MyBean body = new MyBean(); body.setString("Foo"); @@ -159,7 +159,7 @@ public void writeWithBaseType() throws IOException { } @Test - public void writeUTF16() throws IOException { + void writeUTF16() throws IOException { MediaType contentType = new MediaType("application", "json", StandardCharsets.UTF_16BE); MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); String body = "H\u00e9llo W\u00f6rld"; @@ -169,7 +169,7 @@ public void writeUTF16() throws IOException { } @Test - public void readInvalidJson() throws IOException { + void readInvalidJson() { String body = "FooBar"; MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(new MediaType("application", "json")); @@ -259,7 +259,7 @@ public void writeParameterizedBaseType() throws Exception { } @Test - public void prefixJson() throws IOException { + void prefixJson() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); this.converter.setPrefixJson(true); this.converter.writeInternal("foo", null, outputMessage); @@ -267,7 +267,7 @@ public void prefixJson() throws IOException { } @Test - public void prefixJsonCustom() throws IOException { + void prefixJsonCustom() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); this.converter.setJsonPrefix(")))"); this.converter.writeInternal("foo", null, outputMessage); diff --git a/spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilderTests.java b/spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilderTests.java index fc86500b4103..a6fc0b36f683 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilderTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -17,7 +17,7 @@ package org.springframework.http.converter.json; import java.io.IOException; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; import java.text.SimpleDateFormat; @@ -278,21 +278,25 @@ int getY() { } @Test - void wellKnownModules() throws JsonProcessingException, UnsupportedEncodingException { + void wellKnownModules() throws JsonProcessingException { ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build(); Path file = Paths.get("foo"); - assertThat(new String(objectMapper.writeValueAsBytes(file), "UTF-8")).endsWith("foo\""); + assertThat(new String(objectMapper.writeValueAsBytes(file), StandardCharsets.UTF_8)) + .endsWith("foo\""); Optional optional = Optional.of("test"); - assertThat(new String(objectMapper.writeValueAsBytes(optional), "UTF-8")).isEqualTo("\"test\""); + assertThat(new String(objectMapper.writeValueAsBytes(optional), StandardCharsets.UTF_8)) + .isEqualTo("\"test\""); - assertThatCode(() -> objectMapper.readValue("{\"x\":1,\"y\":2}", ParameterModuleDto.class)).doesNotThrowAnyException(); + assertThatCode(() -> objectMapper.readValue("{\"x\":1,\"y\":2}", ParameterModuleDto.class)) + .doesNotThrowAnyException(); // Kotlin module IntRange range = new IntRange(1, 3); - assertThat(new String(objectMapper.writeValueAsBytes(range), "UTF-8")).isEqualTo("{\"start\":1,\"end\":3}"); + assertThat(new String(objectMapper.writeValueAsBytes(range), StandardCharsets.UTF_8)) + .isEqualTo("{\"start\":1,\"end\":3}"); } @Test // gh-22576 @@ -744,7 +748,7 @@ static class Bar {} static class FooSerializer extends JsonSerializer { @Override - public void serialize(Foo value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + public void serialize(Foo value, JsonGenerator gen, SerializerProvider serializers) { } @Override @@ -755,7 +759,7 @@ public Class handledType() { static class BarSerializer extends JsonSerializer { @Override - public void serialize(Bar value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + public void serialize(Bar value, JsonGenerator gen, SerializerProvider serializers) { } @Override public Class handledType() { diff --git a/spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBeanTests.java b/spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBeanTests.java index ffacc08c6624..5e3a55c01876 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBeanTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -83,13 +83,13 @@ public class Jackson2ObjectMapperFactoryBeanTests { @Test - public void unknownFeature() { + void unknownFeature() { this.factory.setFeaturesToEnable(Boolean.TRUE); assertThatIllegalArgumentException().isThrownBy(this.factory::afterPropertiesSet); } @Test - public void booleanSetters() { + void booleanSetters() { this.factory.setAutoDetectFields(false); this.factory.setAutoDetectGettersSetters(false); this.factory.setDefaultViewInclusion(false); @@ -110,34 +110,34 @@ public void booleanSetters() { } @Test - public void defaultSerializationInclusion() { + void defaultSerializationInclusion() { this.factory.afterPropertiesSet(); assertThat(this.factory.getObject().getSerializationConfig().getSerializationInclusion()).isSameAs(Include.ALWAYS); } @Test - public void nonNullSerializationInclusion() { + void nonNullSerializationInclusion() { this.factory.setSerializationInclusion(Include.NON_NULL); this.factory.afterPropertiesSet(); assertThat(this.factory.getObject().getSerializationConfig().getSerializationInclusion()).isSameAs(Include.NON_NULL); } @Test - public void nonDefaultSerializationInclusion() { + void nonDefaultSerializationInclusion() { this.factory.setSerializationInclusion(Include.NON_DEFAULT); this.factory.afterPropertiesSet(); assertThat(this.factory.getObject().getSerializationConfig().getSerializationInclusion()).isSameAs(Include.NON_DEFAULT); } @Test - public void nonEmptySerializationInclusion() { + void nonEmptySerializationInclusion() { this.factory.setSerializationInclusion(Include.NON_EMPTY); this.factory.afterPropertiesSet(); assertThat(this.factory.getObject().getSerializationConfig().getSerializationInclusion()).isSameAs(Include.NON_EMPTY); } @Test - public void setDateFormat() { + void setDateFormat() { this.factory.setDateFormat(this.dateFormat); this.factory.afterPropertiesSet(); @@ -146,7 +146,7 @@ public void setDateFormat() { } @Test - public void setSimpleDateFormat() { + void setSimpleDateFormat() { this.factory.setSimpleDateFormat(DATE_FORMAT); this.factory.afterPropertiesSet(); @@ -155,7 +155,7 @@ public void setSimpleDateFormat() { } @Test - public void setLocale() { + void setLocale() { this.factory.setLocale(Locale.FRENCH); this.factory.afterPropertiesSet(); @@ -164,7 +164,7 @@ public void setLocale() { } @Test - public void setTimeZone() { + void setTimeZone() { TimeZone timeZone = TimeZone.getTimeZone("Europe/Paris"); this.factory.setTimeZone(timeZone); @@ -175,7 +175,7 @@ public void setTimeZone() { } @Test - public void setTimeZoneWithInvalidZoneId() { + void setTimeZoneWithInvalidZoneId() { this.factory.setTimeZone(TimeZone.getTimeZone("bogusZoneId")); this.factory.afterPropertiesSet(); @@ -185,7 +185,7 @@ public void setTimeZoneWithInvalidZoneId() { } @Test - public void setModules() { + void setModules() { NumberSerializer serializer = new NumberSerializer(Integer.class); SimpleModule module = new SimpleModule(); module.addSerializer(Integer.class, serializer); @@ -199,7 +199,7 @@ public void setModules() { } @Test - public void simpleSetup() { + void simpleSetup() { this.factory.afterPropertiesSet(); assertThat(this.factory.getObject()).isNotNull(); @@ -208,7 +208,7 @@ public void simpleSetup() { } @Test - public void undefinedObjectType() { + void undefinedObjectType() { assertThat(this.factory.getObjectType()).isNull(); } @@ -221,7 +221,7 @@ private static DeserializerFactoryConfig getDeserializerFactoryConfig(ObjectMapp } @Test - public void propertyNamingStrategy() { + void propertyNamingStrategy() { PropertyNamingStrategy strategy = new PropertyNamingStrategy.SnakeCaseStrategy(); this.factory.setPropertyNamingStrategy(strategy); this.factory.afterPropertiesSet(); @@ -231,7 +231,7 @@ public void propertyNamingStrategy() { } @Test - public void setMixIns() { + void setMixIns() { Class target = String.class; Class mixinSource = Object.class; Map, Class> mixIns = new HashMap<>(); @@ -248,7 +248,7 @@ public void setMixIns() { } @Test - public void setFilters() throws JsonProcessingException { + void setFilters() throws JsonProcessingException { this.factory.setFilters(new SimpleFilterProvider().setFailOnUnknownId(false)); this.factory.afterPropertiesSet(); ObjectMapper objectMapper = this.factory.getObject(); @@ -260,7 +260,7 @@ public void setFilters() throws JsonProcessingException { } @Test - public void completeSetup() { + void completeSetup() { NopAnnotationIntrospector annotationIntrospector = NopAnnotationIntrospector.instance; ObjectMapper objectMapper = new ObjectMapper(); @@ -324,7 +324,7 @@ public void completeSetup() { } @Test - public void setObjectMapper() { + void setObjectMapper() { this.factory.setObjectMapper(new XmlMapper()); this.factory.afterPropertiesSet(); @@ -334,7 +334,7 @@ public void setObjectMapper() { } @Test - public void setCreateXmlMapper() { + void setCreateXmlMapper() { this.factory.setCreateXmlMapper(true); this.factory.afterPropertiesSet(); diff --git a/spring-web/src/test/java/org/springframework/http/converter/json/JsonbHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/json/JsonbHttpMessageConverterTests.java index 871338a9128e..3fb7545b5768 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/json/JsonbHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/json/JsonbHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -45,31 +45,31 @@ * @author Juergen Hoeller * @since 5.0 */ -public class JsonbHttpMessageConverterTests { +class JsonbHttpMessageConverterTests { private final JsonbHttpMessageConverter converter = new JsonbHttpMessageConverter(); @Test - public void canRead() { + void canRead() { assertThat(this.converter.canRead(MyBean.class, new MediaType("application", "json"))).isTrue(); assertThat(this.converter.canRead(Map.class, new MediaType("application", "json"))).isTrue(); } @Test - public void canWrite() { + void canWrite() { assertThat(this.converter.canWrite(MyBean.class, new MediaType("application", "json"))).isTrue(); assertThat(this.converter.canWrite(Map.class, new MediaType("application", "json"))).isTrue(); } @Test - public void canReadAndWriteMicroformats() { + void canReadAndWriteMicroformats() { assertThat(this.converter.canRead(MyBean.class, new MediaType("application", "vnd.test-micro-type+json"))).isTrue(); assertThat(this.converter.canWrite(MyBean.class, new MediaType("application", "vnd.test-micro-type+json"))).isTrue(); } @Test - public void readTyped() throws IOException { + void readTyped() throws IOException { String body = "{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," + "\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}"; MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8)); @@ -113,7 +113,7 @@ public void readUntyped() throws IOException { } @Test - public void write() throws IOException { + void write() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MyBean body = new MyBean(); body.setString("Foo"); @@ -136,7 +136,7 @@ public void write() throws IOException { } @Test - public void writeWithBaseType() throws IOException { + void writeWithBaseType() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MyBean body = new MyBean(); body.setString("Foo"); @@ -159,7 +159,7 @@ public void writeWithBaseType() throws IOException { } @Test - public void writeUTF16() throws IOException { + void writeUTF16() throws IOException { MediaType contentType = new MediaType("application", "json", StandardCharsets.UTF_16BE); MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); String body = "H\u00e9llo W\u00f6rld"; @@ -169,7 +169,7 @@ public void writeUTF16() throws IOException { } @Test - public void readInvalidJson() { + void readInvalidJson() { String body = "FooBar"; MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(new MediaType("application", "json")); @@ -258,7 +258,7 @@ public void writeParameterizedBaseType() throws Exception { } @Test - public void prefixJson() throws IOException { + void prefixJson() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); this.converter.setPrefixJson(true); this.converter.writeInternal("foo", null, outputMessage); @@ -266,7 +266,7 @@ public void prefixJson() throws IOException { } @Test - public void prefixJsonCustom() throws IOException { + void prefixJsonCustom() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); this.converter.setJsonPrefix(")))"); this.converter.writeInternal("foo", null, outputMessage); diff --git a/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java index 2caed086497a..15f0139bc0cf 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -61,7 +61,7 @@ * @author Sebastien Deleuze * @author Juergen Hoeller */ -public class MappingJackson2HttpMessageConverterTests { +class MappingJackson2HttpMessageConverterTests { protected static final String NEWLINE_SYSTEM_PROPERTY = System.lineSeparator(); @@ -69,7 +69,7 @@ public class MappingJackson2HttpMessageConverterTests { @Test - public void canRead() { + void canRead() { assertThat(converter.canRead(MyBean.class, new MediaType("application", "json"))).isTrue(); assertThat(converter.canRead(Map.class, new MediaType("application", "json"))).isTrue(); assertThat(converter.canRead(MyBean.class, new MediaType("application", "json", StandardCharsets.UTF_8))).isTrue(); @@ -78,7 +78,7 @@ public void canRead() { } @Test - public void canReadWithObjectMapperRegistrationForType() { + void canReadWithObjectMapperRegistrationForType() { MediaType halJsonMediaType = MediaType.parseMediaType("application/hal+json"); MediaType halFormsJsonMediaType = MediaType.parseMediaType("application/prs.hal-forms+json"); @@ -99,7 +99,7 @@ public void canReadWithObjectMapperRegistrationForType() { } @Test - public void canWrite() { + void canWrite() { assertThat(converter.canWrite(MyBean.class, new MediaType("application", "json"))).isTrue(); assertThat(converter.canWrite(Map.class, new MediaType("application", "json"))).isTrue(); assertThat(converter.canWrite(MyBean.class, new MediaType("application", "json", StandardCharsets.UTF_8))).isTrue(); @@ -114,7 +114,7 @@ public void canReadAndWriteMicroformats() { } @Test - public void getSupportedMediaTypes() { + void getSupportedMediaTypes() { MediaType[] defaultMediaTypes = {MediaType.APPLICATION_JSON, MediaType.parseMediaType("application/*+json")}; assertThat(converter.getSupportedMediaTypes()).containsExactly(defaultMediaTypes); assertThat(converter.getSupportedMediaTypes(MyBean.class)).containsExactly(defaultMediaTypes); @@ -130,7 +130,7 @@ public void getSupportedMediaTypes() { } @Test - public void readTyped() throws IOException { + void readTyped() throws IOException { String body = "{" + "\"bytes\":\"AQI=\"," + "\"array\":[\"Foo\",\"Bar\"]," + @@ -174,7 +174,7 @@ public void readUntyped() throws IOException { } @Test - public void write() throws IOException { + void write() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MyBean body = new MyBean(); body.setString("Foo"); @@ -196,7 +196,7 @@ public void write() throws IOException { } @Test - public void writeWithBaseType() throws IOException { + void writeWithBaseType() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MyBean body = new MyBean(); body.setString("Foo"); @@ -218,7 +218,7 @@ public void writeWithBaseType() throws IOException { } @Test - public void writeUTF16() throws IOException { + void writeUTF16() throws IOException { MediaType contentType = new MediaType("application", "json", StandardCharsets.UTF_16BE); MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); String body = "H\u00e9llo W\u00f6rld"; @@ -228,7 +228,7 @@ public void writeUTF16() throws IOException { } @Test - public void readInvalidJson() throws IOException { + void readInvalidJson() { String body = "FooBar"; MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(new MediaType("application", "json")); @@ -237,7 +237,7 @@ public void readInvalidJson() throws IOException { } @Test - public void readValidJsonWithUnknownProperty() throws IOException { + void readValidJsonWithUnknownProperty() throws IOException { String body = "{\"string\":\"string\",\"unknownProperty\":\"value\"}"; MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(new MediaType("application", "json")); @@ -349,7 +349,7 @@ public void writeParameterizedBaseType() throws Exception { // gh-24498 @Test - public void writeOptional() throws IOException { + void writeOptional() throws IOException { ParameterizedTypeReference> optionalParent = new ParameterizedTypeReference<>() {}; Optional result = Optional.of(new Impl1()); MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); @@ -360,7 +360,7 @@ public void writeOptional() throws IOException { } @Test - public void prettyPrint() throws Exception { + void prettyPrint() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); PrettyPrintBean bean = new PrettyPrintBean(); bean.setName("Jason"); @@ -374,7 +374,7 @@ public void prettyPrint() throws Exception { } @Test - public void prettyPrintWithSse() throws Exception { + void prettyPrintWithSse() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); outputMessage.getHeaders().setContentType(MediaType.TEXT_EVENT_STREAM); PrettyPrintBean bean = new PrettyPrintBean(); @@ -388,7 +388,7 @@ public void prettyPrintWithSse() throws Exception { } @Test - public void prefixJson() throws Exception { + void prefixJson() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); this.converter.setPrefixJson(true); this.converter.writeInternal("foo", null, outputMessage); @@ -397,7 +397,7 @@ public void prefixJson() throws Exception { } @Test - public void prefixJsonCustom() throws Exception { + void prefixJsonCustom() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); this.converter.setJsonPrefix(")))"); this.converter.writeInternal("foo", null, outputMessage); @@ -406,7 +406,7 @@ public void prefixJsonCustom() throws Exception { } @Test - public void fieldLevelJsonView() throws Exception { + void fieldLevelJsonView() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); JacksonViewBean bean = new JacksonViewBean(); bean.setWithView1("with"); @@ -424,7 +424,7 @@ public void fieldLevelJsonView() throws Exception { } @Test - public void classLevelJsonView() throws Exception { + void classLevelJsonView() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); JacksonViewBean bean = new JacksonViewBean(); bean.setWithView1("with"); @@ -442,7 +442,7 @@ public void classLevelJsonView() throws Exception { } @Test - public void filters() throws Exception { + void filters() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); JacksonFilteredBean bean = new JacksonFilteredBean(); bean.setProperty1("value"); @@ -533,7 +533,6 @@ public void readAscii() throws Exception { } @Test - @SuppressWarnings("unchecked") public void writeAscii() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); Map body = new HashMap<>(); @@ -548,7 +547,7 @@ public void writeAscii() throws Exception { } @Test - public void readWithCustomized() throws IOException { + void readWithCustomized() throws IOException { MappingJackson2HttpMessageConverterWithCustomization customizedConverter = new MappingJackson2HttpMessageConverterWithCustomization(); String body = "{\"property\":\"Value1\"}"; @@ -565,7 +564,7 @@ public void readWithCustomized() throws IOException { } @Test - public void writeWithCustomized() throws IOException { + void writeWithCustomized() throws IOException { MappingJackson2HttpMessageConverterWithCustomization customizedConverter = new MappingJackson2HttpMessageConverterWithCustomization(); MockHttpOutputMessage outputMessage1 = new MockHttpOutputMessage(); @@ -581,7 +580,7 @@ public void writeWithCustomized() throws IOException { } @Test - public void repeatableWrites() throws IOException { + void repeatableWrites() throws IOException { MockHttpOutputMessage outputMessage1 = new MockHttpOutputMessage(); MyBean body = new MyBean(); body.setString("Foo"); @@ -807,7 +806,7 @@ public String toString() { @JsonTypeInfo(use = JsonTypeInfo.Id.NAME) @JsonSubTypes(value = {@JsonSubTypes.Type(value = Impl1.class), @JsonSubTypes.Type(value = Impl2.class)}) - public static interface MyParent { + public interface MyParent { } public static class Impl1 implements MyParent { diff --git a/spring-web/src/test/java/org/springframework/http/converter/json/SpringHandlerInstantiatorTests.java b/spring-web/src/test/java/org/springframework/http/converter/json/SpringHandlerInstantiatorTests.java index f5f1021369fd..3c9a9b4e5b2b 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/json/SpringHandlerInstantiatorTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/json/SpringHandlerInstantiatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -61,7 +61,7 @@ * * @author Sebastien Deleuze */ -public class SpringHandlerInstantiatorTests { +class SpringHandlerInstantiatorTests { private SpringHandlerInstantiator instantiator; @@ -69,7 +69,7 @@ public class SpringHandlerInstantiatorTests { @BeforeEach - public void setup() { + void setup() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); @@ -81,21 +81,21 @@ public void setup() { @Test - public void autowiredSerializer() throws JsonProcessingException { + void autowiredSerializer() throws JsonProcessingException { User user = new User("bob"); String json = this.objectMapper.writeValueAsString(user); assertThat(json).isEqualTo("{\"username\":\"BOB\"}"); } @Test - public void autowiredDeserializer() throws IOException { + void autowiredDeserializer() throws IOException { String json = "{\"username\":\"bob\"}"; User user = this.objectMapper.readValue(json, User.class); assertThat(user.getUsername()).isEqualTo("BOB"); } @Test - public void autowiredKeyDeserializer() throws IOException { + void autowiredKeyDeserializer() throws IOException { String json = "{\"credentials\":{\"bob\":\"admin\"}}"; SecurityRegistry registry = this.objectMapper.readValue(json, SecurityRegistry.class); assertThat(registry.getCredentials()).containsKey("BOB"); @@ -103,13 +103,13 @@ public void autowiredKeyDeserializer() throws IOException { } @Test - public void applicationContextAwaretypeResolverBuilder() throws JsonProcessingException { + void applicationContextAwaretypeResolverBuilder() throws JsonProcessingException { this.objectMapper.writeValueAsString(new Group()); assertThat(CustomTypeResolverBuilder.isAutowiredFiledInitialized).isTrue(); } @Test - public void applicationContextAwareTypeIdResolver() throws JsonProcessingException { + void applicationContextAwareTypeIdResolver() throws JsonProcessingException { this.objectMapper.writeValueAsString(new Group()); assertThat(CustomTypeIdResolver.isAutowiredFiledInitialized).isTrue(); } @@ -151,7 +151,7 @@ public static class UpperCaseKeyDeserializer extends KeyDeserializer { private Capitalizer capitalizer; @Override - public Object deserializeKey(String key, DeserializationContext context) throws IOException { + public Object deserializeKey(String key, DeserializationContext context) { return this.capitalizer.capitalize(key); } } diff --git a/spring-web/src/test/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverterTests.java index 3c9a1713e660..fe5f0d95f323 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -126,7 +126,7 @@ void writeJsonWithGoogleProtobuf() throws IOException { } @Test - void defaultContentType() throws Exception { + void defaultContentType() { assertThat(this.converter.getDefaultContentType(this.testMsg)) .isEqualTo(ProtobufHttpMessageConverter.PROTOBUF); } diff --git a/spring-web/src/test/java/org/springframework/http/converter/protobuf/ProtobufJsonFormatHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/protobuf/ProtobufJsonFormatHttpMessageConverterTests.java index 9a651cad5e6a..33e2b8008448 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/protobuf/ProtobufJsonFormatHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/protobuf/ProtobufJsonFormatHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -36,7 +36,7 @@ * @author Juergen Hoeller * @author Sebastien Deleuze */ -public class ProtobufJsonFormatHttpMessageConverterTests { +class ProtobufJsonFormatHttpMessageConverterTests { private final ProtobufHttpMessageConverter converter = new ProtobufJsonFormatHttpMessageConverter( JsonFormat.parser(), JsonFormat.printer()); @@ -45,7 +45,7 @@ public class ProtobufJsonFormatHttpMessageConverterTests { @Test - public void canRead() { + void canRead() { assertThat(this.converter.canRead(Msg.class, null)).isTrue(); assertThat(this.converter.canRead(Msg.class, ProtobufHttpMessageConverter.PROTOBUF)).isTrue(); assertThat(this.converter.canRead(Msg.class, MediaType.APPLICATION_JSON)).isTrue(); @@ -53,7 +53,7 @@ public void canRead() { } @Test - public void canWrite() { + void canWrite() { assertThat(this.converter.canWrite(Msg.class, null)).isTrue(); assertThat(this.converter.canWrite(Msg.class, ProtobufHttpMessageConverter.PROTOBUF)).isTrue(); assertThat(this.converter.canWrite(Msg.class, MediaType.APPLICATION_JSON)).isTrue(); @@ -61,7 +61,7 @@ public void canWrite() { } @Test - public void read() throws IOException { + void read() throws IOException { byte[] body = this.testMsg.toByteArray(); MockHttpInputMessage inputMessage = new MockHttpInputMessage(body); inputMessage.getHeaders().setContentType(ProtobufHttpMessageConverter.PROTOBUF); @@ -70,7 +70,7 @@ public void read() throws IOException { } @Test - public void readNoContentType() throws IOException { + void readNoContentType() throws IOException { byte[] body = this.testMsg.toByteArray(); MockHttpInputMessage inputMessage = new MockHttpInputMessage(body); Message result = this.converter.read(Msg.class, inputMessage); @@ -78,7 +78,7 @@ public void readNoContentType() throws IOException { } @Test - public void write() throws IOException { + void write() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MediaType contentType = ProtobufHttpMessageConverter.PROTOBUF; this.converter.write(this.testMsg, contentType, outputMessage); @@ -96,12 +96,12 @@ public void write() throws IOException { } @Test - public void defaultContentType() throws Exception { + void defaultContentType() { assertThat(this.converter.getDefaultContentType(this.testMsg)).isEqualTo(ProtobufHttpMessageConverter.PROTOBUF); } @Test - public void getContentLength() throws Exception { + void getContentLength() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MediaType contentType = ProtobufHttpMessageConverter.PROTOBUF; this.converter.write(this.testMsg, contentType, outputMessage); diff --git a/spring-web/src/test/java/org/springframework/http/converter/smile/MappingJackson2SmileHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/smile/MappingJackson2SmileHttpMessageConverterTests.java index ad57f7d69071..340b8af24c92 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/smile/MappingJackson2SmileHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/smile/MappingJackson2SmileHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -34,28 +34,28 @@ * * @author Sebastien Deleuze */ -public class MappingJackson2SmileHttpMessageConverterTests { +class MappingJackson2SmileHttpMessageConverterTests { private final MappingJackson2SmileHttpMessageConverter converter = new MappingJackson2SmileHttpMessageConverter(); private final ObjectMapper mapper = new ObjectMapper(new SmileFactory()); @Test - public void canRead() { + void canRead() { assertThat(converter.canRead(MyBean.class, new MediaType("application", "x-jackson-smile"))).isTrue(); assertThat(converter.canRead(MyBean.class, new MediaType("application", "json"))).isFalse(); assertThat(converter.canRead(MyBean.class, new MediaType("application", "xml"))).isFalse(); } @Test - public void canWrite() { + void canWrite() { assertThat(converter.canWrite(MyBean.class, new MediaType("application", "x-jackson-smile"))).isTrue(); assertThat(converter.canWrite(MyBean.class, new MediaType("application", "json"))).isFalse(); assertThat(converter.canWrite(MyBean.class, new MediaType("application", "xml"))).isFalse(); } @Test - public void read() throws IOException { + void read() throws IOException { MyBean body = new MyBean(); body.setString("Foo"); body.setNumber(42); @@ -76,7 +76,7 @@ public void read() throws IOException { } @Test - public void write() throws IOException { + void write() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MyBean body = new MyBean(); body.setString("Foo"); diff --git a/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java index e817023264ad..19c277a9b7d5 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -47,7 +47,7 @@ * @author Arjen Poutsma * @author Rossen Stoyanchev */ -public class Jaxb2CollectionHttpMessageConverterTests { +class Jaxb2CollectionHttpMessageConverterTests { private Jaxb2CollectionHttpMessageConverter converter; @@ -61,7 +61,7 @@ public class Jaxb2CollectionHttpMessageConverterTests { @BeforeEach - public void setup() { + void setup() { converter = new Jaxb2CollectionHttpMessageConverter>(); rootElementListType = new ParameterizedTypeReference>() {}.getType(); rootElementSetType = new ParameterizedTypeReference>() {}.getType(); @@ -71,7 +71,7 @@ public void setup() { @Test - public void canRead() { + void canRead() { assertThat(converter.canRead(rootElementListType, null, null)).isTrue(); assertThat(converter.canRead(rootElementSetType, null, null)).isTrue(); assertThat(converter.canRead(typeSetType, null, null)).isTrue(); @@ -179,7 +179,7 @@ protected XMLInputFactory createXmlInputFactory() { } @Test - public void testXmlBomb() throws Exception { + void testXmlBomb() { // https://en.wikipedia.org/wiki/Billion_laughs // https://msdn.microsoft.com/en-us/magazine/ee335713.aspx String content = """ @@ -218,7 +218,7 @@ public RootElement(String s) { @XmlElement public TestType type = new TestType(); - @XmlElement(required=false) + @XmlElement(required = false) public String external; @Override diff --git a/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2RootElementHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2RootElementHttpMessageConverterTests.java index 04af0f70c300..a54aeb779464 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2RootElementHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2RootElementHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -55,7 +55,7 @@ * @author Sebastien Deleuze * @author Rossen Stoyanchev */ -public class Jaxb2RootElementHttpMessageConverterTests { +class Jaxb2RootElementHttpMessageConverterTests { private Jaxb2RootElementHttpMessageConverter converter; @@ -65,7 +65,7 @@ public class Jaxb2RootElementHttpMessageConverterTests { @BeforeEach - public void setup() { + void setup() { converter = new Jaxb2RootElementHttpMessageConverter(); rootElement = new RootElement(); DefaultAopProxyFactory proxyFactory = new DefaultAopProxyFactory(); @@ -78,7 +78,7 @@ public void setup() { @Test - public void canRead() { + void canRead() { assertThat(converter.canRead(RootElement.class, null)) .as("Converter does not support reading @XmlRootElement").isTrue(); assertThat(converter.canRead(Type.class, null)) @@ -86,7 +86,7 @@ public void canRead() { } @Test - public void canWrite() { + void canWrite() { assertThat(converter.canWrite(RootElement.class, null)) .as("Converter does not support writing @XmlRootElement").isTrue(); assertThat(converter.canWrite(RootElementSubclass.class, null)) @@ -98,7 +98,7 @@ public void canWrite() { } @Test - public void readXmlRootElement() throws Exception { + void readXmlRootElement() throws Exception { byte[] body = "".getBytes(StandardCharsets.UTF_8); MockHttpInputMessage inputMessage = new MockHttpInputMessage(body); RootElement result = (RootElement) converter.read(RootElement.class, inputMessage); @@ -106,7 +106,7 @@ public void readXmlRootElement() throws Exception { } @Test - public void readXmlRootElementSubclass() throws Exception { + void readXmlRootElementSubclass() throws Exception { byte[] body = "".getBytes(StandardCharsets.UTF_8); MockHttpInputMessage inputMessage = new MockHttpInputMessage(body); RootElementSubclass result = (RootElementSubclass) converter.read(RootElementSubclass.class, inputMessage); @@ -114,7 +114,7 @@ public void readXmlRootElementSubclass() throws Exception { } @Test - public void readXmlType() throws Exception { + void readXmlType() throws Exception { byte[] body = "".getBytes(StandardCharsets.UTF_8); MockHttpInputMessage inputMessage = new MockHttpInputMessage(body); Type result = (Type) converter.read(Type.class, inputMessage); @@ -122,7 +122,7 @@ public void readXmlType() throws Exception { } @Test - public void readXmlRootElementExternalEntityDisabled() throws Exception { + void readXmlRootElementExternalEntityDisabled() throws Exception { Resource external = new ClassPathResource("external.txt", getClass()); String content = "\n" + @@ -136,7 +136,7 @@ public void readXmlRootElementExternalEntityDisabled() throws Exception { } @Test - public void readXmlRootElementExternalEntityEnabled() throws Exception { + void readXmlRootElementExternalEntityEnabled() throws Exception { Resource external = new ClassPathResource("external.txt", getClass()); String content = "\n" + @@ -150,7 +150,7 @@ public void readXmlRootElementExternalEntityEnabled() throws Exception { } @Test - public void testXmlBomb() throws Exception { + void testXmlBomb() throws Exception { // https://en.wikipedia.org/wiki/Billion_laughs // https://msdn.microsoft.com/en-us/magazine/ee335713.aspx String content = """ @@ -176,7 +176,7 @@ public void testXmlBomb() throws Exception { } @Test - public void writeXmlRootElement() throws Exception { + void writeXmlRootElement() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); converter.write(rootElement, null, outputMessage); assertThat(outputMessage.getHeaders().getContentType()) @@ -187,7 +187,7 @@ public void writeXmlRootElement() throws Exception { } @Test - public void writeXmlRootElementSubclass() throws Exception { + void writeXmlRootElementSubclass() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); converter.write(rootElementCglib, null, outputMessage); assertThat(outputMessage.getHeaders().getContentType()) @@ -200,7 +200,7 @@ public void writeXmlRootElementSubclass() throws Exception { // SPR-11488 @Test - public void customizeMarshaller() throws Exception { + void customizeMarshaller() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MyJaxb2RootElementHttpMessageConverter myConverter = new MyJaxb2RootElementHttpMessageConverter(); myConverter.write(new MyRootElement(new MyCustomElement("a", "b")), null, outputMessage); @@ -210,7 +210,7 @@ public void customizeMarshaller() throws Exception { } @Test - public void customizeUnmarshaller() throws Exception { + void customizeUnmarshaller() throws Exception { byte[] body = "a|||b".getBytes(StandardCharsets.UTF_8); MyJaxb2RootElementHttpMessageConverter myConverter = new MyJaxb2RootElementHttpMessageConverter(); MockHttpInputMessage inputMessage = new MockHttpInputMessage(body); diff --git a/spring-web/src/test/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverterTests.java index d8412635ef9d..303731159260 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -41,13 +41,13 @@ * @author Sebastien Deleuze * @author Rossen Stoyanchev */ -public class MappingJackson2XmlHttpMessageConverterTests { +class MappingJackson2XmlHttpMessageConverterTests { private final MappingJackson2XmlHttpMessageConverter converter = new MappingJackson2XmlHttpMessageConverter(); @Test - public void canRead() { + void canRead() { assertThat(converter.canRead(MyBean.class, new MediaType("application", "xml"))).isTrue(); assertThat(converter.canRead(MyBean.class, new MediaType("text", "xml"))).isTrue(); assertThat(converter.canRead(MyBean.class, new MediaType("application", "soap+xml"))).isTrue(); @@ -56,7 +56,7 @@ public void canRead() { } @Test - public void canWrite() { + void canWrite() { assertThat(converter.canWrite(MyBean.class, new MediaType("application", "xml"))).isTrue(); assertThat(converter.canWrite(MyBean.class, new MediaType("text", "xml"))).isTrue(); assertThat(converter.canWrite(MyBean.class, new MediaType("application", "soap+xml"))).isTrue(); @@ -65,7 +65,7 @@ public void canWrite() { } @Test - public void read() throws IOException { + void read() throws IOException { String body = "" + "Foo" + "42" + @@ -86,7 +86,7 @@ public void read() throws IOException { } @Test - public void write() throws IOException { + void write() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MyBean body = new MyBean(); body.setString("Foo"); @@ -108,7 +108,7 @@ public void write() throws IOException { } @Test - public void readInvalidXml() throws IOException { + void readInvalidXml() { String body = "FooBar"; MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(MediaType.APPLICATION_XML); @@ -117,7 +117,7 @@ public void readInvalidXml() throws IOException { } @Test - public void readValidXmlWithUnknownProperty() throws IOException { + void readValidXmlWithUnknownProperty() throws IOException { String body = "stringvalue"; MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(MediaType.APPLICATION_XML); @@ -126,7 +126,7 @@ public void readValidXmlWithUnknownProperty() throws IOException { } @Test - public void jsonView() throws Exception { + void jsonView() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); JacksonViewBean bean = new JacksonViewBean(); bean.setWithView1("with"); @@ -144,13 +144,13 @@ public void jsonView() throws Exception { } @Test - public void customXmlMapper() { + void customXmlMapper() { new MappingJackson2XmlHttpMessageConverter(new MyXmlMapper()); // Assert no exception is thrown } @Test - public void readWithExternalReference() throws IOException { + void readWithExternalReference() throws IOException { String body = "\n" + " " + "føø bår" + diff --git a/spring-web/src/test/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverterTests.java index 564aa772dcb1..72f9b5a13c39 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -48,10 +48,10 @@ * * @author Arjen Poutsma */ -public class MarshallingHttpMessageConverterTests { +class MarshallingHttpMessageConverterTests { @Test - public void canRead() { + void canRead() { Unmarshaller unmarshaller = mock(); given(unmarshaller.supports(Integer.class)).willReturn(false); @@ -66,7 +66,7 @@ public void canRead() { } @Test - public void canWrite() { + void canWrite() { Marshaller marshaller = mock(); given(marshaller.supports(Integer.class)).willReturn(false); @@ -81,7 +81,7 @@ public void canWrite() { } @Test - public void read() throws Exception { + void read() throws Exception { String body = "Hello World"; MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8)); @@ -96,7 +96,7 @@ public void read() throws Exception { } @Test - public void readWithTypeMismatchException() throws Exception { + void readWithTypeMismatchException() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(new byte[0]); Marshaller marshaller = mock(); @@ -110,7 +110,7 @@ public void readWithTypeMismatchException() throws Exception { } @Test - public void readWithMarshallingFailureException() throws Exception { + void readWithMarshallingFailureException() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(new byte[0]); UnmarshallingFailureException ex = new UnmarshallingFailureException("forced"); @@ -125,7 +125,7 @@ public void readWithMarshallingFailureException() throws Exception { } @Test - public void write() throws Exception { + void write() throws Exception { String body = "Hello World"; MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); @@ -140,7 +140,7 @@ public void write() throws Exception { } @Test - public void writeWithMarshallingFailureException() throws Exception { + void writeWithMarshallingFailureException() throws Exception { String body = "Hello World"; MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MarshallingFailureException ex = new MarshallingFailureException("forced"); @@ -154,7 +154,7 @@ public void writeWithMarshallingFailureException() throws Exception { } @Test - public void supports() { + void supports() { assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> new MarshallingHttpMessageConverter().supports(Object.class)); } diff --git a/spring-web/src/test/java/org/springframework/http/converter/xml/SourceHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/xml/SourceHttpMessageConverterTests.java index 9b4016354c8c..78d8e64d194e 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/xml/SourceHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/xml/SourceHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -55,7 +55,7 @@ * @author Arjen Poutsma * @author Rossen Stoyanchev */ -public class SourceHttpMessageConverterTests { +class SourceHttpMessageConverterTests { private static final String BODY = "Hello World"; @@ -65,7 +65,7 @@ public class SourceHttpMessageConverterTests { @BeforeEach - public void setup() throws IOException { + void setup() throws IOException { converter = new SourceHttpMessageConverter<>(); Resource external = new ClassPathResource("external.txt", getClass()); @@ -76,20 +76,20 @@ public void setup() throws IOException { @Test - public void canRead() { + void canRead() { assertThat(converter.canRead(Source.class, new MediaType("application", "xml"))).isTrue(); assertThat(converter.canRead(Source.class, new MediaType("application", "soap+xml"))).isTrue(); } @Test - public void canWrite() { + void canWrite() { assertThat(converter.canWrite(Source.class, new MediaType("application", "xml"))).isTrue(); assertThat(converter.canWrite(Source.class, new MediaType("application", "soap+xml"))).isTrue(); assertThat(converter.canWrite(Source.class, MediaType.ALL)).isTrue(); } @Test - public void readDOMSource() throws Exception { + void readDOMSource() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(BODY.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(MediaType.APPLICATION_XML); DOMSource result = (DOMSource) converter.read(DOMSource.class, inputMessage); @@ -98,7 +98,7 @@ public void readDOMSource() throws Exception { } @Test - public void readDOMSourceExternal() throws Exception { + void readDOMSourceExternal() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(bodyExternal.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(MediaType.APPLICATION_XML); converter.setSupportDtd(true); @@ -109,7 +109,7 @@ public void readDOMSourceExternal() throws Exception { } @Test - public void readDomSourceWithXmlBomb() throws Exception { + void readDomSourceWithXmlBomb() { // https://en.wikipedia.org/wiki/Billion_laughs // https://msdn.microsoft.com/en-us/magazine/ee335713.aspx String content = """ @@ -136,7 +136,7 @@ public void readDomSourceWithXmlBomb() throws Exception { } @Test - public void readSAXSource() throws Exception { + void readSAXSource() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(BODY.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(MediaType.APPLICATION_XML); SAXSource result = (SAXSource) converter.read(SAXSource.class, inputMessage); @@ -146,7 +146,7 @@ public void readSAXSource() throws Exception { } @Test - public void readSAXSourceExternal() throws Exception { + void readSAXSourceExternal() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(bodyExternal.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(MediaType.APPLICATION_XML); converter.setSupportDtd(true); @@ -164,7 +164,7 @@ public void characters(char[] ch, int start, int length) { } @Test - public void readSAXSourceWithXmlBomb() throws Exception { + void readSAXSourceWithXmlBomb() throws Exception { // https://en.wikipedia.org/wiki/Billion_laughs // https://msdn.microsoft.com/en-us/magazine/ee335713.aspx String content = """ @@ -194,7 +194,7 @@ public void readSAXSourceWithXmlBomb() throws Exception { } @Test - public void readStAXSource() throws Exception { + void readStAXSource() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(BODY.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(MediaType.APPLICATION_XML); StAXSource result = (StAXSource) converter.read(StAXSource.class, inputMessage); @@ -209,7 +209,7 @@ public void readStAXSource() throws Exception { } @Test - public void readStAXSourceExternal() throws Exception { + void readStAXSourceExternal() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(bodyExternal.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(MediaType.APPLICATION_XML); converter.setSupportDtd(true); @@ -231,7 +231,7 @@ public void readStAXSourceExternal() throws Exception { } @Test - public void readStAXSourceWithXmlBomb() throws Exception { + void readStAXSourceWithXmlBomb() throws Exception { // https://en.wikipedia.org/wiki/Billion_laughs // https://msdn.microsoft.com/en-us/magazine/ee335713.aspx String content = """ @@ -264,7 +264,7 @@ public void readStAXSourceWithXmlBomb() throws Exception { } @Test - public void readStreamSource() throws Exception { + void readStreamSource() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(BODY.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(MediaType.APPLICATION_XML); StreamSource result = (StreamSource) converter.read(StreamSource.class, inputMessage); @@ -273,14 +273,14 @@ public void readStreamSource() throws Exception { } @Test - public void readSource() throws Exception { + void readSource() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(BODY.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(MediaType.APPLICATION_XML); converter.read(Source.class, inputMessage); } @Test - public void writeDOMSource() throws Exception { + void writeDOMSource() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); Document document = documentBuilderFactory.newDocumentBuilder().newDocument(); @@ -301,7 +301,7 @@ public void writeDOMSource() throws Exception { } @Test - public void writeSAXSource() throws Exception { + void writeSAXSource() throws Exception { String xml = "Hello World"; SAXSource saxSource = new SAXSource(new InputSource(new StringReader(xml))); @@ -315,7 +315,7 @@ public void writeSAXSource() throws Exception { } @Test - public void writeStreamSource() throws Exception { + void writeStreamSource() throws Exception { String xml = "Hello World"; StreamSource streamSource = new StreamSource(new StringReader(xml)); diff --git a/spring-web/src/test/java/org/springframework/http/server/DefaultPathContainerTests.java b/spring-web/src/test/java/org/springframework/http/server/DefaultPathContainerTests.java index 7af955a3f79c..db8f51387972 100644 --- a/spring-web/src/test/java/org/springframework/http/server/DefaultPathContainerTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/DefaultPathContainerTests.java @@ -103,7 +103,7 @@ private void assertPathSegmentParamsAreImmutable(String path, LinkedMultiValueMa private void testPathSegment(String rawValue, String valueToMatch, MultiValueMap params) { PathContainer container = PathContainer.parsePath(rawValue); - if ("".equals(rawValue)) { + if (rawValue.isEmpty()) { assertThat(container.elements()).isEmpty(); return; } diff --git a/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java b/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java index 91eb6c1a1f90..d5f67995983d 100644 --- a/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -18,7 +18,6 @@ import java.io.IOException; import java.net.URI; -import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.util.List; @@ -37,7 +36,7 @@ * @author Arjen Poutsma * @author Juergen Hoeller */ -public class ServletServerHttpRequestTests { +class ServletServerHttpRequestTests { private ServletServerHttpRequest request; @@ -58,7 +57,7 @@ void getMethod() { } @Test - void getUriForSimplePath() throws URISyntaxException { + void getUriForSimplePath() { URI uri = URI.create("https://example.com/path"); mockRequest.setScheme(uri.getScheme()); mockRequest.setServerName(uri.getHost()); @@ -69,7 +68,7 @@ void getUriForSimplePath() throws URISyntaxException { } @Test - void getUriWithQueryString() throws URISyntaxException { + void getUriWithQueryString() { URI uri = URI.create("https://example.com/path?query"); mockRequest.setScheme(uri.getScheme()); mockRequest.setServerName(uri.getHost()); @@ -80,7 +79,7 @@ void getUriWithQueryString() throws URISyntaxException { } @Test // SPR-16414 - void getUriWithQueryParam() throws URISyntaxException { + void getUriWithQueryParam() { mockRequest.setScheme("https"); mockRequest.setServerPort(443); mockRequest.setServerName("example.com"); @@ -90,7 +89,7 @@ void getUriWithQueryParam() throws URISyntaxException { } @Test // SPR-16414 - void getUriWithMalformedQueryParam() throws URISyntaxException { + void getUriWithMalformedQueryParam() { mockRequest.setScheme("https"); mockRequest.setServerPort(443); mockRequest.setServerName("example.com"); @@ -100,7 +99,7 @@ void getUriWithMalformedQueryParam() throws URISyntaxException { } @Test // SPR-13876 - void getUriWithEncoding() throws URISyntaxException { + void getUriWithEncoding() { URI uri = URI.create("https://example.com/%E4%B8%AD%E6%96%87" + "?redirect=https%3A%2F%2Fgithub.com%2Fspring-projects%2Fspring-framework"); mockRequest.setScheme(uri.getScheme()); diff --git a/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpResponseTests.java b/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpResponseTests.java index 3dbef26f1b3d..efdf1bf691f4 100644 --- a/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpResponseTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpResponseTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -35,7 +35,7 @@ * @author Rossen Stoyanchev * @author Juergen Hoeller */ -public class ServletServerHttpResponseTests { +class ServletServerHttpResponseTests { private ServletServerHttpResponse response; diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/AsyncIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/AsyncIntegrationTests.java index 1f7a964a7cf1..2766f575cb56 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/AsyncIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/AsyncIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -52,7 +52,6 @@ void basicTest(HttpServer httpServer) throws Exception { startServer(httpServer); URI url = URI.create("http://localhost:" + port); - @SuppressWarnings("resource") ResponseEntity response = new RestTemplate().exchange(RequestEntity.get(url).build(), String.class); assertThat(response.getBody()).isEqualTo("hello"); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ChannelSendOperatorTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ChannelSendOperatorTests.java index 5c3c89d62bd0..6caa76349637 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ChannelSendOperatorTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ChannelSendOperatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -49,7 +49,7 @@ class ChannelSendOperatorTests { @Test - void errorBeforeFirstItem() throws Exception { + void errorBeforeFirstItem() { IllegalStateException error = new IllegalStateException("boo"); Mono completion = Mono.error(error).as(this::sendOperator); Signal signal = completion.materialize().block(); @@ -59,7 +59,7 @@ void errorBeforeFirstItem() throws Exception { } @Test - void completionBeforeFirstItem() throws Exception { + void completionBeforeFirstItem() { Mono completion = Flux.empty().as(this::sendOperator); Signal signal = completion.materialize().block(); @@ -71,15 +71,14 @@ void completionBeforeFirstItem() throws Exception { } @Test - void writeOneItem() throws Exception { + void writeOneItem() { Mono completion = Flux.just("one").as(this::sendOperator); Signal signal = completion.materialize().block(); assertThat(signal).isNotNull(); assertThat(signal.isOnComplete()).as("Unexpected signal: " + signal).isTrue(); - assertThat(this.writer.items).hasSize(1); - assertThat(this.writer.items).element(0).isEqualTo("one"); + assertThat(this.writer.items).containsExactly("one"); assertThat(this.writer.completed).isTrue(); } @@ -93,10 +92,7 @@ void writeMultipleItems() { assertThat(signal).isNotNull(); assertThat(signal.isOnComplete()).as("Unexpected signal: " + signal).isTrue(); - assertThat(this.writer.items).hasSize(3); - assertThat(this.writer.items).element(0).isEqualTo("one"); - assertThat(this.writer.items).element(1).isEqualTo("two"); - assertThat(this.writer.items).element(2).isEqualTo("three"); + assertThat(this.writer.items).containsExactly("one", "two", "three"); assertThat(this.writer.completed).isTrue(); } @@ -117,10 +113,7 @@ void errorAfterMultipleItems() { assertThat(signal).isNotNull(); assertThat(signal.getThrowable()).as("Unexpected signal: " + signal).isSameAs(error); - assertThat(this.writer.items).hasSize(3); - assertThat(this.writer.items).element(0).isEqualTo("1"); - assertThat(this.writer.items).element(1).isEqualTo("2"); - assertThat(this.writer.items).element(2).isEqualTo("3"); + assertThat(this.writer.items).containsExactly("1", "2", "3"); assertThat(this.writer.error).isSameAs(error); } @@ -171,7 +164,7 @@ void errorFromWriteSourceWhileItemCached() { operator.subscribe(new BaseSubscriber<>() {}); try { - writeSubscriber.signalDemand(1); // Let cached signals ("foo" and error) be published.. + writeSubscriber.signalDemand(1); // Let cached signals ("foo" and error) be published } catch (Throwable ex) { assertThat(ex.getCause()).isNotNull(); @@ -224,7 +217,7 @@ void errorInWriteFunction() { } - private Mono sendOperator(Publisher source){ + private Mono sendOperator(Publisher source){ return new ChannelSendOperator<>(source, writer::send); } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ContextPathCompositeHandlerTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ContextPathCompositeHandlerTests.java index 3145a8aa6a5a..aeef0ca6b491 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ContextPathCompositeHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ContextPathCompositeHandlerTests.java @@ -38,10 +38,10 @@ * * @author Rossen Stoyanchev */ -public class ContextPathCompositeHandlerTests { +class ContextPathCompositeHandlerTests { @Test - public void invalidContextPath() { + void invalidContextPath() { testInvalid(" ", "Context path must not be empty"); testInvalid("path", "Context path must begin with '/'"); testInvalid("/path/", "Context path must not end with '/'"); @@ -54,7 +54,7 @@ private void testInvalid(String contextPath, String expectedError) { } @Test - public void match() { + void match() { TestHttpHandler handler1 = new TestHttpHandler(); TestHttpHandler handler2 = new TestHttpHandler(); TestHttpHandler handler3 = new TestHttpHandler(); @@ -71,7 +71,7 @@ public void match() { } @Test - public void matchWithContextPathEqualToPath() { + void matchWithContextPathEqualToPath() { TestHttpHandler handler1 = new TestHttpHandler(); TestHttpHandler handler2 = new TestHttpHandler(); TestHttpHandler handler3 = new TestHttpHandler(); @@ -88,7 +88,7 @@ public void matchWithContextPathEqualToPath() { } @Test - public void matchWithNativeContextPath() { + void matchWithNativeContextPath() { MockServerHttpRequest request = MockServerHttpRequest .get("/yet/another/path") .contextPath("/yet") // contextPath in underlying request @@ -104,7 +104,7 @@ public void matchWithNativeContextPath() { } @Test - public void notFound() { + void notFound() { TestHttpHandler handler1 = new TestHttpHandler(); TestHttpHandler handler2 = new TestHttpHandler(); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java index c78c047a3455..a2948129e981 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -39,7 +39,7 @@ * @author Rossen Stoyanchev * @author Sebastien Deleuze */ -public class CookieIntegrationTests extends AbstractHttpHandlerIntegrationTests { +class CookieIntegrationTests extends AbstractHttpHandlerIntegrationTests { private final CookieHandler cookieHandler = new CookieHandler(); @@ -56,7 +56,6 @@ public void basicTest(HttpServer httpServer) throws Exception { URI url = URI.create("http://localhost:" + port); String header = "SID=31d4d96e407aad42; lang=en-US"; - @SuppressWarnings("resource") ResponseEntity response = new RestTemplate().exchange( RequestEntity.get(url).header("Cookie", header).build(), Void.class); @@ -105,7 +104,7 @@ private List splitCookie(String value) { } - private class CookieHandler implements HttpHandler { + private static class CookieHandler implements HttpHandler { private Map> requestCookies; diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java index aedf61a0fa07..9f745b95af0b 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -32,7 +32,7 @@ /** * @author Arjen Poutsma */ -public class EchoHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests { +class EchoHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests { private static final int REQUEST_SIZE = 4096 * 3; @@ -49,7 +49,6 @@ protected EchoHandler createHttpHandler() { public void echo(HttpServer httpServer) throws Exception { startServer(httpServer); - @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); byte[] body = randomBytes(); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java index bcb336e2c10f..804327bea46c 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -49,7 +49,6 @@ protected HttpHandler createHttpHandler() { void responseBodyError(HttpServer httpServer) throws Exception { startServer(httpServer); - @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER); @@ -63,7 +62,6 @@ void responseBodyError(HttpServer httpServer) throws Exception { void handlingError(HttpServer httpServer) throws Exception { startServer(httpServer); - @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER); @@ -77,7 +75,6 @@ void handlingError(HttpServer httpServer) throws Exception { void emptyPathSegments(HttpServer httpServer) throws Exception { startServer(httpServer); - @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/HeadersAdaptersTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/HeadersAdaptersTests.java index 633e81058422..d3e2af64ea11 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/HeadersAdaptersTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/HeadersAdaptersTests.java @@ -20,14 +20,15 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import java.util.Arrays; import java.util.Iterator; +import java.util.List; import java.util.Locale; import java.util.stream.Stream; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.undertow.util.HeaderMap; import org.apache.tomcat.util.http.MimeHeaders; +import org.assertj.core.api.StringAssert; import org.eclipse.jetty.http.HttpFields; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -89,13 +90,13 @@ void addShouldKeepOrdering(MultiValueMap headers) { headers.add("TestHeader", "first"); headers.add("TestHeader", "second"); assertThat(headers.getFirst("TestHeader")).isEqualTo("first"); - assertThat(headers.get("TestHeader")).element(0).isEqualTo("first"); + assertThat(headers.get("TestHeader"), StringAssert.class).element(0).isEqualTo("first"); } @ParameterizedHeadersTest void putShouldOverrideExisting(MultiValueMap headers) { headers.add("TestHeader", "first"); - headers.put("TestHeader", Arrays.asList("override")); + headers.put("TestHeader", List.of("override")); assertThat(headers.getFirst("TestHeader")).isEqualTo("override"); assertThat(headers.get("TestHeader")).hasSize(1); } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ListenerReadPublisherTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ListenerReadPublisherTests.java index d1554898b022..8f42edbf676e 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ListenerReadPublisherTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ListenerReadPublisherTests.java @@ -32,7 +32,7 @@ * @author Violeta Georgieva * @author Rossen Stoyanchev */ -public class ListenerReadPublisherTests { +class ListenerReadPublisherTests { private final TestListenerReadPublisher publisher = new TestListenerReadPublisher(); @@ -40,13 +40,13 @@ public class ListenerReadPublisherTests { @BeforeEach - public void setup() { + void setup() { this.publisher.subscribe(this.subscriber); } @Test - public void twoReads() { + void twoReads() { this.subscriber.getSubscription().request(2); this.publisher.onDataAvailable(); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ListenerWriteProcessorTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ListenerWriteProcessorTests.java index 8256e937ec1e..71d6daa91cf8 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ListenerWriteProcessorTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ListenerWriteProcessorTests.java @@ -35,7 +35,7 @@ * * @author Rossen Stoyanchev */ -public class ListenerWriteProcessorTests { +class ListenerWriteProcessorTests { private final TestListenerWriteProcessor processor = new TestListenerWriteProcessor(); @@ -45,7 +45,7 @@ public class ListenerWriteProcessorTests { @BeforeEach - public void setup() { + void setup() { this.processor.subscribe(this.resultSubscriber); this.processor.onSubscribe(this.subscription); assertThat(subscription.getDemand()).isEqualTo(1); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java index 350673828ba5..1d35756ac86c 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -59,7 +59,6 @@ void random(HttpServer httpServer) throws Exception { // TODO: fix Reactor support - @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); byte[] body = randomBytes(); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ReactorUriHelperTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ReactorUriHelperTests.java index d5e51445b6fb..3f829808a68c 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ReactorUriHelperTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ReactorUriHelperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -29,10 +29,10 @@ /** * @author Arjen Poutsma */ -public class ReactorUriHelperTests { +class ReactorUriHelperTests { @Test - public void hostnameWithZoneId() throws URISyntaxException { + void hostnameWithZoneId() throws URISyntaxException { HttpServerRequest nettyRequest = mock(); given(nettyRequest.scheme()).willReturn("http"); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java index 34ed853aa778..0b091c4fe340 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -46,7 +46,6 @@ void checkUri(HttpServer httpServer) throws Exception { URI url = URI.create("http://localhost:" + port + "/foo?param=bar"); RequestEntity request = RequestEntity.post(url).build(); - @SuppressWarnings("resource") ResponseEntity response = new RestTemplate().exchange(request, Void.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestTests.java index 4d6d580d6576..73d7559e6475 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestTests.java @@ -48,16 +48,16 @@ * @author Sam Brannen * @author Brian Clozel */ -public class ServerHttpRequestTests { +class ServerHttpRequestTests { @Test - public void queryParamsNone() throws Exception { + void queryParamsNone() throws Exception { MultiValueMap params = createRequest("/path").getQueryParams(); assertThat(params).isEmpty(); } @Test - public void queryParams() throws Exception { + void queryParams() throws Exception { MultiValueMap params = createRequest("/path?a=A&b=B").getQueryParams(); assertThat(params).hasSize(2); assertThat(params.get("a")).isEqualTo(Collections.singletonList("A")); @@ -65,7 +65,7 @@ public void queryParams() throws Exception { } @Test - public void queryParamsWithMultipleValues() throws Exception { + void queryParamsWithMultipleValues() throws Exception { MultiValueMap params = createRequest("/path?a=1&a=2").getQueryParams(); assertThat(params).hasSize(1); assertThat(params.get("a")).isEqualTo(Arrays.asList("1", "2")); @@ -79,34 +79,34 @@ public void queryParamsWithEncodedValue() throws Exception { } @Test - public void queryParamsWithEmptyValue() throws Exception { + void queryParamsWithEmptyValue() throws Exception { MultiValueMap params = createRequest("/path?a=").getQueryParams(); assertThat(params).hasSize(1); assertThat(params.get("a")).isEqualTo(Collections.singletonList("")); } @Test - public void queryParamsWithNoValue() throws Exception { + void queryParamsWithNoValue() throws Exception { MultiValueMap params = createRequest("/path?a").getQueryParams(); assertThat(params).hasSize(1); assertThat(params.get("a")).isEqualTo(Collections.singletonList(null)); } @Test - public void mutateRequestMethod() throws Exception { + void mutateRequestMethod() throws Exception { ServerHttpRequest request = createRequest("/").mutate().method(HttpMethod.DELETE).build(); assertThat(request.getMethod()).isEqualTo(HttpMethod.DELETE); } @Test - public void mutateSslInfo() throws Exception { + void mutateSslInfo() throws Exception { SslInfo sslInfo = mock(); ServerHttpRequest request = createRequest("/").mutate().sslInfo(sslInfo).build(); assertThat(request.getSslInfo()).isSameAs(sslInfo); } @Test - public void mutateUriAndPath() throws Exception { + void mutateUriAndPath() throws Exception { String baseUri = "https://aaa.org:8080/a"; ServerHttpRequest request = createRequest(baseUri).mutate().uri(URI.create("https://bbb.org:9090/b")).build(); @@ -130,12 +130,12 @@ public void mutatePathWithEncodedQueryParams() throws Exception { } @Test - public void mutateWithInvalidPath() { + void mutateWithInvalidPath() { assertThatIllegalArgumentException().isThrownBy(() -> createRequest("/").mutate().path("foo-bar")); } @Test - public void mutateHeadersViaConsumer() throws Exception { + void mutateHeadersViaConsumer() throws Exception { String headerName = "key"; String headerValue1 = "value1"; String headerValue2 = "value2"; @@ -151,7 +151,7 @@ public void mutateHeadersViaConsumer() throws Exception { } @Test - public void mutateHeaderBySettingHeaderValues() throws Exception { + void mutateHeaderBySettingHeaderValues() throws Exception { String headerName = "key"; String headerValue1 = "value1"; String headerValue2 = "value2"; diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpsRequestIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpsRequestIntegrationTests.java index 63a5d728c04a..3a07b0db9b41 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpsRequestIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpsRequestIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -85,7 +85,7 @@ void stopServer() { } @Test - void checkUri() throws Exception { + void checkUri() { URI url = URI.create("https://localhost:" + port + "/foo?param=bar"); RequestEntity request = RequestEntity.post(url).build(); ResponseEntity response = this.restTemplate.exchange(request, Void.class); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java index 266d19d65e41..46d6342210df 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -54,7 +54,6 @@ protected WriteOnlyHandler createHttpHandler() { void writeOnly(HttpServer httpServer) throws Exception { startServer(httpServer); - @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); this.body = randomBytes(); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java index 36c672a417db..587825b0b066 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -61,7 +61,6 @@ void zeroCopy(HttpServer httpServer) throws Exception { URI url = URI.create("http://localhost:" + port); RequestEntity request = RequestEntity.get(url).build(); - @SuppressWarnings("resource") ResponseEntity response = new RestTemplate().exchange(request, byte[].class); assertThat(response.hasBody()).isTrue(); diff --git a/spring-web/src/test/java/org/springframework/web/ErrorResponseExceptionTests.java b/spring-web/src/test/java/org/springframework/web/ErrorResponseExceptionTests.java index 6405a092cd1d..396ef15b3d73 100644 --- a/spring-web/src/test/java/org/springframework/web/ErrorResponseExceptionTests.java +++ b/spring-web/src/test/java/org/springframework/web/ErrorResponseExceptionTests.java @@ -70,7 +70,7 @@ * * @author Rossen Stoyanchev */ -public class ErrorResponseExceptionTests { +class ErrorResponseExceptionTests { private final MethodParameter methodParameter = new MethodParameter(ResolvableMethod.on(getClass()).resolveMethod("handle"), 0); diff --git a/spring-web/src/test/java/org/springframework/web/accept/HeaderContentNegotiationStrategyTests.java b/spring-web/src/test/java/org/springframework/web/accept/HeaderContentNegotiationStrategyTests.java index f14a1fdd6300..b5115cf9662e 100644 --- a/spring-web/src/test/java/org/springframework/web/accept/HeaderContentNegotiationStrategyTests.java +++ b/spring-web/src/test/java/org/springframework/web/accept/HeaderContentNegotiationStrategyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -35,7 +35,7 @@ * @author Rossen Stoyanchev * @author Juergen Hoeller */ -public class HeaderContentNegotiationStrategyTests { +class HeaderContentNegotiationStrategyTests { private final HeaderContentNegotiationStrategy strategy = new HeaderContentNegotiationStrategy(); @@ -45,7 +45,7 @@ public class HeaderContentNegotiationStrategyTests { @Test - public void resolveMediaTypes() throws Exception { + void resolveMediaTypes() throws Exception { this.servletRequest.addHeader("Accept", "text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c"); List mediaTypes = this.strategy.resolveMediaTypes(this.webRequest); @@ -70,7 +70,7 @@ public void resolveMediaTypesFromMultipleHeaderValues() throws Exception { } @Test - public void resolveMediaTypesParseError() throws Exception { + void resolveMediaTypesParseError() { this.servletRequest.addHeader("Accept", "textplain; q=0.5"); assertThatExceptionOfType(HttpMediaTypeNotAcceptableException.class).isThrownBy(() -> this.strategy.resolveMediaTypes(this.webRequest)); diff --git a/spring-web/src/test/java/org/springframework/web/accept/MappingContentNegotiationStrategyTests.java b/spring-web/src/test/java/org/springframework/web/accept/MappingContentNegotiationStrategyTests.java index b9ace3bbeda8..e5fb78df8762 100644 --- a/spring-web/src/test/java/org/springframework/web/accept/MappingContentNegotiationStrategyTests.java +++ b/spring-web/src/test/java/org/springframework/web/accept/MappingContentNegotiationStrategyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -33,10 +33,10 @@ * @author Rossen Stoyanchev * @since 3.2 */ -public class MappingContentNegotiationStrategyTests { +class MappingContentNegotiationStrategyTests { @Test - public void resolveMediaTypes() throws Exception { + void resolveMediaTypes() throws Exception { Map mapping = Collections.singletonMap("json", MediaType.APPLICATION_JSON); TestMappingContentNegotiationStrategy strategy = new TestMappingContentNegotiationStrategy("json", mapping); @@ -47,7 +47,7 @@ public void resolveMediaTypes() throws Exception { } @Test - public void resolveMediaTypesNoMatch() throws Exception { + void resolveMediaTypesNoMatch() throws Exception { Map mapping = null; TestMappingContentNegotiationStrategy strategy = new TestMappingContentNegotiationStrategy("blah", mapping); @@ -57,7 +57,7 @@ public void resolveMediaTypesNoMatch() throws Exception { } @Test - public void resolveMediaTypesNoKey() throws Exception { + void resolveMediaTypesNoKey() throws Exception { Map mapping = Collections.singletonMap("json", MediaType.APPLICATION_JSON); TestMappingContentNegotiationStrategy strategy = new TestMappingContentNegotiationStrategy(null, mapping); @@ -67,7 +67,7 @@ public void resolveMediaTypesNoKey() throws Exception { } @Test - public void resolveMediaTypesHandleNoMatch() throws Exception { + void resolveMediaTypesHandleNoMatch() throws Exception { Map mapping = null; TestMappingContentNegotiationStrategy strategy = new TestMappingContentNegotiationStrategy("xml", mapping); diff --git a/spring-web/src/test/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolverTests.java b/spring-web/src/test/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolverTests.java index 8fd4304009a9..002e07626860 100644 --- a/spring-web/src/test/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -33,23 +33,22 @@ * @author Rossen Stoyanchev * @author Melissa Hartsock */ -public class MappingMediaTypeFileExtensionResolverTests { +class MappingMediaTypeFileExtensionResolverTests { private static final Map DEFAULT_MAPPINGS = Collections.singletonMap("json", MediaType.APPLICATION_JSON); @Test - public void resolveExtensions() { + void resolveExtensions() { List extensions = new MappingMediaTypeFileExtensionResolver(DEFAULT_MAPPINGS) .resolveFileExtensions(MediaType.APPLICATION_JSON); - assertThat(extensions).hasSize(1); - assertThat(extensions).element(0).isEqualTo("json"); + assertThat(extensions).containsExactly("json"); } @Test - public void resolveExtensionsNoMatch() { + void resolveExtensionsNoMatch() { assertThat(new MappingMediaTypeFileExtensionResolver(DEFAULT_MAPPINGS) .resolveFileExtensions(MediaType.TEXT_HTML)).isEmpty(); } @@ -61,7 +60,7 @@ public void lookupMediaTypeCaseInsensitive() { } @Test - public void allFileExtensions() { + void allFileExtensions() { Map mappings = new HashMap<>(); mappings.put("json", MediaType.APPLICATION_JSON); mappings.put("JsOn", MediaType.APPLICATION_JSON); diff --git a/spring-web/src/test/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategyTests.java b/spring-web/src/test/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategyTests.java index 3dfd0e8ec286..c1adc00d76d7 100644 --- a/spring-web/src/test/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategyTests.java +++ b/spring-web/src/test/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -16,7 +16,6 @@ package org.springframework.web.accept; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -54,13 +53,13 @@ void resolveMediaTypesFromMapping() throws Exception { List mediaTypes = this.strategy.resolveMediaTypes(this.webRequest); - assertThat(mediaTypes).isEqualTo(Arrays.asList(new MediaType("text", "html"))); + assertThat(mediaTypes).containsExactly(new MediaType("text", "html")); Map mapping = Collections.singletonMap("HTML", MediaType.APPLICATION_XHTML_XML); this.strategy = new PathExtensionContentNegotiationStrategy(mapping); mediaTypes = this.strategy.resolveMediaTypes(this.webRequest); - assertThat(mediaTypes).isEqualTo(Arrays.asList(new MediaType("application", "xhtml+xml"))); + assertThat(mediaTypes).containsExactly(new MediaType("application", "xhtml+xml")); } @Test @@ -69,7 +68,7 @@ void resolveMediaTypesFromMediaTypeFactory() throws Exception { List mediaTypes = this.strategy.resolveMediaTypes(this.webRequest); - assertThat(mediaTypes).isEqualTo(Arrays.asList(new MediaType("application", "vnd.ms-excel"))); + assertThat(mediaTypes).containsExactly(new MediaType("application", "vnd.ms-excel")); } @Test // SPR-8678 diff --git a/spring-web/src/test/java/org/springframework/web/bind/EscapedErrorsTests.java b/spring-web/src/test/java/org/springframework/web/bind/EscapedErrorsTests.java index 5b88f96103ed..a8990cad2b63 100644 --- a/spring-web/src/test/java/org/springframework/web/bind/EscapedErrorsTests.java +++ b/spring-web/src/test/java/org/springframework/web/bind/EscapedErrorsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -30,10 +30,10 @@ * @author Juergen Hoeller * @since 02.05.2003 */ -public class EscapedErrorsTests { +class EscapedErrorsTests { @Test - public void testEscapedErrors() { + void testEscapedErrors() { TestBean tb = new TestBean(); tb.setName("empty &"); diff --git a/spring-web/src/test/java/org/springframework/web/bind/MethodArgumentNotValidExceptionTests.java b/spring-web/src/test/java/org/springframework/web/bind/MethodArgumentNotValidExceptionTests.java index 08c8ff1ac1bc..d385271016e2 100644 --- a/spring-web/src/test/java/org/springframework/web/bind/MethodArgumentNotValidExceptionTests.java +++ b/spring-web/src/test/java/org/springframework/web/bind/MethodArgumentNotValidExceptionTests.java @@ -40,7 +40,7 @@ * * @author Rossen Stoyanchev */ -public class MethodArgumentNotValidExceptionTests { +class MethodArgumentNotValidExceptionTests { @Test void errorsToStringList() throws Exception { diff --git a/spring-web/src/test/java/org/springframework/web/bind/ServletRequestDataBinderTests.java b/spring-web/src/test/java/org/springframework/web/bind/ServletRequestDataBinderTests.java index 1c06d22d2bed..adbae1ddc62d 100644 --- a/spring-web/src/test/java/org/springframework/web/bind/ServletRequestDataBinderTests.java +++ b/spring-web/src/test/java/org/springframework/web/bind/ServletRequestDataBinderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -37,10 +37,10 @@ * @author Chris Beams * @author Scott Andrews */ -public class ServletRequestDataBinderTests { +class ServletRequestDataBinderTests { @Test - public void testBindingWithNestedObjectCreation() throws Exception { + void testBindingWithNestedObjectCreation() { TestBean tb = new TestBean(); ServletRequestDataBinder binder = new ServletRequestDataBinder(tb, "person"); @@ -61,7 +61,7 @@ public void setAsText(String text) throws IllegalArgumentException { } @Test - public void testFieldPrefixCausesFieldReset() throws Exception { + void testFieldPrefixCausesFieldReset() { TestBean target = new TestBean(); ServletRequestDataBinder binder = new ServletRequestDataBinder(target); @@ -77,7 +77,7 @@ public void testFieldPrefixCausesFieldReset() throws Exception { } @Test - public void testFieldPrefixCausesFieldResetWithIgnoreUnknownFields() throws Exception { + void testFieldPrefixCausesFieldResetWithIgnoreUnknownFields() { TestBean target = new TestBean(); ServletRequestDataBinder binder = new ServletRequestDataBinder(target); binder.setIgnoreUnknownFields(false); @@ -94,7 +94,7 @@ public void testFieldPrefixCausesFieldResetWithIgnoreUnknownFields() throws Exce } @Test - public void testFieldDefault() throws Exception { + void testFieldDefault() { TestBean target = new TestBean(); ServletRequestDataBinder binder = new ServletRequestDataBinder(target); @@ -110,7 +110,7 @@ public void testFieldDefault() throws Exception { } @Test - public void testFieldDefaultPreemptsFieldMarker() throws Exception { + void testFieldDefaultPreemptsFieldMarker() { TestBean target = new TestBean(); ServletRequestDataBinder binder = new ServletRequestDataBinder(target); @@ -131,7 +131,7 @@ public void testFieldDefaultPreemptsFieldMarker() throws Exception { } @Test - public void testFieldDefaultNonBoolean() throws Exception { + void testFieldDefaultNonBoolean() { TestBean target = new TestBean(); ServletRequestDataBinder binder = new ServletRequestDataBinder(target); @@ -147,7 +147,7 @@ public void testFieldDefaultNonBoolean() throws Exception { } @Test - public void testWithCommaSeparatedStringArray() throws Exception { + void testWithCommaSeparatedStringArray() { TestBean target = new TestBean(); ServletRequestDataBinder binder = new ServletRequestDataBinder(target); @@ -165,7 +165,7 @@ public void testWithCommaSeparatedStringArray() throws Exception { } @Test - public void testBindingWithNestedObjectCreationAndWrongOrder() throws Exception { + void testBindingWithNestedObjectCreationAndWrongOrder() { TestBean tb = new TestBean(); ServletRequestDataBinder binder = new ServletRequestDataBinder(tb, "person"); @@ -186,7 +186,7 @@ public void setAsText(String text) throws IllegalArgumentException { } @Test - public void testNoPrefix() throws Exception { + void testNoPrefix() { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("forname", "Tony"); request.addParameter("surname", "Blair"); @@ -197,7 +197,7 @@ public void testNoPrefix() throws Exception { } @Test - public void testPrefix() throws Exception { + void testPrefix() { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("test_forname", "Tony"); request.addParameter("test_surname", "Blair"); @@ -213,14 +213,14 @@ public void testPrefix() throws Exception { } @Test - public void testNoParameters() throws Exception { + void testNoParameters() { MockHttpServletRequest request = new MockHttpServletRequest(); ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request); assertThat(pvs.getPropertyValues().length).as("Found no parameters").isEqualTo(0); } @Test - public void testMultipleValuesForParameter() throws Exception { + void testMultipleValuesForParameter() { MockHttpServletRequest request = new MockHttpServletRequest(); String[] original = new String[] {"Tony", "Rod"}; request.addParameter("forname", original); @@ -236,7 +236,7 @@ public void testMultipleValuesForParameter() throws Exception { /** * Must contain: forname=Tony surname=Blair age=50 */ - protected void doTestTony(PropertyValues pvs) throws Exception { + protected void doTestTony(PropertyValues pvs) { assertThat(pvs.getPropertyValues().length).as("Contains 3").isEqualTo(3); assertThat(pvs.contains("forname")).as("Contains forname").isTrue(); assertThat(pvs.contains("surname")).as("Contains surname").isTrue(); diff --git a/spring-web/src/test/java/org/springframework/web/bind/ServletRequestUtilsTests.java b/spring-web/src/test/java/org/springframework/web/bind/ServletRequestUtilsTests.java index 58ea35d9cd95..b6974e704cd9 100644 --- a/spring-web/src/test/java/org/springframework/web/bind/ServletRequestUtilsTests.java +++ b/spring-web/src/test/java/org/springframework/web/bind/ServletRequestUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -58,7 +58,7 @@ void testIntParameter() throws ServletRequestBindingException { @Test void testIntParameters() throws ServletRequestBindingException { - request.addParameter("param", new String[] {"1", "2", "3"}); + request.addParameter("param", "1", "2", "3"); request.addParameter("param2", "1"); request.addParameter("param2", "2"); @@ -100,7 +100,7 @@ void testLongParameter() throws ServletRequestBindingException { @Test void testLongParameters() throws ServletRequestBindingException { - request.setParameter("param", new String[] {"1", "2", "3"}); + request.setParameter("param", "1", "2", "3"); request.setParameter("param2", "0"); request.setParameter("param2", "1"); @@ -113,7 +113,7 @@ void testLongParameters() throws ServletRequestBindingException { assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() -> ServletRequestUtils.getRequiredLongParameters(request, "param2")); - request.setParameter("param2", new String[] {"1", "2"}); + request.setParameter("param2", "1", "2"); values = ServletRequestUtils.getRequiredLongParameters(request, "param2"); assertThat(values).containsExactly(1, 2); @@ -147,7 +147,7 @@ void testFloatParameter() throws ServletRequestBindingException { @Test void testFloatParameters() throws ServletRequestBindingException { - request.addParameter("param", new String[] {"1.5", "2.5", "3"}); + request.addParameter("param", "1.5", "2.5", "3"); request.addParameter("param2", "1.5"); request.addParameter("param2", "2"); @@ -185,7 +185,7 @@ void testDoubleParameter() throws ServletRequestBindingException { @Test void testDoubleParameters() throws ServletRequestBindingException { - request.addParameter("param", new String[] {"1.5", "2.5", "3"}); + request.addParameter("param", "1.5", "2.5", "3"); request.addParameter("param2", "1.5"); request.addParameter("param2", "2"); @@ -227,7 +227,7 @@ void testBooleanParameter() throws ServletRequestBindingException { @Test void testBooleanParameters() throws ServletRequestBindingException { - request.addParameter("param", new String[] {"true", "yes", "off", "1", "bogus"}); + request.addParameter("param", "true", "yes", "off", "1", "bogus"); request.addParameter("param2", "false"); request.addParameter("param2", "true"); diff --git a/spring-web/src/test/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessorTests.java b/spring-web/src/test/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessorTests.java index 596fc6fcaaf0..9f3b20a2344f 100644 --- a/spring-web/src/test/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessorTests.java +++ b/spring-web/src/test/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -32,7 +32,7 @@ * * @author Sebastien Deleuze */ -public class ControllerMappingReflectiveProcessorTests { +class ControllerMappingReflectiveProcessorTests { private final ControllerMappingReflectiveProcessor processor = new ControllerMappingReflectiveProcessor(); @@ -239,7 +239,7 @@ void postHttpEntity(HttpEntity entity) { } @PostMapping - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings("rawtypes") void postRawHttpEntity(HttpEntity entity) { } diff --git a/spring-web/src/test/java/org/springframework/web/bind/support/DefaultDataBinderFactoryTests.java b/spring-web/src/test/java/org/springframework/web/bind/support/DefaultDataBinderFactoryTests.java index e492da10721e..046fe7ab4c4b 100644 --- a/spring-web/src/test/java/org/springframework/web/bind/support/DefaultDataBinderFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/web/bind/support/DefaultDataBinderFactoryTests.java @@ -37,7 +37,7 @@ /** * Tests for {@link DefaultDataBinderFactory}. */ -public class DefaultDataBinderFactoryTests { +class DefaultDataBinderFactoryTests { @Test void jakartaValidatorExcludedWhenMethodValidationApplicable() throws Exception { diff --git a/spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java b/spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java index c7ba27fc0cf1..049d4a59cb19 100644 --- a/spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java +++ b/spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java @@ -52,7 +52,7 @@ * * @author Rossen Stoyanchev */ -public class WebExchangeDataBinderTests { +class WebExchangeDataBinderTests { private TestBean testBean; @@ -60,7 +60,7 @@ public class WebExchangeDataBinderTests { @BeforeEach - public void setup() { + void setup() { this.testBean = new TestBean(); this.binder = new WebExchangeDataBinder(this.testBean, "person"); this.binder.registerCustomEditor(ITestBean.class, new TestBeanPropertyEditor()); @@ -68,7 +68,7 @@ public void setup() { @Test - public void testBindingWithNestedObjectCreation() { + void testBindingWithNestedObjectCreation() { MultiValueMap formData = new LinkedMultiValueMap<>(); formData.add("spouse", "someValue"); formData.add("spouse.name", "test"); @@ -79,7 +79,7 @@ public void testBindingWithNestedObjectCreation() { } @Test - public void testFieldPrefixCausesFieldReset() { + void testFieldPrefixCausesFieldReset() { MultiValueMap formData = new LinkedMultiValueMap<>(); formData.add("_postProcessed", "visible"); formData.add("postProcessed", "on"); @@ -92,7 +92,7 @@ public void testFieldPrefixCausesFieldReset() { } @Test - public void testFieldPrefixCausesFieldResetWithIgnoreUnknownFields() { + void testFieldPrefixCausesFieldResetWithIgnoreUnknownFields() { this.binder.setIgnoreUnknownFields(false); MultiValueMap formData = new LinkedMultiValueMap<>(); @@ -116,7 +116,7 @@ public void testFieldWithEmptyArrayIndex() { } @Test - public void testFieldDefault() { + void testFieldDefault() { MultiValueMap formData = new LinkedMultiValueMap<>(); formData.add("!postProcessed", "off"); formData.add("postProcessed", "on"); @@ -129,7 +129,7 @@ public void testFieldDefault() { } @Test - public void testFieldDefaultPreemptsFieldMarker() { + void testFieldDefaultPreemptsFieldMarker() { MultiValueMap formData = new LinkedMultiValueMap<>(); formData.add("!postProcessed", "on"); formData.add("_postProcessed", "visible"); @@ -147,7 +147,7 @@ public void testFieldDefaultPreemptsFieldMarker() { } @Test - public void testFieldDefaultNonBoolean() { + void testFieldDefaultNonBoolean() { MultiValueMap formData = new LinkedMultiValueMap<>(); formData.add("!name", "anonymous"); formData.add("name", "Scott"); @@ -160,7 +160,7 @@ public void testFieldDefaultNonBoolean() { } @Test - public void testWithCommaSeparatedStringArray() { + void testWithCommaSeparatedStringArray() { MultiValueMap formData = new LinkedMultiValueMap<>(); formData.add("stringArray", "bar"); formData.add("stringArray", "abc"); @@ -175,7 +175,7 @@ public void testWithCommaSeparatedStringArray() { } @Test - public void testBindingWithNestedObjectCreationAndWrongOrder() { + void testBindingWithNestedObjectCreationAndWrongOrder() { MultiValueMap formData = new LinkedMultiValueMap<>(); formData.add("spouse.name", "test"); formData.add("spouse", "someValue"); @@ -186,7 +186,7 @@ public void testBindingWithNestedObjectCreationAndWrongOrder() { } @Test - public void testBindingWithQueryParams() { + void testBindingWithQueryParams() { String url = "/path?spouse=someValue&spouse.name=test"; ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post(url)); this.binder.bind(exchange).block(Duration.ofSeconds(5)); @@ -196,7 +196,7 @@ public void testBindingWithQueryParams() { } @Test - public void testMultipart() { + void testMultipart() { MultipartBean bean = new MultipartBean(); WebExchangeDataBinder binder = new WebExchangeDataBinder(bean); @@ -222,7 +222,7 @@ public void testMultipart() { } @Test - public void testMultipartDataClass() { + void testMultipartDataClass() { WebExchangeDataBinder binder = new WebExchangeDataBinder(null); binder.setTargetType(ResolvableType.forClass(MultipartDataClass.class)); diff --git a/spring-web/src/test/java/org/springframework/web/bind/support/WebRequestDataBinderTests.java b/spring-web/src/test/java/org/springframework/web/bind/support/WebRequestDataBinderTests.java index 18abfa546e86..cc89017f3624 100644 --- a/spring-web/src/test/java/org/springframework/web/bind/support/WebRequestDataBinderTests.java +++ b/spring-web/src/test/java/org/springframework/web/bind/support/WebRequestDataBinderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -41,10 +41,10 @@ /** * @author Juergen Hoeller */ -public class WebRequestDataBinderTests { +class WebRequestDataBinderTests { @Test - public void testBindingWithNestedObjectCreation() throws Exception { + void testBindingWithNestedObjectCreation() { TestBean tb = new TestBean(); WebRequestDataBinder binder = new WebRequestDataBinder(tb, "person"); @@ -65,7 +65,7 @@ public void setAsText(String text) throws IllegalArgumentException { } @Test - public void testBindingWithNestedObjectCreationThroughAutoGrow() throws Exception { + void testBindingWithNestedObjectCreationThroughAutoGrow() { TestBean tb = new TestBeanWithConcreteSpouse(); WebRequestDataBinder binder = new WebRequestDataBinder(tb, "person"); @@ -80,7 +80,7 @@ public void testBindingWithNestedObjectCreationThroughAutoGrow() throws Exceptio } @Test - public void testFieldPrefixCausesFieldReset() throws Exception { + void testFieldPrefixCausesFieldReset() { TestBean target = new TestBean(); WebRequestDataBinder binder = new WebRequestDataBinder(target); @@ -96,7 +96,7 @@ public void testFieldPrefixCausesFieldReset() throws Exception { } @Test - public void testFieldPrefixCausesFieldResetWithIgnoreUnknownFields() throws Exception { + void testFieldPrefixCausesFieldResetWithIgnoreUnknownFields() { TestBean target = new TestBean(); WebRequestDataBinder binder = new WebRequestDataBinder(target); binder.setIgnoreUnknownFields(false); @@ -125,7 +125,7 @@ public void testFieldWithEmptyArrayIndex() { } @Test - public void testFieldDefault() throws Exception { + void testFieldDefault() { TestBean target = new TestBean(); WebRequestDataBinder binder = new WebRequestDataBinder(target); @@ -142,7 +142,7 @@ public void testFieldDefault() throws Exception { // SPR-13502 @Test - public void testCollectionFieldsDefault() throws Exception { + void testCollectionFieldsDefault() { TestBean target = new TestBean(); target.setSomeSet(null); target.setSomeList(null); @@ -161,7 +161,7 @@ public void testCollectionFieldsDefault() throws Exception { } @Test - public void testFieldDefaultPreemptsFieldMarker() throws Exception { + void testFieldDefaultPreemptsFieldMarker() { TestBean target = new TestBean(); WebRequestDataBinder binder = new WebRequestDataBinder(target); @@ -182,7 +182,7 @@ public void testFieldDefaultPreemptsFieldMarker() throws Exception { } @Test - public void testFieldDefaultWithNestedProperty() throws Exception { + void testFieldDefaultWithNestedProperty() { TestBean target = new TestBean(); target.setSpouse(new TestBean()); WebRequestDataBinder binder = new WebRequestDataBinder(target); @@ -204,7 +204,7 @@ public void testFieldDefaultWithNestedProperty() throws Exception { } @Test - public void testFieldDefaultNonBoolean() throws Exception { + void testFieldDefaultNonBoolean() { TestBean target = new TestBean(); WebRequestDataBinder binder = new WebRequestDataBinder(target); @@ -220,7 +220,7 @@ public void testFieldDefaultNonBoolean() throws Exception { } @Test - public void testWithCommaSeparatedStringArray() throws Exception { + void testWithCommaSeparatedStringArray() { TestBean target = new TestBean(); WebRequestDataBinder binder = new WebRequestDataBinder(target); @@ -238,7 +238,7 @@ public void testWithCommaSeparatedStringArray() throws Exception { } @Test - public void testEnumBinding() { + void testEnumBinding() { EnumHolder target = new EnumHolder(); WebRequestDataBinder binder = new WebRequestDataBinder(target); @@ -249,7 +249,7 @@ public void testEnumBinding() { } @Test - public void testMultipartFileAsString() { + void testMultipartFileAsString() { TestBean target = new TestBean(); WebRequestDataBinder binder = new WebRequestDataBinder(target); binder.registerCustomEditor(String.class, new StringMultipartFileEditor()); @@ -261,7 +261,7 @@ public void testMultipartFileAsString() { } @Test - public void testMultipartFileAsStringArray() { + void testMultipartFileAsStringArray() { TestBean target = new TestBean(); WebRequestDataBinder binder = new WebRequestDataBinder(target); binder.registerCustomEditor(String.class, new StringMultipartFileEditor()); @@ -274,7 +274,7 @@ public void testMultipartFileAsStringArray() { } @Test - public void testMultipartFilesAsStringArray() { + void testMultipartFilesAsStringArray() { TestBean target = new TestBean(); WebRequestDataBinder binder = new WebRequestDataBinder(target); binder.registerCustomEditor(String.class, new StringMultipartFileEditor()); @@ -289,7 +289,7 @@ public void testMultipartFilesAsStringArray() { } @Test - public void testNoPrefix() throws Exception { + void testNoPrefix() { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("forname", "Tony"); request.addParameter("surname", "Blair"); @@ -300,7 +300,7 @@ public void testNoPrefix() throws Exception { } @Test - public void testPrefix() throws Exception { + void testPrefix() { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("test_forname", "Tony"); request.addParameter("test_surname", "Blair"); @@ -318,7 +318,7 @@ public void testPrefix() throws Exception { /** * Must contain: forname=Tony surname=Blair age=50 */ - protected void doTestTony(PropertyValues pvs) throws Exception { + protected void doTestTony(PropertyValues pvs) { assertThat(pvs.getPropertyValues().length).as("Contains 3").isEqualTo(3); assertThat(pvs.contains("forname")).as("Contains forname").isTrue(); assertThat(pvs.contains("surname")).as("Contains surname").isTrue(); @@ -343,14 +343,14 @@ protected void doTestTony(PropertyValues pvs) throws Exception { } @Test - public void testNoParameters() throws Exception { + void testNoParameters() { MockHttpServletRequest request = new MockHttpServletRequest(); ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request); assertThat(pvs.getPropertyValues().length).as("Found no parameters").isEqualTo(0); } @Test - public void testMultipleValuesForParameter() throws Exception { + void testMultipleValuesForParameter() { MockHttpServletRequest request = new MockHttpServletRequest(); String[] original = new String[] {"Tony", "Rod"}; request.addParameter("forname", original); diff --git a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java index 0fae323330ce..640abf0b877c 100644 --- a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java @@ -42,7 +42,7 @@ * @author Juergen Hoeller * @author Denys Ivano */ -public class DefaultResponseErrorHandlerTests { +class DefaultResponseErrorHandlerTests { private final DefaultResponseErrorHandler handler = new DefaultResponseErrorHandler(); @@ -50,19 +50,19 @@ public class DefaultResponseErrorHandlerTests { @Test - public void hasErrorTrue() throws Exception { + void hasErrorTrue() throws Exception { given(response.getStatusCode()).willReturn(HttpStatus.NOT_FOUND); assertThat(handler.hasError(response)).isTrue(); } @Test - public void hasErrorFalse() throws Exception { + void hasErrorFalse() throws Exception { given(response.getStatusCode()).willReturn(HttpStatus.OK); assertThat(handler.hasError(response)).isFalse(); } @Test - public void handleError() throws Exception { + void handleError() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); @@ -78,7 +78,7 @@ public void handleError() throws Exception { } @Test - public void handleErrorIOException() throws Exception { + void handleErrorIOException() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); @@ -91,7 +91,7 @@ public void handleErrorIOException() throws Exception { } @Test - public void handleErrorNullResponse() throws Exception { + void handleErrorNullResponse() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); @@ -141,7 +141,7 @@ public void hasErrorForCustomClientError() throws Exception { } @Test - public void handleErrorForCustomClientError() throws Exception { + void handleErrorForCustomClientError() throws Exception { HttpStatusCode statusCode = HttpStatusCode.valueOf(499); String statusText = "Custom status code"; @@ -181,7 +181,7 @@ public void hasErrorForCustomServerError() throws Exception { } @Test - public void handleErrorForCustomServerError() throws Exception { + void handleErrorForCustomServerError() throws Exception { HttpStatusCode statusCode = HttpStatusCode.valueOf(599); String statusText = "Custom status code"; diff --git a/spring-web/src/test/java/org/springframework/web/client/ExtractingResponseErrorHandlerTests.java b/spring-web/src/test/java/org/springframework/web/client/ExtractingResponseErrorHandlerTests.java index 3f8c76797635..e28b623cf5e4 100644 --- a/spring-web/src/test/java/org/springframework/web/client/ExtractingResponseErrorHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/ExtractingResponseErrorHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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,7 +38,7 @@ /** * @author Arjen Poutsma */ -public class ExtractingResponseErrorHandlerTests { +class ExtractingResponseErrorHandlerTests { private ExtractingResponseErrorHandler errorHandler; @@ -46,7 +46,7 @@ public class ExtractingResponseErrorHandlerTests { @BeforeEach - public void setup() { + void setup() { HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); this.errorHandler = new ExtractingResponseErrorHandler( Collections.singletonList(converter)); @@ -59,7 +59,7 @@ public void setup() { @Test - public void hasError() throws Exception { + void hasError() throws Exception { given(this.response.getStatusCode()).willReturn(HttpStatus.I_AM_A_TEAPOT); assertThat(this.errorHandler.hasError(this.response)).isTrue(); @@ -71,7 +71,7 @@ public void hasError() throws Exception { } @Test - public void hasErrorOverride() throws Exception { + void hasErrorOverride() throws Exception { this.errorHandler.setSeriesMapping(Collections .singletonMap(HttpStatus.Series.CLIENT_ERROR, null)); @@ -86,7 +86,7 @@ public void hasErrorOverride() throws Exception { } @Test - public void handleErrorStatusMatch() throws Exception { + void handleErrorStatusMatch() throws Exception { given(this.response.getStatusCode()).willReturn(HttpStatus.I_AM_A_TEAPOT); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setContentType(MediaType.APPLICATION_JSON); @@ -102,7 +102,7 @@ public void handleErrorStatusMatch() throws Exception { } @Test - public void handleErrorSeriesMatch() throws Exception { + void handleErrorSeriesMatch() throws Exception { given(this.response.getStatusCode()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setContentType(MediaType.APPLICATION_JSON); @@ -118,7 +118,7 @@ public void handleErrorSeriesMatch() throws Exception { } @Test - public void handleNoMatch() throws Exception { + void handleNoMatch() throws Exception { given(this.response.getStatusCode()).willReturn(HttpStatus.NOT_FOUND); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setContentType(MediaType.APPLICATION_JSON); @@ -137,7 +137,7 @@ public void handleNoMatch() throws Exception { } @Test - public void handleNoMatchOverride() throws Exception { + void handleNoMatchOverride() throws Exception { this.errorHandler.setSeriesMapping(Collections .singletonMap(HttpStatus.Series.CLIENT_ERROR, null)); diff --git a/spring-web/src/test/java/org/springframework/web/client/HttpMessageConverterExtractorTests.java b/spring-web/src/test/java/org/springframework/web/client/HttpMessageConverterExtractorTests.java index 5b1a764ebcf8..d5de3c8b0c8c 100644 --- a/spring-web/src/test/java/org/springframework/web/client/HttpMessageConverterExtractorTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/HttpMessageConverterExtractorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -34,7 +34,6 @@ import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageNotReadableException; -import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; @@ -52,9 +51,8 @@ */ class HttpMessageConverterExtractorTests { - @SuppressWarnings("unchecked") private final HttpMessageConverter converter = mock(); - private final HttpMessageConverterExtractor extractor = new HttpMessageConverterExtractor<>(String.class, asList(converter)); + private final HttpMessageConverterExtractor extractor = new HttpMessageConverterExtractor<>(String.class, List.of(converter)); private final MediaType contentType = MediaType.TEXT_PLAIN; private final HttpHeaders responseHeaders = new HttpHeaders(); private final ClientHttpResponse response = mock(); @@ -63,7 +61,7 @@ class HttpMessageConverterExtractorTests { @Test void constructorPreconditions() { assertThatIllegalArgumentException() - .isThrownBy(() -> new HttpMessageConverterExtractor<>(String.class, (List>) null)) + .isThrownBy(() -> new HttpMessageConverterExtractor<>(String.class, null)) .withMessage("'messageConverters' must not be empty"); assertThatIllegalArgumentException() .isThrownBy(() -> new HttpMessageConverterExtractor<>(String.class, Arrays.asList(null, this.converter))) @@ -149,7 +147,6 @@ void cannotRead() throws IOException { } @Test - @SuppressWarnings("unchecked") void generics() throws IOException { responseHeaders.setContentType(contentType); String expected = "Foo"; @@ -157,7 +154,7 @@ void generics() throws IOException { Type type = reference.getType(); GenericHttpMessageConverter converter = mock(); - HttpMessageConverterExtractor extractor = new HttpMessageConverterExtractor>(type, asList(converter)); + HttpMessageConverterExtractor extractor = new HttpMessageConverterExtractor>(type, List.of(converter)); given(response.getStatusCode()).willReturn(HttpStatus.OK); given(response.getHeaders()).willReturn(responseHeaders); diff --git a/spring-web/src/test/java/org/springframework/web/client/HttpStatusCodeExceptionTests.java b/spring-web/src/test/java/org/springframework/web/client/HttpStatusCodeExceptionTests.java index 98046a371d50..215c15a7220c 100644 --- a/spring-web/src/test/java/org/springframework/web/client/HttpStatusCodeExceptionTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/HttpStatusCodeExceptionTests.java @@ -34,7 +34,7 @@ * * @author Chris Beams */ -public class HttpStatusCodeExceptionTests { +class HttpStatusCodeExceptionTests { /** * Corners bug SPR-9273, which reported the fact that following the changes made in @@ -42,7 +42,7 @@ public class HttpStatusCodeExceptionTests { * serializable due to the addition of a non-serializable {@code Charset} field. */ @Test - public void testSerializability() throws IOException, ClassNotFoundException { + void testSerializability() throws IOException, ClassNotFoundException { HttpStatusCodeException ex1 = new HttpClientErrorException( HttpStatus.BAD_REQUEST, null, null, StandardCharsets.US_ASCII); ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -54,7 +54,7 @@ public void testSerializability() throws IOException, ClassNotFoundException { } @Test - public void emptyStatusText() { + void emptyStatusText() { HttpStatusCodeException ex = new HttpClientErrorException(HttpStatus.NOT_FOUND, ""); assertThat(ex.getMessage()).isEqualTo("404 Not Found"); diff --git a/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java b/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java index 9e20db92c327..92424a251d25 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -349,7 +349,6 @@ void retrieveJsonNull(ClientHttpRequestFactory requestFactory) { } @ParameterizedRestClientTest - @SuppressWarnings({ "rawtypes", "unchecked" }) void retrieveJsonEmpty(ClientHttpRequestFactory requestFactory) { startServer(requestFactory); diff --git a/spring-web/src/test/java/org/springframework/web/client/RestClientObservationTests.java b/spring-web/src/test/java/org/springframework/web/client/RestClientObservationTests.java index 3dd6c5f87a25..f3d38950c49d 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestClientObservationTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestClientObservationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -66,7 +66,6 @@ class RestClientObservationTests { private final ResponseErrorHandler errorHandler = mock(); - @SuppressWarnings("unchecked") private final HttpMessageConverter converter = mock(); private RestClient client; diff --git a/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java b/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java index 7e8829e27572..6f20c7ff1101 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -168,11 +168,11 @@ void getNoResponse(ClientHttpRequestFactory clientHttpRequestFactory) { } @ParameterizedRestTemplateTest - void getNoContentTypeHeader(ClientHttpRequestFactory clientHttpRequestFactory) throws Exception { + void getNoContentTypeHeader(ClientHttpRequestFactory clientHttpRequestFactory) { setUpClient(clientHttpRequestFactory); byte[] bytes = template.getForObject(baseUrl + "/get/nocontenttype", byte[].class); - assertThat(bytes).as("Invalid content").isEqualTo(helloWorld.getBytes("UTF-8")); + assertThat(bytes).as("Invalid content").isEqualTo(helloWorld.getBytes(StandardCharsets.UTF_8)); } @ParameterizedRestTemplateTest @@ -200,7 +200,7 @@ void getNotModified(ClientHttpRequestFactory clientHttpRequestFactory) { } @ParameterizedRestTemplateTest - void postForLocation(ClientHttpRequestFactory clientHttpRequestFactory) throws Exception { + void postForLocation(ClientHttpRequestFactory clientHttpRequestFactory) { setUpClient(clientHttpRequestFactory); URI location = template.postForLocation(baseUrl + "/{method}", helloWorld, "post"); @@ -208,7 +208,7 @@ void postForLocation(ClientHttpRequestFactory clientHttpRequestFactory) throws E } @ParameterizedRestTemplateTest - void postForLocationEntity(ClientHttpRequestFactory clientHttpRequestFactory) throws Exception { + void postForLocationEntity(ClientHttpRequestFactory clientHttpRequestFactory) { setUpClient(clientHttpRequestFactory); HttpHeaders entityHeaders = new HttpHeaders(); @@ -219,7 +219,7 @@ void postForLocationEntity(ClientHttpRequestFactory clientHttpRequestFactory) th } @ParameterizedRestTemplateTest - void postForObject(ClientHttpRequestFactory clientHttpRequestFactory) throws Exception { + void postForObject(ClientHttpRequestFactory clientHttpRequestFactory) { setUpClient(clientHttpRequestFactory); String s = template.postForObject(baseUrl + "/{method}", helloWorld, String.class, "post"); @@ -227,7 +227,7 @@ void postForObject(ClientHttpRequestFactory clientHttpRequestFactory) throws Exc } @ParameterizedRestTemplateTest - void patchForObject(ClientHttpRequestFactory clientHttpRequestFactory) throws Exception { + void patchForObject(ClientHttpRequestFactory clientHttpRequestFactory) { assumeFalse(clientHttpRequestFactory instanceof SimpleClientHttpRequestFactory, "HttpURLConnection does not support the PATCH method"); @@ -277,7 +277,7 @@ void serverError(ClientHttpRequestFactory clientHttpRequestFactory) { } @ParameterizedRestTemplateTest - void optionsForAllow(ClientHttpRequestFactory clientHttpRequestFactory) throws Exception { + void optionsForAllow(ClientHttpRequestFactory clientHttpRequestFactory) { setUpClient(clientHttpRequestFactory); Set allowed = template.optionsForAllow(URI.create(baseUrl + "/get")); @@ -285,7 +285,7 @@ void optionsForAllow(ClientHttpRequestFactory clientHttpRequestFactory) throws E } @ParameterizedRestTemplateTest - void uri(ClientHttpRequestFactory clientHttpRequestFactory) throws Exception { + void uri(ClientHttpRequestFactory clientHttpRequestFactory) { setUpClient(clientHttpRequestFactory); String result = template.getForObject(baseUrl + "/uri/{query}", String.class, "Z\u00fcrich"); @@ -306,7 +306,7 @@ void multipartFormData(ClientHttpRequestFactory clientHttpRequestFactory) { } @ParameterizedRestTemplateTest - void multipartMixed(ClientHttpRequestFactory clientHttpRequestFactory) throws Exception { + void multipartMixed(ClientHttpRequestFactory clientHttpRequestFactory) { setUpClient(clientHttpRequestFactory); HttpHeaders requestHeaders = new HttpHeaders(); @@ -357,7 +357,7 @@ void form(ClientHttpRequestFactory clientHttpRequestFactory) { } @ParameterizedRestTemplateTest - void exchangeGet(ClientHttpRequestFactory clientHttpRequestFactory) throws Exception { + void exchangeGet(ClientHttpRequestFactory clientHttpRequestFactory) { setUpClient(clientHttpRequestFactory); HttpHeaders requestHeaders = new HttpHeaders(); @@ -369,7 +369,7 @@ void exchangeGet(ClientHttpRequestFactory clientHttpRequestFactory) throws Excep } @ParameterizedRestTemplateTest - void exchangePost(ClientHttpRequestFactory clientHttpRequestFactory) throws Exception { + void exchangePost(ClientHttpRequestFactory clientHttpRequestFactory) { setUpClient(clientHttpRequestFactory); HttpHeaders requestHeaders = new HttpHeaders(); @@ -382,7 +382,7 @@ void exchangePost(ClientHttpRequestFactory clientHttpRequestFactory) throws Exce } @ParameterizedRestTemplateTest - void jsonPostForObject(ClientHttpRequestFactory clientHttpRequestFactory) throws Exception { + void jsonPostForObject(ClientHttpRequestFactory clientHttpRequestFactory) { setUpClient(clientHttpRequestFactory); HttpHeaders entityHeaders = new HttpHeaders(); @@ -399,7 +399,7 @@ void jsonPostForObject(ClientHttpRequestFactory clientHttpRequestFactory) throws } @ParameterizedRestTemplateTest - void jsonPostForObjectWithJacksonView(ClientHttpRequestFactory clientHttpRequestFactory) throws Exception { + void jsonPostForObjectWithJacksonView(ClientHttpRequestFactory clientHttpRequestFactory) { setUpClient(clientHttpRequestFactory); HttpHeaders entityHeaders = new HttpHeaders(); @@ -423,7 +423,7 @@ void serverPort(ClientHttpRequestFactory clientHttpRequestFactory) { } @ParameterizedRestTemplateTest // SPR-13154 - void jsonPostForObjectWithJacksonTypeInfoList(ClientHttpRequestFactory clientHttpRequestFactory) throws Exception { + void jsonPostForObjectWithJacksonTypeInfoList(ClientHttpRequestFactory clientHttpRequestFactory) { setUpClient(clientHttpRequestFactory); List list = new ArrayList<>(); @@ -440,7 +440,7 @@ void jsonPostForObjectWithJacksonTypeInfoList(ClientHttpRequestFactory clientHtt } @ParameterizedRestTemplateTest // SPR-15015 - void postWithoutBody(ClientHttpRequestFactory clientHttpRequestFactory) throws Exception { + void postWithoutBody(ClientHttpRequestFactory clientHttpRequestFactory) { setUpClient(clientHttpRequestFactory); assertThat(template.postForObject(baseUrl + "/jsonpost", null, String.class)).isNull(); diff --git a/spring-web/src/test/java/org/springframework/web/client/RestTemplateObservationTests.java b/spring-web/src/test/java/org/springframework/web/client/RestTemplateObservationTests.java index 97eb7fc5fef9..f1a9eb10ee11 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestTemplateObservationTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestTemplateObservationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -66,7 +66,6 @@ class RestTemplateObservationTests { private final ResponseErrorHandler errorHandler = mock(); - @SuppressWarnings("unchecked") private final HttpMessageConverter converter = mock(); private final RestTemplate template = new RestTemplate(List.of(converter)); diff --git a/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java b/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java index dbc7ed70fe3a..6cb5e2b52e9c 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java @@ -105,7 +105,6 @@ void setup() { @Test // gh-29008 void defaultMessageConvertersWithKotlinSerialization() { - @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); List> httpMessageConverters = restTemplate.getMessageConverters(); assertThat(httpMessageConverters).extracting("class").containsOnlyOnce( @@ -127,7 +126,7 @@ void constructorPreconditions() { @Test void setMessageConvertersPreconditions() { assertThatIllegalArgumentException() - .isThrownBy(() -> template.setMessageConverters((List>) null)) + .isThrownBy(() -> template.setMessageConverters(null)) .withMessage("At least one HttpMessageConverter is required"); assertThatIllegalArgumentException() .isThrownBy(() -> template.setMessageConverters(Arrays.asList(null, this.converter))) @@ -524,9 +523,7 @@ void keepGivenAcceptHeaderOnPut() throws Exception { .map(Entry::getValue) .toList(); - assertThat(accepts).hasSize(1); - assertThat(accepts).element(0).asList().hasSize(1); - assertThat(accepts.get(0)).element(0).isEqualTo("application/json"); + assertThat(accepts).singleElement().isEqualTo(List.of("application/json")); } } @@ -655,7 +652,7 @@ void exchange() throws Exception { @SuppressWarnings("rawtypes") void exchangeParameterizedType() throws Exception { GenericHttpMessageConverter converter = mock(); - template.setMessageConverters(Collections.>singletonList(converter)); + template.setMessageConverters(Collections.singletonList(converter)); ParameterizedTypeReference> intList = new ParameterizedTypeReference<>() {}; given(converter.canRead(intList.getType(), null, null)).willReturn(true); given(converter.getSupportedMediaTypes(any())).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN)); @@ -766,7 +763,7 @@ private void mockSentRequest(HttpMethod method, String uri, HttpHeaders requestH given(request.getHeaders()).willReturn(requestHeaders); } - @SuppressWarnings({ "deprecation", "removal" }) + @SuppressWarnings("removal") private void mockResponseStatus(HttpStatus responseStatus) throws Exception { given(request.execute()).willReturn(response); given(errorHandler.hasError(response)).willReturn(responseStatus.isError()); diff --git a/spring-web/src/test/java/org/springframework/web/context/ContextLoaderInitializerTests.java b/spring-web/src/test/java/org/springframework/web/context/ContextLoaderInitializerTests.java index 5bd5599aa97f..0544e8d2e899 100644 --- a/spring-web/src/test/java/org/springframework/web/context/ContextLoaderInitializerTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/ContextLoaderInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -34,7 +34,7 @@ * * @author Arjen Poutsma */ -public class ContextLoaderInitializerTests { +class ContextLoaderInitializerTests { private static final String BEAN_NAME = "myBean"; @@ -45,14 +45,14 @@ public class ContextLoaderInitializerTests { private EventListener eventListener; @BeforeEach - public void setUp() throws Exception { + void setUp() { servletContext = new MyMockServletContext(); initializer = new MyContextLoaderInitializer(); eventListener = null; } @Test - public void register() throws ServletException { + void register() throws ServletException { initializer.onStartup(servletContext); boolean condition1 = eventListener instanceof ContextLoaderListener; diff --git a/spring-web/src/test/java/org/springframework/web/context/request/RequestAndSessionScopedBeanTests.java b/spring-web/src/test/java/org/springframework/web/context/request/RequestAndSessionScopedBeanTests.java index 23613401695f..ab4f434bbca5 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/RequestAndSessionScopedBeanTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/RequestAndSessionScopedBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 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. @@ -33,10 +33,9 @@ * @author Rod Johnson * @author Juergen Hoeller */ -public class RequestAndSessionScopedBeanTests { +class RequestAndSessionScopedBeanTests { @Test - @SuppressWarnings("resource") public void testPutBeanInRequest() { String targetBeanName = "target"; @@ -71,7 +70,6 @@ public void testPutBeanInRequest() { } @Test - @SuppressWarnings("resource") public void testPutBeanInSession() { String targetBeanName = "target"; HttpServletRequest request = new MockHttpServletRequest(); diff --git a/spring-web/src/test/java/org/springframework/web/context/request/RequestContextListenerTests.java b/spring-web/src/test/java/org/springframework/web/context/request/RequestContextListenerTests.java index 84487b927d41..b433af80d61a 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/RequestContextListenerTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/RequestContextListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -28,10 +28,10 @@ /** * @author Juergen Hoeller */ -public class RequestContextListenerTests { +class RequestContextListenerTests { @Test - public void requestContextListenerWithSameThread() { + void requestContextListenerWithSameThread() { RequestContextListener listener = new RequestContextListener(); MockServletContext context = new MockServletContext(); MockHttpServletRequest request = new MockHttpServletRequest(context); @@ -51,7 +51,7 @@ public void requestContextListenerWithSameThread() { } @Test - public void requestContextListenerWithSameThreadAndAttributesGone() { + void requestContextListenerWithSameThreadAndAttributesGone() { RequestContextListener listener = new RequestContextListener(); MockServletContext context = new MockServletContext(); MockHttpServletRequest request = new MockHttpServletRequest(context); @@ -72,7 +72,7 @@ public void requestContextListenerWithSameThreadAndAttributesGone() { } @Test - public void requestContextListenerWithDifferentThread() { + void requestContextListenerWithDifferentThread() { final RequestContextListener listener = new RequestContextListener(); final MockServletContext context = new MockServletContext(); final MockHttpServletRequest request = new MockHttpServletRequest(context); @@ -87,12 +87,8 @@ public void requestContextListenerWithDifferentThread() { "test", runnable, RequestAttributes.SCOPE_REQUEST); // Execute requestDestroyed callback in different thread. - Thread thread = new Thread() { - @Override - public void run() { - listener.requestDestroyed(new ServletRequestEvent(context, request)); - } - }; + Thread thread = new Thread(() -> listener.requestDestroyed( + new ServletRequestEvent(context, request))); thread.start(); try { thread.join(); diff --git a/spring-web/src/test/java/org/springframework/web/context/request/RequestScopeTests.java b/spring-web/src/test/java/org/springframework/web/context/request/RequestScopeTests.java index 30a48143cc3b..404f0d70d882 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/RequestScopeTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/RequestScopeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -44,13 +44,13 @@ * @author Sam Brannen * @see SessionScopeTests */ -public class RequestScopeTests { +class RequestScopeTests { private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); @BeforeEach - public void setup() { + void setup() { this.beanFactory.registerScope("request", new RequestScope()); this.beanFactory.setBeanExpressionResolver(new StandardBeanExpressionResolver()); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory); @@ -59,13 +59,13 @@ public void setup() { } @AfterEach - public void resetRequestAttributes() { + void resetRequestAttributes() { RequestContextHolder.setRequestAttributes(null); } @Test - public void getFromScope() { + void getFromScope() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setContextPath("/path"); RequestAttributes requestAttributes = new ServletRequestAttributes(request); @@ -80,7 +80,7 @@ public void getFromScope() { } @Test - public void destructionAtRequestCompletion() { + void destructionAtRequestCompletion() { MockHttpServletRequest request = new MockHttpServletRequest(); ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes); @@ -96,7 +96,7 @@ public void destructionAtRequestCompletion() { } @Test - public void getFromFactoryBeanInScope() { + void getFromFactoryBeanInScope() { MockHttpServletRequest request = new MockHttpServletRequest(); RequestAttributes requestAttributes = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes); @@ -110,7 +110,7 @@ public void getFromFactoryBeanInScope() { } @Test - public void circleLeadsToException() { + void circleLeadsToException() { MockHttpServletRequest request = new MockHttpServletRequest(); RequestAttributes requestAttributes = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes); @@ -123,7 +123,7 @@ public void circleLeadsToException() { } @Test - public void innerBeanInheritsContainingBeanScopeByDefault() { + void innerBeanInheritsContainingBeanScopeByDefault() { MockHttpServletRequest request = new MockHttpServletRequest(); ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes); @@ -146,7 +146,7 @@ public void innerBeanInheritsContainingBeanScopeByDefault() { } @Test - public void requestScopedInnerBeanDestroyedWhileContainedBySingleton() { + void requestScopedInnerBeanDestroyedWhileContainedBySingleton() { MockHttpServletRequest request = new MockHttpServletRequest(); ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes); @@ -164,7 +164,7 @@ public void requestScopedInnerBeanDestroyedWhileContainedBySingleton() { } @Test - public void scopeNotAvailable() { + void scopeNotAvailable() { assertThatExceptionOfType(ScopeNotActiveException.class).isThrownBy( () -> this.beanFactory.getBean(CountingTestBean.class)); diff --git a/spring-web/src/test/java/org/springframework/web/context/request/RequestScopedProxyTests.java b/spring-web/src/test/java/org/springframework/web/context/request/RequestScopedProxyTests.java index 65605e1a47e5..fde0951604f0 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/RequestScopedProxyTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/RequestScopedProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -40,13 +40,13 @@ /** * @author Juergen Hoeller */ -public class RequestScopedProxyTests { +class RequestScopedProxyTests { private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); @BeforeEach - public void setup() { + void setup() { this.beanFactory.registerScope("request", new RequestScope()); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory); reader.loadBeanDefinitions(new ClassPathResource("requestScopedProxyTests.xml", getClass())); @@ -55,7 +55,7 @@ public void setup() { @Test - public void testGetFromScope() { + void testGetFromScope() { String name = "requestScopedObject"; TestBean bean = (TestBean) this.beanFactory.getBean(name); assertThat(AopUtils.isCglibProxy(bean)).isTrue(); @@ -80,7 +80,7 @@ public void testGetFromScope() { } @Test - public void testGetFromScopeThroughDynamicProxy() { + void testGetFromScopeThroughDynamicProxy() { String name = "requestScopedProxy"; ITestBean bean = (ITestBean) this.beanFactory.getBean(name); // assertTrue(AopUtils.isJdkDynamicProxy(bean)); @@ -105,7 +105,7 @@ public void testGetFromScopeThroughDynamicProxy() { } @Test - public void testDestructionAtRequestCompletion() { + void testDestructionAtRequestCompletion() { String name = "requestScopedDisposableObject"; DerivedTestBean bean = (DerivedTestBean) this.beanFactory.getBean(name); assertThat(AopUtils.isCglibProxy(bean)).isTrue(); @@ -131,7 +131,7 @@ public void testDestructionAtRequestCompletion() { } @Test - public void testGetFromFactoryBeanInScope() { + void testGetFromFactoryBeanInScope() { String name = "requestScopedFactoryBean"; TestBean bean = (TestBean) this.beanFactory.getBean(name); assertThat(AopUtils.isCglibProxy(bean)).isTrue(); @@ -153,7 +153,7 @@ public void testGetFromFactoryBeanInScope() { } @Test - public void testGetInnerBeanFromScope() { + void testGetInnerBeanFromScope() { TestBean bean = (TestBean) this.beanFactory.getBean("outerBean"); assertThat(AopUtils.isAopProxy(bean)).isFalse(); assertThat(AopUtils.isCglibProxy(bean.getSpouse())).isTrue(); @@ -177,7 +177,7 @@ public void testGetInnerBeanFromScope() { } @Test - public void testGetAnonymousInnerBeanFromScope() { + void testGetAnonymousInnerBeanFromScope() { TestBean bean = (TestBean) this.beanFactory.getBean("outerBean"); assertThat(AopUtils.isAopProxy(bean)).isFalse(); assertThat(AopUtils.isCglibProxy(bean.getSpouse())).isTrue(); @@ -204,7 +204,7 @@ public void testGetAnonymousInnerBeanFromScope() { } @Test - public void scopeNotAvailable() { + void scopeNotAvailable() { assertThatExceptionOfType(ScopeNotActiveException.class).isThrownBy( () -> this.beanFactory.getBean(CountingTestBean.class).absquatulate()); diff --git a/spring-web/src/test/java/org/springframework/web/context/request/ServletRequestAttributesTests.java b/spring-web/src/test/java/org/springframework/web/context/request/ServletRequestAttributesTests.java index 24a5d82ef32c..27b1ebbc5436 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/ServletRequestAttributesTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/ServletRequestAttributesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -40,7 +40,7 @@ * @author Rick Evans * @author Juergen Hoeller */ -public class ServletRequestAttributesTests { +class ServletRequestAttributesTests { private static final String KEY = "ThatThingThatThing"; @@ -50,13 +50,13 @@ public class ServletRequestAttributesTests { @Test - public void ctorRejectsNullArg() { + void ctorRejectsNullArg() { assertThatIllegalArgumentException().isThrownBy(() -> new ServletRequestAttributes(null)); } @Test - public void setRequestScopedAttribute() { + void setRequestScopedAttribute() { MockHttpServletRequest request = new MockHttpServletRequest(); ServletRequestAttributes attrs = new ServletRequestAttributes(request); attrs.setAttribute(KEY, VALUE, RequestAttributes.SCOPE_REQUEST); @@ -65,7 +65,7 @@ public void setRequestScopedAttribute() { } @Test - public void setRequestScopedAttributeAfterCompletion() { + void setRequestScopedAttributeAfterCompletion() { MockHttpServletRequest request = new MockHttpServletRequest(); ServletRequestAttributes attrs = new ServletRequestAttributes(request); request.close(); @@ -74,7 +74,7 @@ public void setRequestScopedAttributeAfterCompletion() { } @Test - public void setSessionScopedAttribute() { + void setSessionScopedAttribute() { MockHttpSession session = new MockHttpSession(); session.setAttribute(KEY, VALUE); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -85,7 +85,7 @@ public void setSessionScopedAttribute() { } @Test - public void setSessionScopedAttributeAfterCompletion() { + void setSessionScopedAttributeAfterCompletion() { MockHttpSession session = new MockHttpSession(); session.setAttribute(KEY, VALUE); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -99,7 +99,7 @@ public void setSessionScopedAttributeAfterCompletion() { } @Test - public void getSessionScopedAttributeDoesNotForceCreationOfSession() { + void getSessionScopedAttributeDoesNotForceCreationOfSession() { HttpServletRequest request = mock(); ServletRequestAttributes attrs = new ServletRequestAttributes(request); @@ -109,7 +109,7 @@ public void getSessionScopedAttributeDoesNotForceCreationOfSession() { } @Test - public void removeSessionScopedAttribute() { + void removeSessionScopedAttribute() { MockHttpSession session = new MockHttpSession(); session.setAttribute(KEY, VALUE); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -121,7 +121,7 @@ public void removeSessionScopedAttribute() { } @Test - public void removeSessionScopedAttributeDoesNotForceCreationOfSession() { + void removeSessionScopedAttributeDoesNotForceCreationOfSession() { HttpServletRequest request = mock(); ServletRequestAttributes attrs = new ServletRequestAttributes(request); @@ -130,7 +130,7 @@ public void removeSessionScopedAttributeDoesNotForceCreationOfSession() { } @Test - public void updateAccessedAttributes() { + void updateAccessedAttributes() { HttpServletRequest request = mock(); HttpSession session = mock(); given(request.getSession(anyBoolean())).willReturn(session); @@ -146,32 +146,32 @@ public void updateAccessedAttributes() { } @Test - public void skipImmutableString() { + void skipImmutableString() { doSkipImmutableValue("someString"); } @Test - public void skipImmutableCharacter() { + void skipImmutableCharacter() { doSkipImmutableValue('x'); } @Test - public void skipImmutableBoolean() { + void skipImmutableBoolean() { doSkipImmutableValue(Boolean.TRUE); } @Test - public void skipImmutableInteger() { + void skipImmutableInteger() { doSkipImmutableValue(1); } @Test - public void skipImmutableFloat() { + void skipImmutableFloat() { doSkipImmutableValue(1.1F); } @Test - public void skipImmutableBigInteger() { + void skipImmutableBigInteger() { doSkipImmutableValue(new BigInteger("1")); } diff --git a/spring-web/src/test/java/org/springframework/web/context/request/ServletWebRequestTests.java b/spring-web/src/test/java/org/springframework/web/context/request/ServletWebRequestTests.java index 3eac9237f328..3ea85ae691f5 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/ServletWebRequestTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/ServletWebRequestTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -37,7 +37,7 @@ /** * @author Juergen Hoeller */ -public class ServletWebRequestTests { +class ServletWebRequestTests { private MockHttpServletRequest servletRequest; @@ -47,7 +47,7 @@ public class ServletWebRequestTests { @BeforeEach - public void setup() { + void setup() { servletRequest = new MockHttpServletRequest(); servletResponse = new MockHttpServletResponse(); request = new ServletWebRequest(servletRequest, servletResponse); @@ -55,18 +55,15 @@ public void setup() { @Test - public void parameters() { + void parameters() { servletRequest.addParameter("param1", "value1"); servletRequest.addParameter("param2", "value2"); servletRequest.addParameter("param2", "value2a"); assertThat(request.getParameter("param1")).isEqualTo("value1"); - assertThat(request.getParameterValues("param1")).hasSize(1); - assertThat(request.getParameterValues("param1")[0]).isEqualTo("value1"); + assertThat(request.getParameterValues("param1")).containsExactly("value1"); assertThat(request.getParameter("param2")).isEqualTo("value2"); - assertThat(request.getParameterValues("param2")).hasSize(2); - assertThat(request.getParameterValues("param2")[0]).isEqualTo("value2"); - assertThat(request.getParameterValues("param2")[1]).isEqualTo("value2a"); + assertThat(request.getParameterValues("param2")).containsExactly("value2", "value2a"); Map paramMap = request.getParameterMap(); assertThat(paramMap).hasSize(2); @@ -78,14 +75,14 @@ public void parameters() { } @Test - public void locale() { + void locale() { servletRequest.addPreferredLocale(Locale.UK); assertThat(request.getLocale()).isEqualTo(Locale.UK); } @Test - public void nativeRequest() { + void nativeRequest() { assertThat(request.getNativeRequest()).isSameAs(servletRequest); assertThat(request.getNativeRequest(ServletRequest.class)).isSameAs(servletRequest); assertThat(request.getNativeRequest(HttpServletRequest.class)).isSameAs(servletRequest); @@ -99,7 +96,7 @@ public void nativeRequest() { } @Test - public void decoratedNativeRequest() { + void decoratedNativeRequest() { HttpServletRequest decoratedRequest = new HttpServletRequestWrapper(servletRequest); HttpServletResponse decoratedResponse = new HttpServletResponseWrapper(servletResponse); ServletWebRequest request = new ServletWebRequest(decoratedRequest, decoratedResponse); diff --git a/spring-web/src/test/java/org/springframework/web/context/request/SessionScopeTests.java b/spring-web/src/test/java/org/springframework/web/context/request/SessionScopeTests.java index 62d8f4cb6e98..aeeb63262cf2 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/SessionScopeTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/SessionScopeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -43,26 +43,26 @@ * @author Sam Brannen * @see RequestScopeTests */ -public class SessionScopeTests { +class SessionScopeTests { private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); @BeforeEach - public void setup() throws Exception { + void setup() { this.beanFactory.registerScope("session", new SessionScope()); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory); reader.loadBeanDefinitions(new ClassPathResource("sessionScopeTests.xml", getClass())); } @AfterEach - public void resetRequestAttributes() { + void resetRequestAttributes() { RequestContextHolder.setRequestAttributes(null); } @Test - public void getFromScope() throws Exception { + void getFromScope() { AtomicInteger count = new AtomicInteger(); MockHttpSession session = new MockHttpSession() { @Override @@ -91,7 +91,7 @@ public void setAttribute(String name, Object value) { } @Test - public void getFromScopeWithSingleAccess() throws Exception { + void getFromScopeWithSingleAccess() { AtomicInteger count = new AtomicInteger(); MockHttpSession session = new MockHttpSession() { @Override @@ -117,7 +117,7 @@ public void setAttribute(String name, Object value) { } @Test - public void destructionAtSessionTermination() throws Exception { + void destructionAtSessionTermination() { MockHttpSession session = new MockHttpSession(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); @@ -136,18 +136,18 @@ public void destructionAtSessionTermination() throws Exception { } @Test - public void destructionWithSessionSerialization() throws Exception { + void destructionWithSessionSerialization() throws Exception { doTestDestructionWithSessionSerialization(false); } @Test - public void destructionWithSessionSerializationAndBeanPostProcessor() throws Exception { + void destructionWithSessionSerializationAndBeanPostProcessor() throws Exception { this.beanFactory.addBeanPostProcessor(new CustomDestructionAwareBeanPostProcessor()); doTestDestructionWithSessionSerialization(false); } @Test - public void destructionWithSessionSerializationAndSerializableBeanPostProcessor() throws Exception { + void destructionWithSessionSerializationAndSerializableBeanPostProcessor() throws Exception { this.beanFactory.addBeanPostProcessor(new CustomSerializableDestructionAwareBeanPostProcessor()); doTestDestructionWithSessionSerialization(true); } diff --git a/spring-web/src/test/java/org/springframework/web/context/request/WebApplicationContextScopeTests.java b/spring-web/src/test/java/org/springframework/web/context/request/WebApplicationContextScopeTests.java index 4f4a3a1d8f23..4bde1b54da98 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/WebApplicationContextScopeTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/WebApplicationContextScopeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -32,7 +32,7 @@ /** * @author Juergen Hoeller */ -public class WebApplicationContextScopeTests { +class WebApplicationContextScopeTests { private static final String NAME = "scoped"; @@ -49,7 +49,7 @@ private WebApplicationContext initApplicationContext(String scope) { } @Test - public void testRequestScope() { + void testRequestScope() { WebApplicationContext ac = initApplicationContext(WebApplicationContext.SCOPE_REQUEST); MockHttpServletRequest request = new MockHttpServletRequest(); ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request); @@ -68,7 +68,7 @@ public void testRequestScope() { } @Test - public void testSessionScope() { + void testSessionScope() { WebApplicationContext ac = initApplicationContext(WebApplicationContext.SCOPE_SESSION); MockHttpServletRequest request = new MockHttpServletRequest(); ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request); @@ -87,7 +87,7 @@ public void testSessionScope() { } @Test - public void testApplicationScope() { + void testApplicationScope() { WebApplicationContext ac = initApplicationContext(WebApplicationContext.SCOPE_APPLICATION); assertThat(ac.getServletContext().getAttribute(NAME)).isNull(); DerivedTestBean bean = ac.getBean(NAME, DerivedTestBean.class); diff --git a/spring-web/src/test/java/org/springframework/web/context/request/async/DeferredResultTests.java b/spring-web/src/test/java/org/springframework/web/context/request/async/DeferredResultTests.java index f4ef7c302bef..c5f632d60f1d 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/async/DeferredResultTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/async/DeferredResultTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -29,10 +29,10 @@ * * @author Rossen Stoyanchev */ -public class DeferredResultTests { +class DeferredResultTests { @Test - public void setResult() { + void setResult() { DeferredResultHandler handler = mock(); DeferredResult result = new DeferredResult<>(); @@ -43,7 +43,7 @@ public void setResult() { } @Test - public void setResultTwice() { + void setResultTwice() { DeferredResultHandler handler = mock(); DeferredResult result = new DeferredResult<>(); @@ -56,7 +56,7 @@ public void setResultTwice() { } @Test - public void isSetOrExpired() { + void isSetOrExpired() { DeferredResultHandler handler = mock(); DeferredResult result = new DeferredResult<>(); @@ -72,7 +72,7 @@ public void isSetOrExpired() { } @Test - public void hasResult() { + void hasResult() { DeferredResultHandler handler = mock(); DeferredResult result = new DeferredResult<>(); @@ -87,7 +87,7 @@ public void hasResult() { } @Test - public void onCompletion() throws Exception { + void onCompletion() throws Exception { final StringBuilder sb = new StringBuilder(); DeferredResult result = new DeferredResult<>(); @@ -100,7 +100,7 @@ public void onCompletion() throws Exception { } @Test - public void onTimeout() throws Exception { + void onTimeout() throws Exception { final StringBuilder sb = new StringBuilder(); DeferredResultHandler handler = mock(); @@ -117,7 +117,7 @@ public void onTimeout() throws Exception { } @Test - public void onError() throws Exception { + void onError() throws Exception { final StringBuilder sb = new StringBuilder(); DeferredResultHandler handler = mock(); diff --git a/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java b/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java index c27202ed98e2..4a82587915a2 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -35,7 +35,7 @@ * A test fixture with a {@link StandardServletAsyncWebRequest}. * @author Rossen Stoyanchev */ -public class StandardServletAsyncWebRequestTests { +class StandardServletAsyncWebRequestTests { private StandardServletAsyncWebRequest asyncRequest; @@ -45,7 +45,7 @@ public class StandardServletAsyncWebRequestTests { @BeforeEach - public void setup() { + void setup() { this.request = new MockHttpServletRequest(); this.request.setAsyncSupported(true); this.response = new MockHttpServletResponse(); @@ -55,14 +55,14 @@ public void setup() { @Test - public void isAsyncStarted() throws Exception { + void isAsyncStarted() { assertThat(this.asyncRequest.isAsyncStarted()).isFalse(); this.asyncRequest.startAsync(); assertThat(this.asyncRequest.isAsyncStarted()).isTrue(); } @Test - public void startAsync() throws Exception { + void startAsync() { this.asyncRequest.startAsync(); MockAsyncContext context = (MockAsyncContext) this.request.getAsyncContext(); @@ -73,7 +73,7 @@ public void startAsync() throws Exception { } @Test - public void startAsyncMultipleTimes() throws Exception { + void startAsyncMultipleTimes() { this.asyncRequest.startAsync(); this.asyncRequest.startAsync(); this.asyncRequest.startAsync(); @@ -85,7 +85,7 @@ public void startAsyncMultipleTimes() throws Exception { } @Test - public void startAsyncNotSupported() throws Exception { + void startAsyncNotSupported() { this.request.setAsyncSupported(false); assertThatIllegalStateException().isThrownBy( this.asyncRequest::startAsync) @@ -93,7 +93,7 @@ public void startAsyncNotSupported() throws Exception { } @Test - public void startAsyncAfterCompleted() throws Exception { + void startAsyncAfterCompleted() throws Exception { this.asyncRequest.onComplete(new AsyncEvent(new MockAsyncContext(this.request, this.response))); assertThatIllegalStateException().isThrownBy( this.asyncRequest::startAsync) @@ -101,22 +101,21 @@ public void startAsyncAfterCompleted() throws Exception { } @Test - public void onTimeoutDefaultBehavior() throws Exception { + void onTimeoutDefaultBehavior() throws Exception { this.asyncRequest.onTimeout(new AsyncEvent(new MockAsyncContext(this.request, this.response))); assertThat(this.response.getStatus()).isEqualTo(200); } @Test - public void onTimeoutHandler() throws Exception { + void onTimeoutHandler() throws Exception { Runnable timeoutHandler = mock(); this.asyncRequest.addTimeoutHandler(timeoutHandler); this.asyncRequest.onTimeout(new AsyncEvent(new MockAsyncContext(this.request, this.response))); verify(timeoutHandler).run(); } - @SuppressWarnings("unchecked") @Test - public void onErrorHandler() throws Exception { + void onErrorHandler() throws Exception { Consumer errorHandler = mock(); this.asyncRequest.addErrorHandler(errorHandler); Exception e = new Exception(); @@ -125,14 +124,14 @@ public void onErrorHandler() throws Exception { } @Test - public void setTimeoutDuringConcurrentHandling() { + void setTimeoutDuringConcurrentHandling() { this.asyncRequest.startAsync(); assertThatIllegalStateException().isThrownBy(() -> this.asyncRequest.setTimeout(25L)); } @Test - public void onCompletionHandler() throws Exception { + void onCompletionHandler() throws Exception { Runnable handler = mock(); this.asyncRequest.addCompletionHandler(handler); @@ -145,9 +144,8 @@ public void onCompletionHandler() throws Exception { // SPR-13292 - @SuppressWarnings("unchecked") @Test - public void onErrorHandlerAfterOnErrorEvent() throws Exception { + void onErrorHandlerAfterOnErrorEvent() throws Exception { Consumer handler = mock(); this.asyncRequest.addErrorHandler(handler); @@ -159,7 +157,7 @@ public void onErrorHandlerAfterOnErrorEvent() throws Exception { } @Test - public void onCompletionHandlerAfterOnCompleteEvent() throws Exception { + void onCompletionHandlerAfterOnCompleteEvent() throws Exception { Runnable handler = mock(); this.asyncRequest.addCompletionHandler(handler); diff --git a/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerErrorTests.java b/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerErrorTests.java index 71749c225e13..542638dcbf2c 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerErrorTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerErrorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -41,7 +41,7 @@ * @author Violeta Georgieva * @since 5.0 */ -public class WebAsyncManagerErrorTests { +class WebAsyncManagerErrorTests { private WebAsyncManager asyncManager; @@ -53,7 +53,7 @@ public class WebAsyncManagerErrorTests { @BeforeEach - public void setup() { + void setup() { this.servletRequest = new MockHttpServletRequest("GET", "/test"); this.servletRequest.setAsyncSupported(true); this.servletResponse = new MockHttpServletResponse(); @@ -68,7 +68,7 @@ public void setup() { @Test - public void startCallableProcessingErrorAndComplete() throws Exception { + void startCallableProcessingErrorAndComplete() throws Exception { StubCallable callable = new StubCallable(); CallableProcessingInterceptor interceptor = mock(); @@ -90,7 +90,7 @@ public void startCallableProcessingErrorAndComplete() throws Exception { } @Test - public void startCallableProcessingErrorAndResumeThroughCallback() throws Exception { + void startCallableProcessingErrorAndResumeThroughCallback() throws Exception { StubCallable callable = new StubCallable(); WebAsyncTask webAsyncTask = new WebAsyncTask<>(callable); @@ -108,7 +108,7 @@ public void startCallableProcessingErrorAndResumeThroughCallback() throws Except } @Test - public void startCallableProcessingErrorAndResumeThroughInterceptor() throws Exception { + void startCallableProcessingErrorAndResumeThroughInterceptor() throws Exception { StubCallable callable = new StubCallable(); @@ -130,7 +130,7 @@ public void startCallableProcessingErrorAndResumeThroughInterceptor() throws Exc } @Test - public void startCallableProcessingAfterException() throws Exception { + void startCallableProcessingAfterException() throws Exception { StubCallable callable = new StubCallable(); Exception exception = new Exception(); @@ -153,7 +153,7 @@ public void startCallableProcessingAfterException() throws Exception { } @Test - public void startDeferredResultProcessingErrorAndComplete() throws Exception { + void startDeferredResultProcessingErrorAndComplete() throws Exception { DeferredResult deferredResult = new DeferredResult<>(); @@ -177,7 +177,7 @@ public void startDeferredResultProcessingErrorAndComplete() throws Exception { } @Test - public void startDeferredResultProcessingErrorAndResumeWithDefaultResult() throws Exception { + void startDeferredResultProcessingErrorAndResumeWithDefaultResult() throws Exception { Exception e = new Exception(); DeferredResult deferredResult = new DeferredResult<>(null, e); @@ -192,10 +192,10 @@ public void startDeferredResultProcessingErrorAndResumeWithDefaultResult() throw } @Test - public void startDeferredResultProcessingErrorAndResumeThroughCallback() throws Exception { + void startDeferredResultProcessingErrorAndResumeThroughCallback() throws Exception { final DeferredResult deferredResult = new DeferredResult<>(); - deferredResult.onError(t -> deferredResult.setResult(t)); + deferredResult.onError(deferredResult::setResult); this.asyncManager.startDeferredResultProcessing(deferredResult); @@ -209,14 +209,13 @@ public void startDeferredResultProcessingErrorAndResumeThroughCallback() throws } @Test - public void startDeferredResultProcessingErrorAndResumeThroughInterceptor() throws Exception { + void startDeferredResultProcessingErrorAndResumeThroughInterceptor() throws Exception { DeferredResult deferredResult = new DeferredResult<>(); DeferredResultProcessingInterceptor interceptor = new DeferredResultProcessingInterceptor() { @Override - public boolean handleError(NativeWebRequest request, DeferredResult result, Throwable t) - throws Exception { + public boolean handleError(NativeWebRequest request, DeferredResult result, Throwable t) { result.setErrorResult(t); return true; } @@ -235,7 +234,7 @@ public boolean handleError(NativeWebRequest request, DeferredResult resul } @Test - public void startDeferredResultProcessingAfterException() throws Exception { + void startDeferredResultProcessingAfterException() throws Exception { DeferredResult deferredResult = new DeferredResult<>(); final Exception exception = new Exception(); @@ -261,9 +260,9 @@ public boolean handleError(NativeWebRequest request, DeferredResult resul } - private final class StubCallable implements Callable { + private static final class StubCallable implements Callable { @Override - public Object call() throws Exception { + public Object call() { return 21; } } diff --git a/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTests.java b/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTests.java index 2b62a60f8a32..e0ddfa62108e 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -64,7 +64,7 @@ void setup() { @Test - void startAsyncProcessingWithoutAsyncWebRequest() throws Exception { + void startAsyncProcessingWithoutAsyncWebRequest() { WebAsyncManager manager = WebAsyncUtils.getAsyncManager(new MockHttpServletRequest()); assertThatIllegalStateException() @@ -261,7 +261,7 @@ void startCallableProcessingWithAsyncTask() throws Exception { } @Test - void startCallableProcessingNullInput() throws Exception { + void startCallableProcessingNullInput() { assertThatIllegalArgumentException() .isThrownBy(() -> this.asyncManager.startCallableProcessing((Callable) null)) .withMessage("Callable must not be null"); @@ -352,7 +352,7 @@ void startDeferredResultProcessingPostProcessException() throws Exception { } @Test - void startDeferredResultProcessingNullInput() throws Exception { + void startDeferredResultProcessingNullInput() { assertThatIllegalArgumentException() .isThrownBy(() -> this.asyncManager.startDeferredResultProcessing(null)) .withMessage("DeferredResult must not be null"); @@ -372,9 +372,9 @@ private void verifyDefaultAsyncScenario() { } - private final class StubCallable implements Callable { + private static final class StubCallable implements Callable { - private Object value; + private final Object value; StubCallable(Object value) { this.value = value; diff --git a/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTimeoutTests.java b/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTimeoutTests.java index b0ed65573412..f546dd6bc0a0 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTimeoutTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTimeoutTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -43,7 +43,7 @@ * * @author Rossen Stoyanchev */ -public class WebAsyncManagerTimeoutTests { +class WebAsyncManagerTimeoutTests { private static final AsyncEvent ASYNC_EVENT = null; @@ -57,7 +57,7 @@ public class WebAsyncManagerTimeoutTests { @BeforeEach - public void setup() { + void setup() { this.servletRequest = new MockHttpServletRequest("GET", "/test"); this.servletRequest.setAsyncSupported(true); this.servletResponse = new MockHttpServletResponse(); @@ -72,7 +72,7 @@ public void setup() { @Test - public void startCallableProcessingTimeoutAndComplete() throws Exception { + void startCallableProcessingTimeoutAndComplete() throws Exception { StubCallable callable = new StubCallable(); CallableProcessingInterceptor interceptor = mock(); @@ -92,7 +92,7 @@ public void startCallableProcessingTimeoutAndComplete() throws Exception { } @Test - public void startCallableProcessingTimeoutAndResumeThroughCallback() throws Exception { + void startCallableProcessingTimeoutAndResumeThroughCallback() throws Exception { StubCallable callable = new StubCallable(); WebAsyncTask webAsyncTask = new WebAsyncTask<>(callable); @@ -108,7 +108,7 @@ public void startCallableProcessingTimeoutAndResumeThroughCallback() throws Exce } @Test - public void startCallableProcessingTimeoutAndResumeThroughInterceptor() throws Exception { + void startCallableProcessingTimeoutAndResumeThroughInterceptor() throws Exception { StubCallable callable = new StubCallable(); @@ -128,7 +128,7 @@ public void startCallableProcessingTimeoutAndResumeThroughInterceptor() throws E } @Test - public void startCallableProcessingAfterTimeoutException() throws Exception { + void startCallableProcessingAfterTimeoutException() throws Exception { StubCallable callable = new StubCallable(); Exception exception = new Exception(); @@ -170,7 +170,7 @@ public void startCallableProcessingTimeoutAndCheckThreadInterrupted() throws Exc } @Test - public void startDeferredResultProcessingTimeoutAndComplete() throws Exception { + void startDeferredResultProcessingTimeoutAndComplete() throws Exception { DeferredResult deferredResult = new DeferredResult<>(); @@ -192,7 +192,7 @@ public void startDeferredResultProcessingTimeoutAndComplete() throws Exception { } @Test - public void startDeferredResultProcessingTimeoutAndResumeWithDefaultResult() throws Exception { + void startDeferredResultProcessingTimeoutAndResumeWithDefaultResult() throws Exception { DeferredResult deferredResult = new DeferredResult<>(null, 23); this.asyncManager.startDeferredResultProcessing(deferredResult); @@ -206,7 +206,7 @@ public void startDeferredResultProcessingTimeoutAndResumeWithDefaultResult() thr } @Test - public void startDeferredResultProcessingTimeoutAndResumeThroughCallback() throws Exception { + void startDeferredResultProcessingTimeoutAndResumeThroughCallback() throws Exception { final DeferredResult deferredResult = new DeferredResult<>(); deferredResult.onTimeout(() -> deferredResult.setResult(23)); @@ -222,7 +222,7 @@ public void startDeferredResultProcessingTimeoutAndResumeThroughCallback() throw } @Test - public void startDeferredResultProcessingTimeoutAndResumeThroughInterceptor() throws Exception { + void startDeferredResultProcessingTimeoutAndResumeThroughInterceptor() throws Exception { DeferredResult deferredResult = new DeferredResult<>(); @@ -246,7 +246,7 @@ public boolean handleTimeout(NativeWebRequest request, DeferredResult res } @Test - public void startDeferredResultProcessingAfterTimeoutException() throws Exception { + void startDeferredResultProcessingAfterTimeoutException() throws Exception { DeferredResult deferredResult = new DeferredResult<>(); final Exception exception = new Exception(); @@ -270,9 +270,9 @@ public boolean handleTimeout(NativeWebRequest request, DeferredResult res } - private final class StubCallable implements Callable { + private static final class StubCallable implements Callable { @Override - public Object call() throws Exception { + public Object call() { return 21; } } diff --git a/spring-web/src/test/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContextTests.java b/spring-web/src/test/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContextTests.java index 106eb25c63a3..39c8286cab59 100644 --- a/spring-web/src/test/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContextTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -30,10 +30,9 @@ * @author Chris Beams * @author Juergen Hoeller */ -public class AnnotationConfigWebApplicationContextTests { +class AnnotationConfigWebApplicationContextTests { @Test - @SuppressWarnings("resource") public void registerSingleClass() { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(Config.class); @@ -44,7 +43,6 @@ public void registerSingleClass() { } @Test - @SuppressWarnings("resource") public void configLocationWithSingleClass() { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.setConfigLocation(Config.class.getName()); @@ -55,7 +53,6 @@ public void configLocationWithSingleClass() { } @Test - @SuppressWarnings("resource") public void configLocationWithBasePackage() { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.setConfigLocation("org.springframework.web.context.support"); @@ -66,7 +63,6 @@ public void configLocationWithBasePackage() { } @Test - @SuppressWarnings("resource") public void withBeanNameGenerator() { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() { diff --git a/spring-web/src/test/java/org/springframework/web/context/support/ServletContextResourceTests.java b/spring-web/src/test/java/org/springframework/web/context/support/ServletContextResourceTests.java index 5f84ebdafc14..fc31c610ae5e 100644 --- a/spring-web/src/test/java/org/springframework/web/context/support/ServletContextResourceTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/support/ServletContextResourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -34,7 +34,7 @@ * @author Chris Beams * @author Brian Clozel */ -public class ServletContextResourceTests { +class ServletContextResourceTests { private static final String TEST_RESOURCE_PATH = "org/springframework/web/context/support/resource.txt"; diff --git a/spring-web/src/test/java/org/springframework/web/context/support/Spr8510Tests.java b/spring-web/src/test/java/org/springframework/web/context/support/Spr8510Tests.java index aa56a4d9a14f..8642352a20f0 100644 --- a/spring-web/src/test/java/org/springframework/web/context/support/Spr8510Tests.java +++ b/spring-web/src/test/java/org/springframework/web/context/support/Spr8510Tests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -35,10 +35,10 @@ * @since 3.1 * @see org.springframework.web.context.ContextLoaderTests */ -public class Spr8510Tests { +class Spr8510Tests { @Test - public void abstractRefreshableWAC_respectsProgrammaticConfigLocations() { + void abstractRefreshableWAC_respectsProgrammaticConfigLocations() { XmlWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setConfigLocation("programmatic.xml"); ContextLoaderListener cll = new ContextLoaderListener(ctx); @@ -58,7 +58,7 @@ public void abstractRefreshableWAC_respectsProgrammaticConfigLocations() { * hybrid web.xml + WebApplicationInitializer cases. */ @Test - public void abstractRefreshableWAC_respectsInitParam_overProgrammaticConfigLocations() { + void abstractRefreshableWAC_respectsInitParam_overProgrammaticConfigLocations() { XmlWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setConfigLocation("programmatic.xml"); ContextLoaderListener cll = new ContextLoaderListener(ctx); @@ -76,7 +76,7 @@ public void abstractRefreshableWAC_respectsInitParam_overProgrammaticConfigLocat * then fall back to the ContextLoaderListener init-param if present. */ @Test - public void abstractRefreshableWAC_fallsBackToInitParam() { + void abstractRefreshableWAC_fallsBackToInitParam() { XmlWebApplicationContext ctx = new XmlWebApplicationContext(); //ctx.setConfigLocation("programmatic.xml"); // nothing set programmatically ContextLoaderListener cll = new ContextLoaderListener(ctx); @@ -93,7 +93,7 @@ public void abstractRefreshableWAC_fallsBackToInitParam() { * Ensure that any custom default locations are still respected. */ @Test - public void customAbstractRefreshableWAC_fallsBackToInitParam() { + void customAbstractRefreshableWAC_fallsBackToInitParam() { XmlWebApplicationContext ctx = new XmlWebApplicationContext() { @Override protected String[] getDefaultConfigLocations() { @@ -116,7 +116,7 @@ protected String[] getDefaultConfigLocations() { * context nor the context loader listener, then fall back to default values. */ @Test - public void abstractRefreshableWAC_fallsBackToConventionBasedNaming() { + void abstractRefreshableWAC_fallsBackToConventionBasedNaming() { XmlWebApplicationContext ctx = new XmlWebApplicationContext(); //ctx.setConfigLocation("programmatic.xml"); // nothing set programmatically ContextLoaderListener cll = new ContextLoaderListener(ctx); @@ -134,7 +134,7 @@ public void abstractRefreshableWAC_fallsBackToConventionBasedNaming() { * Ensure that ContextLoaderListener and GenericWebApplicationContext interact nicely. */ @Test - public void genericWAC() { + void genericWAC() { GenericWebApplicationContext ctx = new GenericWebApplicationContext(); ContextLoaderListener cll = new ContextLoaderListener(ctx); @@ -148,7 +148,7 @@ public void genericWAC() { * Ensure that ContextLoaderListener and AnnotationConfigApplicationContext interact nicely. */ @Test - public void annotationConfigWAC() { + void annotationConfigWAC() { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.scan("does.not.matter"); diff --git a/spring-web/src/test/java/org/springframework/web/context/support/SpringBeanAutowiringSupportTests.java b/spring-web/src/test/java/org/springframework/web/context/support/SpringBeanAutowiringSupportTests.java index 9a9f1b879e77..3cf4834cc7ce 100644 --- a/spring-web/src/test/java/org/springframework/web/context/support/SpringBeanAutowiringSupportTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/support/SpringBeanAutowiringSupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -32,10 +32,10 @@ /** * @author Juergen Hoeller */ -public class SpringBeanAutowiringSupportTests { +class SpringBeanAutowiringSupportTests { @Test - public void testProcessInjectionBasedOnServletContext() { + void testProcessInjectionBasedOnServletContext() { StaticWebApplicationContext wac = new StaticWebApplicationContext(); AnnotationConfigUtils.registerAnnotationConfigProcessors(wac); diff --git a/spring-web/src/test/java/org/springframework/web/context/support/StandardServletEnvironmentTests.java b/spring-web/src/test/java/org/springframework/web/context/support/StandardServletEnvironmentTests.java index e07100bdf698..bbefe75ff727 100644 --- a/spring-web/src/test/java/org/springframework/web/context/support/StandardServletEnvironmentTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/support/StandardServletEnvironmentTests.java @@ -33,10 +33,10 @@ * @author Chris Beams * @since 3.1 */ -public class StandardServletEnvironmentTests { +class StandardServletEnvironmentTests { @Test - public void propertySourceOrder() throws Exception { + void propertySourceOrder() throws Exception { SimpleNamingContextBuilder.emptyActivatedContextBuilder(); ConfigurableEnvironment env = new StandardServletEnvironment(); diff --git a/spring-web/src/test/java/org/springframework/web/cors/CorsUtilsTests.java b/spring-web/src/test/java/org/springframework/web/cors/CorsUtilsTests.java index d68c677ddf18..bd58899cd16a 100644 --- a/spring-web/src/test/java/org/springframework/web/cors/CorsUtilsTests.java +++ b/spring-web/src/test/java/org/springframework/web/cors/CorsUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -29,23 +29,23 @@ * * @author Sebastien Deleuze */ -public class CorsUtilsTests { +class CorsUtilsTests { @Test - public void isCorsRequest() { + void isCorsRequest() { MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader(HttpHeaders.ORIGIN, "https://domain.com"); assertThat(CorsUtils.isCorsRequest(request)).isTrue(); } @Test - public void isNotCorsRequest() { + void isNotCorsRequest() { MockHttpServletRequest request = new MockHttpServletRequest(); assertThat(CorsUtils.isCorsRequest(request)).isFalse(); } @Test - public void isPreFlightRequest() { + void isPreFlightRequest() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod(HttpMethod.OPTIONS.name()); request.addHeader(HttpHeaders.ORIGIN, "https://domain.com"); @@ -54,7 +54,7 @@ public void isPreFlightRequest() { } @Test - public void isNotPreFlightRequest() { + void isNotPreFlightRequest() { MockHttpServletRequest request = new MockHttpServletRequest(); assertThat(CorsUtils.isPreFlightRequest(request)).isFalse(); diff --git a/spring-web/src/test/java/org/springframework/web/cors/DefaultCorsProcessorTests.java b/spring-web/src/test/java/org/springframework/web/cors/DefaultCorsProcessorTests.java index 2bd442867cfb..301154fe015f 100644 --- a/spring-web/src/test/java/org/springframework/web/cors/DefaultCorsProcessorTests.java +++ b/spring-web/src/test/java/org/springframework/web/cors/DefaultCorsProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -37,7 +37,7 @@ * @author Rossen Stoyanchev * @author Juergen Hoeller */ -public class DefaultCorsProcessorTests { +class DefaultCorsProcessorTests { private MockHttpServletRequest request; @@ -49,7 +49,7 @@ public class DefaultCorsProcessorTests { @BeforeEach - public void setup() { + void setup() { this.request = new MockHttpServletRequest(); this.request.setRequestURI("/test.html"); this.request.setServerName("domain1.example"); @@ -60,7 +60,7 @@ public void setup() { } @Test - public void requestWithoutOriginHeader() throws Exception { + void requestWithoutOriginHeader() throws Exception { this.request.setMethod(HttpMethod.GET.name()); this.processor.processRequest(this.conf, this.request, this.response); @@ -71,7 +71,7 @@ public void requestWithoutOriginHeader() throws Exception { } @Test - public void sameOriginRequest() throws Exception { + void sameOriginRequest() throws Exception { this.request.setMethod(HttpMethod.GET.name()); this.request.addHeader(HttpHeaders.ORIGIN, "http://domain1.example"); @@ -83,7 +83,7 @@ public void sameOriginRequest() throws Exception { } @Test - public void actualRequestWithOriginHeader() throws Exception { + void actualRequestWithOriginHeader() throws Exception { this.request.setMethod(HttpMethod.GET.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); @@ -95,7 +95,7 @@ public void actualRequestWithOriginHeader() throws Exception { } @Test - public void actualRequestWithOriginHeaderAndNullConfig() throws Exception { + void actualRequestWithOriginHeaderAndNullConfig() throws Exception { this.request.setMethod(HttpMethod.GET.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); @@ -105,7 +105,7 @@ public void actualRequestWithOriginHeaderAndNullConfig() throws Exception { } @Test - public void actualRequestWithOriginHeaderAndAllowedOrigin() throws Exception { + void actualRequestWithOriginHeaderAndAllowedOrigin() throws Exception { this.request.setMethod(HttpMethod.GET.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.conf.addAllowedOrigin("*"); @@ -121,7 +121,7 @@ public void actualRequestWithOriginHeaderAndAllowedOrigin() throws Exception { } @Test - public void actualRequestCredentials() throws Exception { + void actualRequestCredentials() throws Exception { this.request.setMethod(HttpMethod.GET.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.conf.addAllowedOrigin("https://domain1.com"); @@ -140,7 +140,7 @@ public void actualRequestCredentials() throws Exception { } @Test - public void actualRequestCredentialsWithWildcardOrigin() throws Exception { + void actualRequestCredentialsWithWildcardOrigin() throws Exception { this.request.setMethod(HttpMethod.GET.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); @@ -163,7 +163,7 @@ public void actualRequestCredentialsWithWildcardOrigin() throws Exception { } @Test - public void actualRequestCaseInsensitiveOriginMatch() throws Exception { + void actualRequestCaseInsensitiveOriginMatch() throws Exception { this.request.setMethod(HttpMethod.GET.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.conf.addAllowedOrigin("https://DOMAIN2.com"); @@ -185,7 +185,7 @@ public void actualRequestTrailingSlashOriginMatch() throws Exception { } @Test - public void actualRequestExposedHeaders() throws Exception { + void actualRequestExposedHeaders() throws Exception { this.request.setMethod(HttpMethod.GET.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.conf.addExposedHeader("header1"); @@ -204,7 +204,7 @@ public void actualRequestExposedHeaders() throws Exception { } @Test - public void preflightRequestAllOriginsAllowed() throws Exception { + void preflightRequestAllOriginsAllowed() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); @@ -217,7 +217,7 @@ public void preflightRequestAllOriginsAllowed() throws Exception { } @Test - public void preflightRequestWrongAllowedMethod() throws Exception { + void preflightRequestWrongAllowedMethod() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "DELETE"); @@ -230,7 +230,7 @@ public void preflightRequestWrongAllowedMethod() throws Exception { } @Test - public void preflightRequestMatchedAllowedMethod() throws Exception { + void preflightRequestMatchedAllowedMethod() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); @@ -244,7 +244,7 @@ public void preflightRequestMatchedAllowedMethod() throws Exception { } @Test - public void preflightRequestTestWithOriginButWithoutOtherHeaders() throws Exception { + void preflightRequestTestWithOriginButWithoutOtherHeaders() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); @@ -256,7 +256,7 @@ public void preflightRequestTestWithOriginButWithoutOtherHeaders() throws Except } @Test - public void preflightRequestWithoutRequestMethod() throws Exception { + void preflightRequestWithoutRequestMethod() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "Header1"); @@ -269,7 +269,7 @@ public void preflightRequestWithoutRequestMethod() throws Exception { } @Test - public void preflightRequestWithRequestAndMethodHeaderButNoConfig() throws Exception { + void preflightRequestWithRequestAndMethodHeaderButNoConfig() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); @@ -283,7 +283,7 @@ public void preflightRequestWithRequestAndMethodHeaderButNoConfig() throws Excep } @Test - public void preflightRequestValidRequestAndConfig() throws Exception { + void preflightRequestValidRequestAndConfig() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); @@ -306,7 +306,7 @@ public void preflightRequestValidRequestAndConfig() throws Exception { } @Test - public void preflightRequestCredentials() throws Exception { + void preflightRequestCredentials() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); @@ -328,7 +328,7 @@ public void preflightRequestCredentials() throws Exception { } @Test - public void preflightRequestCredentialsWithWildcardOrigin() throws Exception { + void preflightRequestCredentialsWithWildcardOrigin() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); @@ -352,7 +352,7 @@ public void preflightRequestCredentialsWithWildcardOrigin() throws Exception { } @Test - public void preflightRequestPrivateNetworkWithWildcardOrigin() throws Exception { + void preflightRequestPrivateNetworkWithWildcardOrigin() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); @@ -378,7 +378,7 @@ public void preflightRequestPrivateNetworkWithWildcardOrigin() throws Exception } @Test - public void preflightRequestAllowedHeaders() throws Exception { + void preflightRequestAllowedHeaders() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); @@ -400,7 +400,7 @@ public void preflightRequestAllowedHeaders() throws Exception { } @Test - public void preflightRequestAllowsAllHeaders() throws Exception { + void preflightRequestAllowsAllHeaders() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); @@ -420,7 +420,7 @@ public void preflightRequestAllowsAllHeaders() throws Exception { } @Test - public void preflightRequestWithEmptyHeaders() throws Exception { + void preflightRequestWithEmptyHeaders() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); @@ -437,7 +437,7 @@ public void preflightRequestWithEmptyHeaders() throws Exception { } @Test - public void preflightRequestWithNullConfig() throws Exception { + void preflightRequestWithNullConfig() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); @@ -449,7 +449,7 @@ public void preflightRequestWithNullConfig() throws Exception { } @Test - public void preventDuplicatedVaryHeaders() throws Exception { + void preventDuplicatedVaryHeaders() throws Exception { this.request.setMethod(HttpMethod.GET.name()); this.response.addHeader(HttpHeaders.VARY, HttpHeaders.ORIGIN); this.response.addHeader(HttpHeaders.VARY, HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD); @@ -461,7 +461,7 @@ public void preventDuplicatedVaryHeaders() throws Exception { } @Test - public void preflightRequestWithoutAccessControlRequestPrivateNetwork() throws Exception { + void preflightRequestWithoutAccessControlRequestPrivateNetwork() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); @@ -475,7 +475,7 @@ public void preflightRequestWithoutAccessControlRequestPrivateNetwork() throws E } @Test - public void preflightRequestWithAccessControlRequestPrivateNetworkNotAllowed() throws Exception { + void preflightRequestWithAccessControlRequestPrivateNetworkNotAllowed() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); @@ -490,7 +490,7 @@ public void preflightRequestWithAccessControlRequestPrivateNetworkNotAllowed() t } @Test - public void preflightRequestWithAccessControlRequestPrivateNetworkAllowed() throws Exception { + void preflightRequestWithAccessControlRequestPrivateNetworkAllowed() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); this.request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com"); this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); diff --git a/spring-web/src/test/java/org/springframework/web/cors/reactive/CorsUtilsTests.java b/spring-web/src/test/java/org/springframework/web/cors/reactive/CorsUtilsTests.java index 7780a1f7f940..3b816e87c811 100644 --- a/spring-web/src/test/java/org/springframework/web/cors/reactive/CorsUtilsTests.java +++ b/spring-web/src/test/java/org/springframework/web/cors/reactive/CorsUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 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. @@ -34,22 +34,22 @@ * @author Sebastien Deleuze * @author Rossen Stoyanchev */ -public class CorsUtilsTests { +class CorsUtilsTests { @Test - public void isCorsRequest() { + void isCorsRequest() { ServerHttpRequest request = get("http://domain.example/").header(HttpHeaders.ORIGIN, "https://domain.com").build(); assertThat(CorsUtils.isCorsRequest(request)).isTrue(); } @Test - public void isNotCorsRequest() { + void isNotCorsRequest() { ServerHttpRequest request = get("/").build(); assertThat(CorsUtils.isCorsRequest(request)).isFalse(); } @Test - public void isPreFlightRequest() { + void isPreFlightRequest() { ServerHttpRequest request = options("/") .header(HttpHeaders.ORIGIN, "https://domain.com") .header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET") @@ -58,7 +58,7 @@ public void isPreFlightRequest() { } @Test - public void isNotPreFlightRequest() { + void isNotPreFlightRequest() { ServerHttpRequest request = get("/").build(); assertThat(CorsUtils.isPreFlightRequest(request)).isFalse(); diff --git a/spring-web/src/test/java/org/springframework/web/cors/reactive/CorsWebFilterTests.java b/spring-web/src/test/java/org/springframework/web/cors/reactive/CorsWebFilterTests.java index 4575443596f9..ef01066b2253 100644 --- a/spring-web/src/test/java/org/springframework/web/cors/reactive/CorsWebFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/cors/reactive/CorsWebFilterTests.java @@ -16,10 +16,8 @@ package org.springframework.web.cors.reactive; -import java.io.IOException; import java.util.Arrays; -import jakarta.servlet.ServletException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; @@ -46,14 +44,14 @@ * * @author Sebastien Deleuze */ -public class CorsWebFilterTests { +class CorsWebFilterTests { private CorsWebFilter filter; private final CorsConfiguration config = new CorsConfiguration(); @BeforeEach - public void setup() throws Exception { + void setup() { config.setAllowedOrigins(Arrays.asList("https://domain1.com", "https://domain2.com")); config.setAllowedMethods(Arrays.asList("GET", "POST")); config.setAllowedHeaders(Arrays.asList("header1", "header2")); @@ -64,7 +62,7 @@ public void setup() throws Exception { } @Test - public void nonCorsRequest() { + void nonCorsRequest() { WebFilterChain filterChain = filterExchange -> { try { HttpHeaders headers = filterExchange.getResponse().getHeaders(); @@ -85,7 +83,7 @@ public void nonCorsRequest() { } @Test - public void sameOriginRequest() { + void sameOriginRequest() { WebFilterChain filterChain = filterExchange -> { try { HttpHeaders headers = filterExchange.getResponse().getHeaders(); @@ -106,7 +104,7 @@ public void sameOriginRequest() { } @Test - public void validActualRequest() { + void validActualRequest() { WebFilterChain filterChain = filterExchange -> { try { HttpHeaders headers = filterExchange.getResponse().getHeaders(); @@ -129,7 +127,7 @@ public void validActualRequest() { } @Test - public void invalidActualRequest() throws ServletException, IOException { + void invalidActualRequest() { MockServerWebExchange exchange = MockServerWebExchange.from( MockServerHttpRequest .delete("https://domain1.com/test.html") @@ -144,7 +142,7 @@ public void invalidActualRequest() throws ServletException, IOException { } @Test - public void validPreFlightRequest() throws ServletException, IOException { + void validPreFlightRequest() { MockServerWebExchange exchange = MockServerWebExchange.from( MockServerHttpRequest @@ -167,7 +165,7 @@ public void validPreFlightRequest() throws ServletException, IOException { } @Test - public void invalidPreFlightRequest() throws ServletException, IOException { + void invalidPreFlightRequest() { MockServerWebExchange exchange = MockServerWebExchange.from( MockServerHttpRequest diff --git a/spring-web/src/test/java/org/springframework/web/cors/reactive/DefaultCorsProcessorTests.java b/spring-web/src/test/java/org/springframework/web/cors/reactive/DefaultCorsProcessorTests.java index d2a24decabf9..fcb805129d94 100644 --- a/spring-web/src/test/java/org/springframework/web/cors/reactive/DefaultCorsProcessorTests.java +++ b/spring-web/src/test/java/org/springframework/web/cors/reactive/DefaultCorsProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -42,7 +42,7 @@ * * @author Sebastien Deleuze */ -public class DefaultCorsProcessorTests { +class DefaultCorsProcessorTests { private DefaultCorsProcessor processor; @@ -50,14 +50,14 @@ public class DefaultCorsProcessorTests { @BeforeEach - public void setup() { + void setup() { this.conf = new CorsConfiguration(); this.processor = new DefaultCorsProcessor(); } @Test - public void requestWithoutOriginHeader() { + void requestWithoutOriginHeader() { MockServerHttpRequest request = MockServerHttpRequest .method(HttpMethod.GET, "http://domain1.example/test.html") .build(); @@ -72,7 +72,7 @@ public void requestWithoutOriginHeader() { } @Test - public void sameOriginRequest() { + void sameOriginRequest() { MockServerHttpRequest request = MockServerHttpRequest .method(HttpMethod.GET, "http://domain1.example/test.html") .header(HttpHeaders.ORIGIN, "http://domain1.example") @@ -88,7 +88,7 @@ public void sameOriginRequest() { } @Test - public void actualRequestWithOriginHeader() { + void actualRequestWithOriginHeader() { ServerWebExchange exchange = actualRequest(); this.processor.process(this.conf, exchange); @@ -100,7 +100,7 @@ public void actualRequestWithOriginHeader() { } @Test - public void actualRequestWithOriginHeaderAndNullConfig() { + void actualRequestWithOriginHeaderAndNullConfig() { ServerWebExchange exchange = actualRequest(); this.processor.process(null, exchange); @@ -110,7 +110,7 @@ public void actualRequestWithOriginHeaderAndNullConfig() { } @Test - public void actualRequestWithOriginHeaderAndAllowedOrigin() { + void actualRequestWithOriginHeaderAndAllowedOrigin() { ServerWebExchange exchange = actualRequest(); this.conf.addAllowedOrigin("*"); this.processor.process(this.conf, exchange); @@ -126,7 +126,7 @@ public void actualRequestWithOriginHeaderAndAllowedOrigin() { } @Test - public void actualRequestCredentials() { + void actualRequestCredentials() { ServerWebExchange exchange = actualRequest(); this.conf.addAllowedOrigin("https://domain1.com"); this.conf.addAllowedOrigin("https://domain2.com"); @@ -145,7 +145,7 @@ public void actualRequestCredentials() { } @Test - public void actualRequestCredentialsWithWildcardOrigin() { + void actualRequestCredentialsWithWildcardOrigin() { ServerWebExchange exchange = actualRequest(); this.conf.addAllowedOrigin("*"); this.conf.setAllowCredentials(true); @@ -166,7 +166,7 @@ public void actualRequestCredentialsWithWildcardOrigin() { } @Test - public void actualRequestCaseInsensitiveOriginMatch() { + void actualRequestCaseInsensitiveOriginMatch() { ServerWebExchange exchange = actualRequest(); this.conf.addAllowedOrigin("https://DOMAIN2.com"); this.processor.process(this.conf, exchange); @@ -191,7 +191,7 @@ public void actualRequestTrailingSlashOriginMatch() { } @Test - public void actualRequestExposedHeaders() { + void actualRequestExposedHeaders() { ServerWebExchange exchange = actualRequest(); this.conf.addExposedHeader("header1"); this.conf.addExposedHeader("header2"); @@ -210,7 +210,7 @@ public void actualRequestExposedHeaders() { } @Test - public void preflightRequestAllOriginsAllowed() { + void preflightRequestAllOriginsAllowed() { ServerWebExchange exchange = MockServerWebExchange.from( preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET")); this.conf.addAllowedOrigin("*"); @@ -224,7 +224,7 @@ public void preflightRequestAllOriginsAllowed() { @Test - public void preflightRequestWrongAllowedMethod() { + void preflightRequestWrongAllowedMethod() { ServerWebExchange exchange = MockServerWebExchange.from( preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "DELETE")); this.conf.addAllowedOrigin("*"); @@ -237,7 +237,7 @@ public void preflightRequestWrongAllowedMethod() { } @Test - public void preflightRequestMatchedAllowedMethod() { + void preflightRequestMatchedAllowedMethod() { ServerWebExchange exchange = MockServerWebExchange.from( preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET")); this.conf.addAllowedOrigin("*"); @@ -251,7 +251,7 @@ public void preflightRequestMatchedAllowedMethod() { } @Test - public void preflightRequestTestWithOriginButWithoutOtherHeaders() { + void preflightRequestTestWithOriginButWithoutOtherHeaders() { ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()); this.processor.process(this.conf, exchange); @@ -263,7 +263,7 @@ public void preflightRequestTestWithOriginButWithoutOtherHeaders() { } @Test - public void preflightRequestWithoutRequestMethod() { + void preflightRequestWithoutRequestMethod() { ServerWebExchange exchange = MockServerWebExchange.from( preFlightRequest().header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")); this.processor.process(this.conf, exchange); @@ -276,7 +276,7 @@ public void preflightRequestWithoutRequestMethod() { } @Test - public void preflightRequestWithRequestAndMethodHeaderButNoConfig() { + void preflightRequestWithRequestAndMethodHeaderButNoConfig() { ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest() .header(ACCESS_CONTROL_REQUEST_METHOD, "GET") .header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")); @@ -291,7 +291,7 @@ public void preflightRequestWithRequestAndMethodHeaderButNoConfig() { } @Test - public void preflightRequestValidRequestAndConfig() { + void preflightRequestValidRequestAndConfig() { ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest() .header(ACCESS_CONTROL_REQUEST_METHOD, "GET") .header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")); @@ -316,7 +316,7 @@ public void preflightRequestValidRequestAndConfig() { } @Test - public void preflightRequestCredentials() { + void preflightRequestCredentials() { ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest() .header(ACCESS_CONTROL_REQUEST_METHOD, "GET") .header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")); @@ -340,7 +340,7 @@ public void preflightRequestCredentials() { } @Test - public void preflightRequestCredentialsWithWildcardOrigin() { + void preflightRequestCredentialsWithWildcardOrigin() { ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest() .header(ACCESS_CONTROL_REQUEST_METHOD, "GET") .header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")); @@ -365,7 +365,7 @@ public void preflightRequestCredentialsWithWildcardOrigin() { } @Test - public void preflightRequestPrivateNetworkWithWildcardOrigin() { + void preflightRequestPrivateNetworkWithWildcardOrigin() { ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest() .header(ACCESS_CONTROL_REQUEST_METHOD, "GET") .header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1") @@ -392,7 +392,7 @@ public void preflightRequestPrivateNetworkWithWildcardOrigin() { } @Test - public void preflightRequestAllowedHeaders() { + void preflightRequestAllowedHeaders() { ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest() .header(ACCESS_CONTROL_REQUEST_METHOD, "GET") .header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1, Header2")); @@ -416,7 +416,7 @@ public void preflightRequestAllowedHeaders() { } @Test - public void preflightRequestAllowsAllHeaders() { + void preflightRequestAllowsAllHeaders() { ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest() .header(ACCESS_CONTROL_REQUEST_METHOD, "GET") .header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1, Header2")); @@ -438,7 +438,7 @@ public void preflightRequestAllowsAllHeaders() { } @Test - public void preflightRequestWithEmptyHeaders() { + void preflightRequestWithEmptyHeaders() { ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest() .header(ACCESS_CONTROL_REQUEST_METHOD, "GET") .header(ACCESS_CONTROL_REQUEST_HEADERS, "")); @@ -457,7 +457,7 @@ public void preflightRequestWithEmptyHeaders() { } @Test - public void preflightRequestWithNullConfig() throws Exception { + void preflightRequestWithNullConfig() { ServerWebExchange exchange = MockServerWebExchange.from( preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET")); this.conf.addAllowedOrigin("*"); @@ -469,7 +469,7 @@ public void preflightRequestWithNullConfig() throws Exception { } @Test - public void preventDuplicatedVaryHeaders() { + void preventDuplicatedVaryHeaders() { MockServerHttpRequest request = MockServerHttpRequest .method(HttpMethod.GET, "http://domain1.example/test.html") .header(HttpHeaders.ORIGIN, "http://domain1.example") @@ -488,7 +488,7 @@ public void preventDuplicatedVaryHeaders() { } @Test - public void preflightRequestWithoutAccessControlRequestPrivateNetwork() { + void preflightRequestWithoutAccessControlRequestPrivateNetwork() { ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest() .header(ACCESS_CONTROL_REQUEST_METHOD, "GET")); @@ -504,7 +504,7 @@ public void preflightRequestWithoutAccessControlRequestPrivateNetwork() { } @Test - public void preflightRequestWithAccessControlRequestPrivateNetworkNotAllowed() { + void preflightRequestWithAccessControlRequestPrivateNetworkNotAllowed() { ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest() .header(ACCESS_CONTROL_REQUEST_METHOD, "GET") .header(DefaultCorsProcessor.ACCESS_CONTROL_REQUEST_PRIVATE_NETWORK, "true")); @@ -521,7 +521,7 @@ public void preflightRequestWithAccessControlRequestPrivateNetworkNotAllowed() { } @Test - public void preflightRequestWithAccessControlRequestPrivateNetworkAllowed() { + void preflightRequestWithAccessControlRequestPrivateNetworkAllowed() { ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest() .header(ACCESS_CONTROL_REQUEST_METHOD, "GET") .header(DefaultCorsProcessor.ACCESS_CONTROL_REQUEST_PRIVATE_NETWORK, "true")); diff --git a/spring-web/src/test/java/org/springframework/web/filter/CharacterEncodingFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/CharacterEncodingFilterTests.java index d7fcf8e58759..9f3afb2c5ad4 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/CharacterEncodingFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/CharacterEncodingFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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,7 +38,7 @@ * @author Juergen Hoeller * @author Vedran Pavic */ -public class CharacterEncodingFilterTests { +class CharacterEncodingFilterTests { private static final String FILTER_NAME = "boot"; @@ -46,7 +46,7 @@ public class CharacterEncodingFilterTests { @Test - public void forceEncodingAlwaysSetsEncoding() throws Exception { + void forceEncodingAlwaysSetsEncoding() throws Exception { HttpServletRequest request = mock(); request.setCharacterEncoding(ENCODING); given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null); @@ -67,7 +67,7 @@ public void forceEncodingAlwaysSetsEncoding() throws Exception { } @Test - public void encodingIfEmptyAndNotForced() throws Exception { + void encodingIfEmptyAndNotForced() throws Exception { HttpServletRequest request = mock(); given(request.getCharacterEncoding()).willReturn(null); given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null); @@ -89,7 +89,7 @@ public void encodingIfEmptyAndNotForced() throws Exception { } @Test - public void doesNotIfEncodingIsNotEmptyAndNotForced() throws Exception { + void doesNotIfEncodingIsNotEmptyAndNotForced() throws Exception { HttpServletRequest request = mock(); given(request.getCharacterEncoding()).willReturn(ENCODING); given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null); @@ -110,7 +110,7 @@ public void doesNotIfEncodingIsNotEmptyAndNotForced() throws Exception { } @Test - public void withBeanInitialization() throws Exception { + void withBeanInitialization() throws Exception { HttpServletRequest request = mock(); given(request.getCharacterEncoding()).willReturn(null); given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null); @@ -134,7 +134,7 @@ public void withBeanInitialization() throws Exception { } @Test - public void withIncompleteInitialization() throws Exception { + void withIncompleteInitialization() throws Exception { HttpServletRequest request = mock(); given(request.getCharacterEncoding()).willReturn(null); given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null); @@ -156,7 +156,7 @@ public void withIncompleteInitialization() throws Exception { // SPR-14240 @Test - public void setForceEncodingOnRequestOnly() throws Exception { + void setForceEncodingOnRequestOnly() throws Exception { HttpServletRequest request = mock(); request.setCharacterEncoding(ENCODING); given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null); diff --git a/spring-web/src/test/java/org/springframework/web/filter/CompositeFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/CompositeFilterTests.java index 322a38997048..693d3653912e 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/CompositeFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/CompositeFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -17,7 +17,7 @@ package org.springframework.web.filter; import java.io.IOException; -import java.util.Arrays; +import java.util.List; import jakarta.servlet.Filter; import jakarta.servlet.FilterChain; @@ -38,16 +38,16 @@ /** * @author Dave Syer */ -public class CompositeFilterTests { +class CompositeFilterTests { @Test - public void testCompositeFilter() throws ServletException, IOException { + void testCompositeFilter() throws ServletException, IOException { ServletContext sc = new MockServletContext(); MockFilter targetFilter = new MockFilter(); MockFilterConfig proxyConfig = new MockFilterConfig(sc); CompositeFilter filterProxy = new CompositeFilter(); - filterProxy.setFilters(Arrays.asList(targetFilter)); + filterProxy.setFilters(List.of(targetFilter)); filterProxy.init(proxyConfig); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -67,7 +67,7 @@ public static class MockFilter implements Filter { public FilterConfig filterConfig; @Override - public void init(FilterConfig filterConfig) throws ServletException { + public void init(FilterConfig filterConfig) { this.filterConfig = filterConfig; } diff --git a/spring-web/src/test/java/org/springframework/web/filter/ContentCachingResponseWrapperTests.java b/spring-web/src/test/java/org/springframework/web/filter/ContentCachingResponseWrapperTests.java index 145bd169c3a8..691386f99818 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/ContentCachingResponseWrapperTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/ContentCachingResponseWrapperTests.java @@ -33,7 +33,7 @@ * * @author Rossen Stoyanchev */ -public class ContentCachingResponseWrapperTests { +class ContentCachingResponseWrapperTests { @Test void copyBodyToResponse() throws Exception { diff --git a/spring-web/src/test/java/org/springframework/web/filter/CorsFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/CorsFilterTests.java index 8ded104dc472..c5e36f054d7a 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/CorsFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/CorsFilterTests.java @@ -39,7 +39,7 @@ * * @author Sebastien Deleuze */ -public class CorsFilterTests { +class CorsFilterTests { private CorsFilter filter; diff --git a/spring-web/src/test/java/org/springframework/web/filter/DelegatingFilterProxyTests.java b/spring-web/src/test/java/org/springframework/web/filter/DelegatingFilterProxyTests.java index 875169ca2524..fffa8076f153 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/DelegatingFilterProxyTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/DelegatingFilterProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -43,10 +43,10 @@ * @author Rob Winch * @since 08.05.2005 */ -public class DelegatingFilterProxyTests { +class DelegatingFilterProxyTests { @Test - public void testDelegatingFilterProxy() throws ServletException, IOException { + void testDelegatingFilterProxy() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); @@ -74,7 +74,7 @@ public void testDelegatingFilterProxy() throws ServletException, IOException { } @Test - public void testDelegatingFilterProxyAndCustomContextAttribute() throws ServletException, IOException { + void testDelegatingFilterProxyAndCustomContextAttribute() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); @@ -103,7 +103,7 @@ public void testDelegatingFilterProxyAndCustomContextAttribute() throws ServletE } @Test - public void testDelegatingFilterProxyWithFilterDelegateInstance() throws ServletException, IOException { + void testDelegatingFilterProxyWithFilterDelegateInstance() throws ServletException, IOException { MockFilter targetFilter = new MockFilter(); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(targetFilter); @@ -121,7 +121,7 @@ public void testDelegatingFilterProxyWithFilterDelegateInstance() throws Servlet } @Test - public void testDelegatingFilterProxyWithTargetBeanName() throws ServletException, IOException { + void testDelegatingFilterProxyWithTargetBeanName() throws ServletException, IOException { MockServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); @@ -147,7 +147,7 @@ public void testDelegatingFilterProxyWithTargetBeanName() throws ServletExceptio } @Test - public void testDelegatingFilterProxyWithTargetBeanNameAndNotYetRefreshedApplicationContext() + void testDelegatingFilterProxyWithTargetBeanNameAndNotYetRefreshedApplicationContext() throws ServletException, IOException { MockServletContext sc = new MockServletContext(); @@ -175,8 +175,8 @@ public void testDelegatingFilterProxyWithTargetBeanNameAndNotYetRefreshedApplica } @Test - public void testDelegatingFilterProxyWithTargetBeanNameAndNoApplicationContext() - throws ServletException, IOException { + void testDelegatingFilterProxyWithTargetBeanNameAndNoApplicationContext() + throws ServletException { MockServletContext sc = new MockServletContext(); @@ -190,7 +190,7 @@ public void testDelegatingFilterProxyWithTargetBeanNameAndNoApplicationContext() } @Test - public void testDelegatingFilterProxyWithFilterName() throws ServletException, IOException { + void testDelegatingFilterProxyWithFilterName() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); @@ -217,7 +217,7 @@ public void testDelegatingFilterProxyWithFilterName() throws ServletException, I } @Test - public void testDelegatingFilterProxyWithLazyContextStartup() throws ServletException, IOException { + void testDelegatingFilterProxyWithLazyContextStartup() throws ServletException, IOException { ServletContext sc = new MockServletContext(); MockFilterConfig proxyConfig = new MockFilterConfig(sc); @@ -245,7 +245,7 @@ public void testDelegatingFilterProxyWithLazyContextStartup() throws ServletExce } @Test - public void testDelegatingFilterProxyWithTargetFilterLifecycle() throws ServletException, IOException { + void testDelegatingFilterProxyWithTargetFilterLifecycle() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); @@ -275,7 +275,7 @@ public void testDelegatingFilterProxyWithTargetFilterLifecycle() throws ServletE } @Test - public void testDelegatingFilterProxyWithFrameworkServletContext() throws ServletException, IOException { + void testDelegatingFilterProxyWithFrameworkServletContext() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); @@ -302,7 +302,7 @@ public void testDelegatingFilterProxyWithFrameworkServletContext() throws Servle } @Test - public void testDelegatingFilterProxyInjectedPreferred() throws ServletException, IOException { + void testDelegatingFilterProxyInjectedPreferred() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); @@ -331,7 +331,7 @@ public void testDelegatingFilterProxyInjectedPreferred() throws ServletException } @Test - public void testDelegatingFilterProxyNotInjectedWacServletAttrPreferred() + void testDelegatingFilterProxyNotInjectedWacServletAttrPreferred() throws ServletException, IOException { ServletContext sc = new MockServletContext(); @@ -367,7 +367,7 @@ public void testDelegatingFilterProxyNotInjectedWacServletAttrPreferred() } @Test - public void testDelegatingFilterProxyNotInjectedWithRootPreferred() throws ServletException, IOException { + void testDelegatingFilterProxyNotInjectedWithRootPreferred() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); @@ -404,13 +404,13 @@ public static class MockFilter implements Filter { public FilterConfig filterConfig; @Override - public void init(FilterConfig filterConfig) throws ServletException { + public void init(FilterConfig filterConfig) { this.filterConfig = filterConfig; } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) - throws IOException, ServletException { + throws IOException { request.setAttribute("called", Boolean.TRUE); } diff --git a/spring-web/src/test/java/org/springframework/web/filter/FormContentFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/FormContentFilterTests.java index 6bfd2c0e5f12..3a95417acac0 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/FormContentFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/FormContentFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -16,6 +16,7 @@ package org.springframework.web.filter; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -36,7 +37,7 @@ * * @author Rossen Stoyanchev */ -public class FormContentFilterTests { +class FormContentFilterTests { private final FormContentFilter filter = new FormContentFilter(); @@ -48,7 +49,7 @@ public class FormContentFilterTests { @BeforeEach - public void setup() { + void setup() { this.request = new MockHttpServletRequest("PUT", "/"); this.request.setContentType("application/x-www-form-urlencoded; charset=ISO-8859-1"); this.response = new MockHttpServletResponse(); @@ -57,10 +58,10 @@ public void setup() { @Test - public void wrapPutPatchAndDeleteOnly() throws Exception { + void wrapPutPatchAndDeleteOnly() throws Exception { for (HttpMethod method : HttpMethod.values()) { MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "/"); - request.setContent("foo=bar".getBytes("ISO-8859-1")); + request.setContent("foo=bar".getBytes(StandardCharsets.ISO_8859_1)); request.setContentType("application/x-www-form-urlencoded; charset=ISO-8859-1"); this.filterChain = new MockFilterChain(); this.filter.doFilter(request, this.response, this.filterChain); @@ -74,11 +75,11 @@ public void wrapPutPatchAndDeleteOnly() throws Exception { } @Test - public void wrapFormEncodedOnly() throws Exception { + void wrapFormEncodedOnly() throws Exception { String[] contentTypes = new String[] {"text/plain", "multipart/form-data"}; for (String contentType : contentTypes) { MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/"); - request.setContent("".getBytes("ISO-8859-1")); + request.setContent("".getBytes(StandardCharsets.ISO_8859_1)); request.setContentType(contentType); this.filterChain = new MockFilterChain(); this.filter.doFilter(request, this.response, this.filterChain); @@ -87,8 +88,8 @@ public void wrapFormEncodedOnly() throws Exception { } @Test - public void invalidMediaType() throws Exception { - this.request.setContent("".getBytes("ISO-8859-1")); + void invalidMediaType() throws Exception { + this.request.setContent("".getBytes(StandardCharsets.ISO_8859_1)); this.request.setContentType("foo"); this.filterChain = new MockFilterChain(); this.filter.doFilter(this.request, this.response, this.filterChain); @@ -96,17 +97,17 @@ public void invalidMediaType() throws Exception { } @Test - public void getParameter() throws Exception { - this.request.setContent("name=value".getBytes("ISO-8859-1")); + void getParameter() throws Exception { + this.request.setContent("name=value".getBytes(StandardCharsets.ISO_8859_1)); this.filter.doFilter(this.request, this.response, this.filterChain); assertThat(this.filterChain.getRequest().getParameter("name")).isEqualTo("value"); } @Test - public void getParameterFromQueryString() throws Exception { + void getParameterFromQueryString() throws Exception { this.request.addParameter("name", "value1"); - this.request.setContent("name=value2".getBytes("ISO-8859-1")); + this.request.setContent("name=value2".getBytes(StandardCharsets.ISO_8859_1)); this.filter.doFilter(this.request, this.response, this.filterChain); assertThat(this.filterChain.getRequest()).as("Request not wrapped").isNotSameAs(this.request); @@ -114,8 +115,8 @@ public void getParameterFromQueryString() throws Exception { } @Test - public void getParameterNullValue() throws Exception { - this.request.setContent("name=value".getBytes("ISO-8859-1")); + void getParameterNullValue() throws Exception { + this.request.setContent("name=value".getBytes(StandardCharsets.ISO_8859_1)); this.filter.doFilter(this.request, this.response, this.filterChain); assertThat(this.filterChain.getRequest()).as("Request not wrapped").isNotSameAs(this.request); @@ -123,10 +124,10 @@ public void getParameterNullValue() throws Exception { } @Test - public void getParameterNames() throws Exception { + void getParameterNames() throws Exception { this.request.addParameter("name1", "value1"); this.request.addParameter("name2", "value2"); - this.request.setContent("name1=value1&name3=value3&name4=value4".getBytes("ISO-8859-1")); + this.request.setContent("name1=value1&name3=value3&name4=value4".getBytes(StandardCharsets.ISO_8859_1)); this.filter.doFilter(this.request, this.response, this.filterChain); List names = Collections.list(this.filterChain.getRequest().getParameterNames()); @@ -136,11 +137,11 @@ public void getParameterNames() throws Exception { } @Test - public void getParameterValues() throws Exception { + void getParameterValues() throws Exception { this.request.setQueryString("name=value1&name=value2"); this.request.addParameter("name", "value1"); this.request.addParameter("name", "value2"); - this.request.setContent("name=value3&name=value4".getBytes("ISO-8859-1")); + this.request.setContent("name=value3&name=value4".getBytes(StandardCharsets.ISO_8859_1)); this.filter.doFilter(this.request, this.response, this.filterChain); String[] values = this.filterChain.getRequest().getParameterValues("name"); @@ -150,11 +151,11 @@ public void getParameterValues() throws Exception { } @Test - public void getParameterValuesFromQueryString() throws Exception { + void getParameterValuesFromQueryString() throws Exception { this.request.setQueryString("name=value1&name=value2"); this.request.addParameter("name", "value1"); this.request.addParameter("name", "value2"); - this.request.setContent("anotherName=anotherValue".getBytes("ISO-8859-1")); + this.request.setContent("anotherName=anotherValue".getBytes(StandardCharsets.ISO_8859_1)); this.filter.doFilter(this.request, this.response, this.filterChain); String[] values = this.filterChain.getRequest().getParameterValues("name"); @@ -164,10 +165,10 @@ public void getParameterValuesFromQueryString() throws Exception { } @Test - public void getParameterValuesFromFormContent() throws Exception { + void getParameterValuesFromFormContent() throws Exception { this.request.addParameter("name", "value1"); this.request.addParameter("name", "value2"); - this.request.setContent("anotherName=anotherValue".getBytes("ISO-8859-1")); + this.request.setContent("anotherName=anotherValue".getBytes(StandardCharsets.ISO_8859_1)); this.filter.doFilter(this.request, this.response, this.filterChain); String[] values = this.filterChain.getRequest().getParameterValues("anotherName"); @@ -177,10 +178,10 @@ public void getParameterValuesFromFormContent() throws Exception { } @Test - public void getParameterValuesInvalidName() throws Exception { + void getParameterValuesInvalidName() throws Exception { this.request.addParameter("name", "value1"); this.request.addParameter("name", "value2"); - this.request.setContent("anotherName=anotherValue".getBytes("ISO-8859-1")); + this.request.setContent("anotherName=anotherValue".getBytes(StandardCharsets.ISO_8859_1)); this.filter.doFilter(this.request, this.response, this.filterChain); String[] values = this.filterChain.getRequest().getParameterValues("noSuchParameter"); @@ -190,11 +191,11 @@ public void getParameterValuesInvalidName() throws Exception { } @Test - public void getParameterMap() throws Exception { + void getParameterMap() throws Exception { this.request.setQueryString("name=value1&name=value2"); this.request.addParameter("name", "value1"); this.request.addParameter("name", "value2"); - this.request.setContent("name=value3&name4=value4".getBytes("ISO-8859-1")); + this.request.setContent("name=value3&name4=value4".getBytes(StandardCharsets.ISO_8859_1)); this.filter.doFilter(this.request, this.response, this.filterChain); Map parameters = this.filterChain.getRequest().getParameterMap(); diff --git a/spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java index 21f38af66a4d..32ad293236e7 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java @@ -49,7 +49,7 @@ * @author Rob Winch * @author Brian Clozel */ -public class ForwardedHeaderFilterTests { +class ForwardedHeaderFilterTests { private static final String FORWARDED = "forwarded"; diff --git a/spring-web/src/test/java/org/springframework/web/filter/HiddenHttpMethodFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/HiddenHttpMethodFilterTests.java index db08c418cb7b..55509aa42f1f 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/HiddenHttpMethodFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/HiddenHttpMethodFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -34,26 +34,26 @@ * @author Arjen Poutsma * @author Brian Clozel */ -public class HiddenHttpMethodFilterTests { +class HiddenHttpMethodFilterTests { private final HiddenHttpMethodFilter filter = new HiddenHttpMethodFilter(); @Test - public void filterWithParameter() throws IOException, ServletException { + void filterWithParameter() throws IOException, ServletException { filterWithParameterForMethod("delete", "DELETE"); filterWithParameterForMethod("put", "PUT"); filterWithParameterForMethod("patch", "PATCH"); } @Test - public void filterWithParameterDisallowedMethods() throws IOException, ServletException { + void filterWithParameterDisallowedMethods() throws IOException, ServletException { filterWithParameterForMethod("trace", "POST"); filterWithParameterForMethod("head", "POST"); filterWithParameterForMethod("options", "POST"); } @Test - public void filterWithNoParameter() throws IOException, ServletException { + void filterWithNoParameter() throws IOException, ServletException { filterWithParameterForMethod(null, "POST"); } diff --git a/spring-web/src/test/java/org/springframework/web/filter/OncePerRequestFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/OncePerRequestFilterTests.java index 9a64248c69f9..504987114f9c 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/OncePerRequestFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/OncePerRequestFilterTests.java @@ -40,7 +40,7 @@ * @author Rossen Stoyanchev * @since 5.1.9 */ -public class OncePerRequestFilterTests { +class OncePerRequestFilterTests { private final TestOncePerRequestFilter filter = new TestOncePerRequestFilter(); @@ -50,7 +50,6 @@ public class OncePerRequestFilterTests { @BeforeEach - @SuppressWarnings("serial") public void setup() throws Exception { this.request = new MockHttpServletRequest(); this.request.setScheme("http"); @@ -61,7 +60,7 @@ public void setup() throws Exception { @Test - public void filterOnce() throws ServletException, IOException { + void filterOnce() throws ServletException, IOException { // Already filtered this.request.setAttribute(this.filter.getAlreadyFilteredAttributeName(), Boolean.TRUE); @@ -80,7 +79,7 @@ public void filterOnce() throws ServletException, IOException { } @Test - public void shouldNotFilterErrorDispatch() throws ServletException, IOException { + void shouldNotFilterErrorDispatch() throws ServletException, IOException { initErrorDispatch(); @@ -90,7 +89,7 @@ public void shouldNotFilterErrorDispatch() throws ServletException, IOException } @Test - public void shouldNotFilterNestedErrorDispatch() throws ServletException, IOException { + void shouldNotFilterNestedErrorDispatch() throws ServletException, IOException { initErrorDispatch(); this.request.setAttribute(this.filter.getAlreadyFilteredAttributeName(), Boolean.TRUE); diff --git a/spring-web/src/test/java/org/springframework/web/filter/RelativeRedirectFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/RelativeRedirectFilterTests.java index a031d2faa3f1..f0477634b103 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/RelativeRedirectFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/RelativeRedirectFilterTests.java @@ -38,7 +38,7 @@ * @author Rob Winch * @author Juergen Hoeller */ -public class RelativeRedirectFilterTests { +class RelativeRedirectFilterTests { private RelativeRedirectFilter filter = new RelativeRedirectFilter(); diff --git a/spring-web/src/test/java/org/springframework/web/filter/RequestContextFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/RequestContextFilterTests.java index fdfe302fbdf4..91dd31e04b02 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/RequestContextFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/RequestContextFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -16,8 +16,6 @@ package org.springframework.web.filter; -import java.io.IOException; - import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; @@ -38,15 +36,15 @@ * @author Rod Johnson * @author Juergen Hoeller */ -public class RequestContextFilterTests { +class RequestContextFilterTests { @Test - public void happyPath() throws Exception { + void happyPath() throws Exception { testFilterInvocation(null); } @Test - public void withException() throws Exception { + void withException() throws Exception { testFilterInvocation(new ServletException()); } @@ -59,7 +57,7 @@ private void testFilterInvocation(final ServletException sex) throws Exception { class DummyFilterChain implements FilterChain { public int invocations = 0; @Override - public void doFilter(ServletRequest req, ServletResponse resp) throws IOException, ServletException { + public void doFilter(ServletRequest req, ServletResponse resp) throws ServletException { ++invocations; if (invocations == 1) { assertThat(RequestContextHolder.currentRequestAttributes().getAttribute("myAttr", RequestAttributes.SCOPE_REQUEST)).isSameAs("myValue"); diff --git a/spring-web/src/test/java/org/springframework/web/filter/ServerHttpObservationFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/ServerHttpObservationFilterTests.java index 354e5c50a48f..0a3459e7af05 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/ServerHttpObservationFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/ServerHttpObservationFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -89,11 +89,10 @@ void filterShouldUseThrownException() throws Exception { void filterShouldUnwrapServletException() { IllegalArgumentException customError = new IllegalArgumentException("custom error"); - assertThatThrownBy(() -> { - this.filter.doFilter(this.request, this.response, (request, response) -> { - throw new ServletException(customError); - }); - }).isInstanceOf(ServletException.class); + assertThatThrownBy(() -> + this.filter.doFilter(this.request, this.response, (request, response) -> { + throw new ServletException(customError); + })).isInstanceOf(ServletException.class); ServerRequestObservationContext context = (ServerRequestObservationContext) this.request .getAttribute(ServerHttpObservationFilter.CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE); assertThat(context.getError()).isEqualTo(customError); @@ -102,11 +101,10 @@ void filterShouldUnwrapServletException() { @Test void filterShouldSetDefaultErrorStatusForBubblingExceptions() { - assertThatThrownBy(() -> { - this.filter.doFilter(this.request, this.response, (request, response) -> { - throw new ServletException(new IllegalArgumentException("custom error")); - }); - }).isInstanceOf(ServletException.class); + assertThatThrownBy(() -> + this.filter.doFilter(this.request, this.response, (request, response) -> { + throw new ServletException(new IllegalArgumentException("custom error")); + })).isInstanceOf(ServletException.class); assertThatHttpObservation().hasLowCardinalityKeyValue("outcome", "SERVER_ERROR") .hasLowCardinalityKeyValue("status", "500"); } diff --git a/spring-web/src/test/java/org/springframework/web/filter/ShallowEtagHeaderFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/ShallowEtagHeaderFilterTests.java index 8ab3db1165c6..f688e6cbb381 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/ShallowEtagHeaderFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/ShallowEtagHeaderFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -35,13 +35,13 @@ * @author Brian Clozel * @author Juergen Hoeller */ -public class ShallowEtagHeaderFilterTests { +class ShallowEtagHeaderFilterTests { private final ShallowEtagHeaderFilter filter = new ShallowEtagHeaderFilter(); @Test - public void isEligibleForEtag() { + void isEligibleForEtag() { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels"); MockHttpServletResponse response = new MockHttpServletResponse(); @@ -60,7 +60,7 @@ public void isEligibleForEtag() { } @Test - public void filterNoMatch() throws Exception { + void filterNoMatch() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels"); MockHttpServletResponse response = new MockHttpServletResponse(); @@ -79,7 +79,7 @@ public void filterNoMatch() throws Exception { } @Test - public void filterNoMatchWeakETag() throws Exception { + void filterNoMatchWeakETag() throws Exception { this.filter.setWriteWeakETag(true); final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels"); MockHttpServletResponse response = new MockHttpServletResponse(); @@ -99,7 +99,7 @@ public void filterNoMatchWeakETag() throws Exception { } @Test - public void filterMatch() throws Exception { + void filterMatch() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels"); String etag = "\"0b10a8db164e0754105b7a99be72e3fe5\""; request.addHeader("If-None-Match", etag); @@ -121,7 +121,7 @@ public void filterMatch() throws Exception { } @Test - public void filterMatchWeakEtag() throws Exception { + void filterMatchWeakEtag() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels"); String etag = "\"0b10a8db164e0754105b7a99be72e3fe5\""; request.addHeader("If-None-Match", "W/" + etag); @@ -143,7 +143,7 @@ public void filterMatchWeakEtag() throws Exception { } @Test - public void filterWriter() throws Exception { + void filterWriter() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels"); String etag = "\"0b10a8db164e0754105b7a99be72e3fe5\""; request.addHeader("If-None-Match", etag); @@ -185,7 +185,7 @@ public void filterWriterWithDisabledCaching() throws Exception { } @Test - public void filterSendError() throws Exception { + void filterSendError() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels"); MockHttpServletResponse response = new MockHttpServletResponse(); @@ -205,7 +205,7 @@ public void filterSendError() throws Exception { } @Test - public void filterSendErrorMessage() throws Exception { + void filterSendErrorMessage() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels"); MockHttpServletResponse response = new MockHttpServletResponse(); @@ -226,7 +226,7 @@ public void filterSendErrorMessage() throws Exception { } @Test - public void filterSendRedirect() throws Exception { + void filterSendRedirect() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels"); MockHttpServletResponse response = new MockHttpServletResponse(); diff --git a/spring-web/src/test/java/org/springframework/web/filter/reactive/HiddenHttpMethodFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/reactive/HiddenHttpMethodFilterTests.java index 8b360081c7e8..8a468282a675 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/reactive/HiddenHttpMethodFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/reactive/HiddenHttpMethodFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -36,7 +36,7 @@ * @author Greg Turnquist * @author Rossen Stoyanchev */ -public class HiddenHttpMethodFilterTests { +class HiddenHttpMethodFilterTests { private final HiddenHttpMethodFilter filter = new HiddenHttpMethodFilter(); @@ -44,38 +44,38 @@ public class HiddenHttpMethodFilterTests { @Test - public void filterWithParameter() { + void filterWithParameter() { postForm("_method=DELETE").block(Duration.ZERO); assertThat(this.filterChain.getHttpMethod()).isEqualTo(HttpMethod.DELETE); } @Test - public void filterWithParameterMethodNotAllowed() { + void filterWithParameterMethodNotAllowed() { postForm("_method=TRACE").block(Duration.ZERO); assertThat(this.filterChain.getHttpMethod()).isEqualTo(HttpMethod.POST); } @Test - public void filterWithNoParameter() { + void filterWithNoParameter() { postForm("").block(Duration.ZERO); assertThat(this.filterChain.getHttpMethod()).isEqualTo(HttpMethod.POST); } @Test - public void filterWithEmptyStringParameter() { + void filterWithEmptyStringParameter() { postForm("_method=").block(Duration.ZERO); assertThat(this.filterChain.getHttpMethod()).isEqualTo(HttpMethod.POST); } @Test - public void filterWithDifferentMethodParam() { + void filterWithDifferentMethodParam() { this.filter.setMethodParamName("_foo"); postForm("_foo=DELETE").block(Duration.ZERO); assertThat(this.filterChain.getHttpMethod()).isEqualTo(HttpMethod.DELETE); } @Test - public void filterWithHttpPut() { + void filterWithHttpPut() { ServerWebExchange exchange = MockServerWebExchange.from( MockServerHttpRequest.put("/") diff --git a/spring-web/src/test/java/org/springframework/web/jsf/DelegatingNavigationHandlerTests.java b/spring-web/src/test/java/org/springframework/web/jsf/DelegatingNavigationHandlerTests.java index 51904f646872..3b5178d5b438 100644 --- a/spring-web/src/test/java/org/springframework/web/jsf/DelegatingNavigationHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/jsf/DelegatingNavigationHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -30,7 +30,7 @@ * @author Colin Sampaleanu * @author Juergen Hoeller */ -public class DelegatingNavigationHandlerTests { +class DelegatingNavigationHandlerTests { private final MockFacesContext facesContext = new MockFacesContext(); @@ -47,7 +47,7 @@ protected BeanFactory getBeanFactory(FacesContext facesContext) { @Test - public void handleNavigationWithoutDecoration() { + void handleNavigationWithoutDecoration() { TestNavigationHandler targetHandler = new TestNavigationHandler(); beanFactory.addBean("jsfNavigationHandler", targetHandler); @@ -57,7 +57,7 @@ public void handleNavigationWithoutDecoration() { } @Test - public void handleNavigationWithDecoration() { + void handleNavigationWithDecoration() { TestDecoratingNavigationHandler targetHandler = new TestDecoratingNavigationHandler(); beanFactory.addBean("jsfNavigationHandler", targetHandler); diff --git a/spring-web/src/test/java/org/springframework/web/jsf/DelegatingPhaseListenerTests.java b/spring-web/src/test/java/org/springframework/web/jsf/DelegatingPhaseListenerTests.java index 00c035370403..b059d88acb8d 100644 --- a/spring-web/src/test/java/org/springframework/web/jsf/DelegatingPhaseListenerTests.java +++ b/spring-web/src/test/java/org/springframework/web/jsf/DelegatingPhaseListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -31,7 +31,7 @@ * @author Colin Sampaleanu * @author Juergen Hoeller */ -public class DelegatingPhaseListenerTests { +class DelegatingPhaseListenerTests { private final MockFacesContext facesContext = new MockFacesContext(); @@ -47,7 +47,7 @@ protected ListableBeanFactory getBeanFactory(FacesContext facesContext) { @SuppressWarnings("unchecked") @Test - public void beforeAndAfterPhaseWithSingleTarget() { + void beforeAndAfterPhaseWithSingleTarget() { TestListener target = new TestListener(); beanFactory.addBean("testListener", target); @@ -63,7 +63,7 @@ public void beforeAndAfterPhaseWithSingleTarget() { @SuppressWarnings("unchecked") @Test - public void beforeAndAfterPhaseWithMultipleTargets() { + void beforeAndAfterPhaseWithMultipleTargets() { TestListener target1 = new TestListener(); TestListener target2 = new TestListener(); beanFactory.addBean("testListener1", target1); diff --git a/spring-web/src/test/java/org/springframework/web/method/ControllerAdviceBeanTests.java b/spring-web/src/test/java/org/springframework/web/method/ControllerAdviceBeanTests.java index efffcbc4dddf..b04f5c22a961 100644 --- a/spring-web/src/test/java/org/springframework/web/method/ControllerAdviceBeanTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/ControllerAdviceBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -46,16 +46,16 @@ * @author Brian Clozel * @author Sam Brannen */ -public class ControllerAdviceBeanTests { +class ControllerAdviceBeanTests { @Test - public void constructorPreconditions() { + void constructorPreconditions() { assertThatIllegalArgumentException() .isThrownBy(() -> new ControllerAdviceBean(null)) .withMessage("Bean must not be null"); assertThatIllegalArgumentException() - .isThrownBy(() -> new ControllerAdviceBean((String) null, null)) + .isThrownBy(() -> new ControllerAdviceBean(null, null)) .withMessage("Bean name must contain text"); assertThatIllegalArgumentException() @@ -72,7 +72,7 @@ public void constructorPreconditions() { } @Test - public void equalsHashCodeAndToStringForBeanName() { + void equalsHashCodeAndToStringForBeanName() { String beanName = "myBean"; BeanFactory beanFactory = mock(); given(beanFactory.containsBean(beanName)).willReturn(true); @@ -83,7 +83,7 @@ public void equalsHashCodeAndToStringForBeanName() { } @Test - public void equalsHashCodeAndToStringForBeanInstance() { + void equalsHashCodeAndToStringForBeanInstance() { String toString = "beanInstance"; Object beanInstance = new Object() { @Override @@ -97,39 +97,39 @@ public String toString() { } @Test - public void orderedWithLowestPrecedenceByDefaultForBeanName() { + void orderedWithLowestPrecedenceByDefaultForBeanName() { assertOrder(SimpleControllerAdvice.class, Ordered.LOWEST_PRECEDENCE); } @Test - public void orderedWithLowestPrecedenceByDefaultForBeanInstance() { + void orderedWithLowestPrecedenceByDefaultForBeanInstance() { assertOrder(new SimpleControllerAdvice(), Ordered.LOWEST_PRECEDENCE); } @Test - public void orderedViaOrderedInterfaceForBeanName() { + void orderedViaOrderedInterfaceForBeanName() { assertOrder(OrderedControllerAdvice.class, 42); } @Test - public void orderedViaOrderedInterfaceForBeanInstance() { + void orderedViaOrderedInterfaceForBeanInstance() { assertOrder(new OrderedControllerAdvice(), 42); } @Test - public void orderedViaAnnotationForBeanName() { + void orderedViaAnnotationForBeanName() { assertOrder(OrderAnnotationControllerAdvice.class, 100); assertOrder(PriorityAnnotationControllerAdvice.class, 200); } @Test - public void orderedViaAnnotationForBeanInstance() { + void orderedViaAnnotationForBeanInstance() { assertOrder(new OrderAnnotationControllerAdvice(), 100); assertOrder(new PriorityAnnotationControllerAdvice(), 200); } @Test - public void shouldMatchAll() { + void shouldMatchAll() { ControllerAdviceBean bean = new ControllerAdviceBean(new SimpleControllerAdvice()); assertApplicable("should match all", bean, AnnotatedController.class); assertApplicable("should match all", bean, ImplementationController.class); @@ -138,7 +138,7 @@ public void shouldMatchAll() { } @Test - public void basePackageSupport() { + void basePackageSupport() { ControllerAdviceBean bean = new ControllerAdviceBean(new BasePackageSupport()); assertApplicable("base package support", bean, AnnotatedController.class); assertApplicable("base package support", bean, ImplementationController.class); @@ -147,7 +147,7 @@ public void basePackageSupport() { } @Test - public void basePackageValueSupport() { + void basePackageValueSupport() { ControllerAdviceBean bean = new ControllerAdviceBean(new BasePackageValueSupport()); assertApplicable("base package support", bean, AnnotatedController.class); assertApplicable("base package support", bean, ImplementationController.class); @@ -156,14 +156,14 @@ public void basePackageValueSupport() { } @Test - public void annotationSupport() { + void annotationSupport() { ControllerAdviceBean bean = new ControllerAdviceBean(new AnnotationSupport()); assertApplicable("annotation support", bean, AnnotatedController.class); assertNotApplicable("this bean is not annotated", bean, InheritanceController.class); } @Test - public void markerClassSupport() { + void markerClassSupport() { ControllerAdviceBean bean = new ControllerAdviceBean(new MarkerClassSupport()); assertApplicable("base package class support", bean, AnnotatedController.class); assertApplicable("base package class support", bean, ImplementationController.class); @@ -172,7 +172,7 @@ public void markerClassSupport() { } @Test - public void shouldNotMatch() { + void shouldNotMatch() { ControllerAdviceBean bean = new ControllerAdviceBean(new ShouldNotMatch()); assertNotApplicable("should not match", bean, AnnotatedController.class); assertNotApplicable("should not match", bean, ImplementationController.class); @@ -181,7 +181,7 @@ public void shouldNotMatch() { } @Test - public void assignableTypesSupport() { + void assignableTypesSupport() { ControllerAdviceBean bean = new ControllerAdviceBean(new AssignableTypesSupport()); assertApplicable("controller implements assignable", bean, ImplementationController.class); assertApplicable("controller inherits assignable", bean, InheritanceController.class); @@ -190,7 +190,7 @@ public void assignableTypesSupport() { } @Test - public void multipleMatch() { + void multipleMatch() { ControllerAdviceBean bean = new ControllerAdviceBean(new MultipleSelectorsSupport()); assertApplicable("controller implements assignable", bean, ImplementationController.class); assertApplicable("controller is annotated", bean, AnnotatedController.class); diff --git a/spring-web/src/test/java/org/springframework/web/method/HandlerMethodTests.java b/spring-web/src/test/java/org/springframework/web/method/HandlerMethodTests.java index 6701945f27fd..c8cfd8bf1d74 100644 --- a/spring-web/src/test/java/org/springframework/web/method/HandlerMethodTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/HandlerMethodTests.java @@ -35,7 +35,7 @@ * * @author Rossen Stoyanchev */ -public class HandlerMethodTests { +class HandlerMethodTests { @Test void shouldValidateArgsWithConstraintsDirectlyOnClass() { diff --git a/spring-web/src/test/java/org/springframework/web/method/HandlerTypePredicateTests.java b/spring-web/src/test/java/org/springframework/web/method/HandlerTypePredicateTests.java index a0fc245280a3..1b8f6b7a7fad 100644 --- a/spring-web/src/test/java/org/springframework/web/method/HandlerTypePredicateTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/HandlerTypePredicateTests.java @@ -30,10 +30,10 @@ * * @author Rossen Stoyanchev */ -public class HandlerTypePredicateTests { +class HandlerTypePredicateTests { @Test - public void forAnnotation() { + void forAnnotation() { Predicate> predicate = HandlerTypePredicate.forAnnotation(Controller.class); @@ -43,7 +43,7 @@ public void forAnnotation() { } @Test - public void forAnnotationWithException() { + void forAnnotationWithException() { Predicate> predicate = HandlerTypePredicate.forAnnotation(Controller.class) .and(HandlerTypePredicate.forAssignableType(Special.class)); diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/CookieValueMethodArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/CookieValueMethodArgumentResolverTests.java index 581e4fe2b129..934ed75ebd13 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/CookieValueMethodArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/CookieValueMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -40,7 +40,7 @@ * @author Arjen Poutsma * @author Rossen Stoyanchev */ -public class CookieValueMethodArgumentResolverTests { +class CookieValueMethodArgumentResolverTests { private AbstractCookieValueMethodArgumentResolver resolver; @@ -56,7 +56,7 @@ public class CookieValueMethodArgumentResolverTests { @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { resolver = new TestCookieValueMethodArgumentResolver(); Method method = getClass().getMethod("params", Cookie.class, String.class, String.class); @@ -70,14 +70,14 @@ public void setUp() throws Exception { @Test - public void supportsParameter() { + void supportsParameter() { assertThat(resolver.supportsParameter(paramNamedCookie)).as("Cookie parameter not supported").isTrue(); assertThat(resolver.supportsParameter(paramNamedDefaultValueString)).as("Cookie string parameter not supported").isTrue(); assertThat(resolver.supportsParameter(paramString)).as("non-@CookieValue parameter supported").isFalse(); } @Test - public void resolveCookieDefaultValue() throws Exception { + void resolveCookieDefaultValue() throws Exception { Object result = resolver.resolveArgument(paramNamedDefaultValueString, null, webRequest, null); boolean condition = result instanceof String; @@ -86,7 +86,7 @@ public void resolveCookieDefaultValue() throws Exception { } @Test - public void notFound() throws Exception { + void notFound() { assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() -> resolver.resolveArgument(paramNamedCookie, null, webRequest, null)); } @@ -98,7 +98,7 @@ public TestCookieValueMethodArgumentResolver() { } @Override - protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { + protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) { return null; } } diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolverTests.java index 1bf57b4bb2ec..bcb510d54cbc 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -36,7 +36,7 @@ * * @author Rossen Stoyanchev */ -public class ErrorsMethodArgumentResolverTests { +class ErrorsMethodArgumentResolverTests { private final ErrorsMethodArgumentResolver resolver = new ErrorsMethodArgumentResolver(); @@ -48,7 +48,7 @@ public class ErrorsMethodArgumentResolverTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { paramErrors = new MethodParameter(getClass().getDeclaredMethod("handle", Errors.class), 0); bindingResult = new WebDataBinder(new Object(), "attr").getBindingResult(); webRequest = new ServletWebRequest(new MockHttpServletRequest()); @@ -56,12 +56,12 @@ public void setup() throws Exception { @Test - public void supports() { + void supports() { resolver.supportsParameter(paramErrors); } @Test - public void bindingResult() throws Exception { + void bindingResult() throws Exception { ModelAndViewContainer mavContainer = new ModelAndViewContainer(); mavContainer.addAttribute("ignore1", "value1"); mavContainer.addAttribute("ignore2", "value2"); @@ -75,7 +75,7 @@ public void bindingResult() throws Exception { } @Test - public void bindingResultNotFound() throws Exception { + void bindingResultNotFound() { ModelAndViewContainer mavContainer = new ModelAndViewContainer(); mavContainer.addAllAttributes(bindingResult.getModel()); mavContainer.addAttribute("ignore1", "value1"); @@ -85,7 +85,7 @@ public void bindingResultNotFound() throws Exception { } @Test - public void noBindingResult() throws Exception { + void noBindingResult() { assertThatIllegalStateException().isThrownBy(() -> resolver.resolveArgument(paramErrors, new ModelAndViewContainer(), webRequest, null)); } diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java index 773862d55e35..eeccbd1ca68f 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -37,24 +37,24 @@ * * @author Rossen Stoyanchev */ -public class ExceptionHandlerMethodResolverTests { +class ExceptionHandlerMethodResolverTests { @Test - public void resolveMethodFromAnnotation() { + void resolveMethodFromAnnotation() { ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(ExceptionController.class); IOException exception = new IOException(); assertThat(resolver.resolveMethod(exception).getName()).isEqualTo("handleIOException"); } @Test - public void resolveMethodFromArgument() { + void resolveMethodFromArgument() { ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(ExceptionController.class); IllegalArgumentException exception = new IllegalArgumentException(); assertThat(resolver.resolveMethod(exception).getName()).isEqualTo("handleIllegalArgumentException"); } @Test - public void resolveMethodExceptionSubType() { + void resolveMethodExceptionSubType() { ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(ExceptionController.class); IOException ioException = new FileNotFoundException(); assertThat(resolver.resolveMethod(ioException).getName()).isEqualTo("handleIOException"); @@ -63,14 +63,14 @@ public void resolveMethodExceptionSubType() { } @Test - public void resolveMethodBestMatch() { + void resolveMethodBestMatch() { ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(ExceptionController.class); SocketException exception = new SocketException(); assertThat(resolver.resolveMethod(exception).getName()).isEqualTo("handleSocketException"); } @Test - public void resolveMethodNoMatch() { + void resolveMethodNoMatch() { ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(ExceptionController.class); Exception exception = new Exception(); assertThat(resolver.resolveMethod(exception)).as("1st lookup").isNull(); @@ -78,7 +78,7 @@ public void resolveMethodNoMatch() { } @Test - public void resolveMethodExceptionCause() { + void resolveMethodExceptionCause() { ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(ExceptionController.class); SocketException bindException = new BindException(); @@ -90,20 +90,20 @@ public void resolveMethodExceptionCause() { } @Test - public void resolveMethodInherited() { + void resolveMethodInherited() { ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(InheritedController.class); IOException exception = new IOException(); assertThat(resolver.resolveMethod(exception).getName()).isEqualTo("handleIOException"); } @Test - public void ambiguousExceptionMapping() { + void ambiguousExceptionMapping() { assertThatIllegalStateException().isThrownBy(() -> new ExceptionHandlerMethodResolver(AmbiguousController.class)); } @Test - public void noExceptionMapping() { + void noExceptionMapping() { assertThatIllegalStateException().isThrownBy(() -> new ExceptionHandlerMethodResolver(NoExceptionController.class)); } @@ -143,8 +143,7 @@ static class AmbiguousController { public void handle() {} @ExceptionHandler({BindException.class, IllegalArgumentException.class}) - public String handle1(Exception ex, HttpServletRequest request, HttpServletResponse response) - throws IOException { + public String handle1(Exception ex, HttpServletRequest request, HttpServletResponse response) { return ClassUtils.getShortName(ex.getClass()); } diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/ExpressionValueMethodArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/ExpressionValueMethodArgumentResolverTests.java index 86c419c8dd12..28635ac7d6ee 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/ExpressionValueMethodArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/ExpressionValueMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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,7 +38,7 @@ * * @author Rossen Stoyanchev */ -public class ExpressionValueMethodArgumentResolverTests { +class ExpressionValueMethodArgumentResolverTests { private ExpressionValueMethodArgumentResolver resolver; @@ -51,7 +51,6 @@ public class ExpressionValueMethodArgumentResolverTests { private NativeWebRequest webRequest; @BeforeEach - @SuppressWarnings("resource") public void setUp() throws Exception { GenericWebApplicationContext context = new GenericWebApplicationContext(); context.refresh(); @@ -69,19 +68,19 @@ public void setUp() throws Exception { } @AfterEach - public void teardown() { + void teardown() { RequestContextHolder.resetRequestAttributes(); } @Test - public void supportsParameter() throws Exception { + void supportsParameter() throws Exception { assertThat(resolver.supportsParameter(paramSystemProperty)).isTrue(); assertThat(resolver.supportsParameter(paramContextPath)).isTrue(); assertThat(resolver.supportsParameter(paramNotSupported)).isFalse(); } @Test - public void resolveSystemProperty() throws Exception { + void resolveSystemProperty() throws Exception { System.setProperty("systemProperty", "22"); Object value = resolver.resolveArgument(paramSystemProperty, null, webRequest, null); System.clearProperty("systemProperty"); @@ -90,7 +89,7 @@ public void resolveSystemProperty() throws Exception { } @Test - public void resolveContextPath() throws Exception { + void resolveContextPath() throws Exception { webRequest.getNativeRequest(MockHttpServletRequest.class).setContextPath("/contextPath"); Object value = resolver.resolveArgument(paramContextPath, null, webRequest, null); diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/InitBinderDataBinderFactoryTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/InitBinderDataBinderFactoryTests.java index 08fd411307c4..99d3e14d2180 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/InitBinderDataBinderFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/InitBinderDataBinderFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -44,7 +44,7 @@ * * @author Rossen Stoyanchev */ -public class InitBinderDataBinderFactoryTests { +class InitBinderDataBinderFactoryTests { private final ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer(); @@ -56,7 +56,7 @@ public class InitBinderDataBinderFactoryTests { @Test - public void createBinder() throws Exception { + void createBinder() throws Exception { WebDataBinderFactory factory = createFactory("initBinder", WebDataBinder.class); WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, null); @@ -65,7 +65,7 @@ public void createBinder() throws Exception { } @Test - public void createBinderWithGlobalInitialization() throws Exception { + void createBinderWithGlobalInitialization() throws Exception { ConversionService conversionService = new DefaultFormattingConversionService(); bindingInitializer.setConversionService(conversionService); @@ -76,7 +76,7 @@ public void createBinderWithGlobalInitialization() throws Exception { } @Test - public void createBinderWithAttrName() throws Exception { + void createBinderWithAttrName() throws Exception { WebDataBinderFactory factory = createFactory("initBinderWithAttributeName", WebDataBinder.class); WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, "foo"); @@ -85,7 +85,7 @@ public void createBinderWithAttrName() throws Exception { } @Test - public void createBinderWithAttrNameNoMatch() throws Exception { + void createBinderWithAttrNameNoMatch() throws Exception { WebDataBinderFactory factory = createFactory("initBinderWithAttributeName", WebDataBinder.class); WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, "invalidName"); @@ -93,7 +93,7 @@ public void createBinderWithAttrNameNoMatch() throws Exception { } @Test - public void createBinderNullAttrName() throws Exception { + void createBinderNullAttrName() throws Exception { WebDataBinderFactory factory = createFactory("initBinderWithAttributeName", WebDataBinder.class); WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, null); @@ -101,14 +101,14 @@ public void createBinderNullAttrName() throws Exception { } @Test - public void returnValueNotExpected() throws Exception { + void returnValueNotExpected() throws Exception { WebDataBinderFactory factory = createFactory("initBinderReturnValue", WebDataBinder.class); assertThatIllegalStateException().isThrownBy(() -> factory.createBinder(this.webRequest, null, "invalidName")); } @Test - public void createBinderTypeConversion() throws Exception { + void createBinderTypeConversion() throws Exception { this.webRequest.getNativeRequest(MockHttpServletRequest.class).setParameter("requestParam", "22"); this.argumentResolvers.addResolver(new RequestParamMethodArgumentResolver(null, false)); diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/MapMethodProcessorTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/MapMethodProcessorTests.java index 4482307abe7f..483f88d80f3f 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/MapMethodProcessorTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/MapMethodProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -39,7 +39,7 @@ * * @author Rossen Stoyanchev */ -public class MapMethodProcessorTests { +class MapMethodProcessorTests { private MapMethodProcessor processor; @@ -52,7 +52,7 @@ public class MapMethodProcessorTests { @BeforeEach - public void setUp() throws Exception { + void setUp() { this.processor = new MapMethodProcessor(); this.mavContainer = new ModelAndViewContainer(); this.webRequest = new ServletWebRequest(new MockHttpServletRequest()); @@ -60,7 +60,7 @@ public void setUp() throws Exception { @Test - public void supportsParameter() { + void supportsParameter() { assertThat(this.processor.supportsParameter( this.resolvable.annotNotPresent().arg(Map.class, String.class, Object.class))).isTrue(); assertThat(this.processor.supportsParameter( @@ -68,18 +68,18 @@ public void supportsParameter() { } @Test - public void supportsReturnType() { + void supportsReturnType() { assertThat(this.processor.supportsReturnType(this.resolvable.returnType())).isTrue(); } @Test - public void resolveArgumentValue() throws Exception { + void resolveArgumentValue() throws Exception { MethodParameter param = this.resolvable.annotNotPresent().arg(Map.class, String.class, Object.class); assertThat(this.processor.resolveArgument(param, this.mavContainer, this.webRequest, null)).isSameAs(this.mavContainer.getModel()); } @Test - public void handleMapReturnValue() throws Exception { + void handleMapReturnValue() throws Exception { this.mavContainer.addAttribute("attr1", "value1"); Map returnValue = new ModelMap("attr2", "value2"); diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessorTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessorTests.java index 9335194e8e4f..8ee2c336df47 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessorTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -65,7 +65,7 @@ * @author Rossen Stoyanchev * @author Vladislav Kisel */ -public class ModelAttributeMethodProcessorTests { +class ModelAttributeMethodProcessorTests { private NativeWebRequest request; @@ -86,7 +86,7 @@ public class ModelAttributeMethodProcessorTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { this.request = new ServletWebRequest(new MockHttpServletRequest()); this.container = new ModelAndViewContainer(); this.processor = new ModelAttributeMethodProcessor(false); @@ -112,7 +112,7 @@ public void setup() throws Exception { @Test - public void supportedParameters() { + void supportedParameters() { assertThat(this.processor.supportsParameter(this.paramNamedValidModelAttr)).isTrue(); assertThat(this.processor.supportsParameter(this.paramModelAttr)).isTrue(); @@ -122,7 +122,7 @@ public void supportedParameters() { } @Test - public void supportedParametersInDefaultResolutionMode() { + void supportedParametersInDefaultResolutionMode() { this.processor = new ModelAttributeMethodProcessor(true); // Only non-simple types, even if not annotated @@ -135,34 +135,34 @@ public void supportedParametersInDefaultResolutionMode() { } @Test - public void supportedReturnTypes() { + void supportedReturnTypes() { this.processor = new ModelAttributeMethodProcessor(false); assertThat(this.processor.supportsReturnType(returnParamNamedModelAttr)).isTrue(); assertThat(this.processor.supportsReturnType(returnParamNonSimpleType)).isFalse(); } @Test - public void supportedReturnTypesInDefaultResolutionMode() { + void supportedReturnTypesInDefaultResolutionMode() { this.processor = new ModelAttributeMethodProcessor(true); assertThat(this.processor.supportsReturnType(returnParamNamedModelAttr)).isTrue(); assertThat(this.processor.supportsReturnType(returnParamNonSimpleType)).isTrue(); } @Test - public void bindExceptionRequired() { + void bindExceptionRequired() { assertThat(this.processor.isBindExceptionRequired(null, this.paramNonSimpleType)).isTrue(); assertThat(this.processor.isBindExceptionRequired(null, this.paramNamedValidModelAttr)).isFalse(); } @Test - public void resolveArgumentFromModel() throws Exception { + void resolveArgumentFromModel() throws Exception { testGetAttributeFromModel("attrName", this.paramNamedValidModelAttr); testGetAttributeFromModel("testBean", this.paramModelAttr); testGetAttributeFromModel("testBean", this.paramNonSimpleType); } @Test - public void resolveArgumentViaDefaultConstructor() throws Exception { + void resolveArgumentViaDefaultConstructor() throws Exception { WebDataBinder dataBinder = new WebRequestDataBinder(null); dataBinder.setTargetType(ResolvableType.forMethodParameter(this.paramNamedValidModelAttr)); @@ -174,7 +174,7 @@ public void resolveArgumentViaDefaultConstructor() throws Exception { } @Test - public void resolveArgumentValidation() throws Exception { + void resolveArgumentValidation() throws Exception { String name = "attrName"; Object target = new TestBean(); this.container.addAttribute(name, target); @@ -191,7 +191,7 @@ public void resolveArgumentValidation() throws Exception { } @Test - public void resolveArgumentBindingDisabledPreviously() throws Exception { + void resolveArgumentBindingDisabledPreviously() throws Exception { String name = "attrName"; Object target = new TestBean(); this.container.addAttribute(name, target); @@ -211,7 +211,7 @@ public void resolveArgumentBindingDisabledPreviously() throws Exception { } @Test - public void resolveArgumentBindingDisabled() throws Exception { + void resolveArgumentBindingDisabled() throws Exception { String name = "noBindAttr"; Object target = new TestBean(); this.container.addAttribute(name, target); @@ -228,7 +228,7 @@ public void resolveArgumentBindingDisabled() throws Exception { } @Test - public void resolveArgumentBindException() throws Exception { + void resolveArgumentBindException() throws Exception { String name = "testBean"; Object target = new TestBean(); this.container.getModel().addAttribute(target); @@ -269,13 +269,13 @@ public void resolveArgumentOrdering() throws Exception { } @Test - public void handleAnnotatedReturnValue() throws Exception { + void handleAnnotatedReturnValue() throws Exception { this.processor.handleReturnValue("expected", this.returnParamNamedModelAttr, this.container, this.request); assertThat(this.container.getModel().get("modelAttrName")).isEqualTo("expected"); } @Test - public void handleNotAnnotatedReturnValue() throws Exception { + void handleNotAnnotatedReturnValue() throws Exception { TestBean testBean = new TestBean("expected"); this.processor.handleReturnValue(testBean, this.returnParamNonSimpleType, this.container, this.request); assertThat(this.container.getModel().get("testBean")).isSameAs(testBean); diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/ModelFactoryOrderingTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/ModelFactoryOrderingTests.java index 3134256e53ce..59e1a2c3db36 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/ModelFactoryOrderingTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/ModelFactoryOrderingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -138,7 +138,7 @@ private void assertInvokedBefore(String beforeMethod, String... afterMethods) { List actual = getInvokedMethods(); for (String afterMethod : afterMethods) { assertThat(actual.indexOf(beforeMethod)) - .as(beforeMethod + " should be before " + afterMethod + ". Actual order: " + actual.toString()) + .as(beforeMethod + " should be before " + afterMethod + ". Actual order: " + actual) .isLessThan(actual.indexOf(afterMethod)); } } @@ -156,7 +156,7 @@ public void handle() { } @SuppressWarnings("unchecked") - T updateAndReturn(Model model, String methodName, T returnValue) throws IOException { + T updateAndReturn(Model model, String methodName, T returnValue) { ((List) model.asMap().get("methods")).add(methodName); return returnValue; } diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/ModelFactoryTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/ModelFactoryTests.java index c9091e108444..ee41bbc372ee 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/ModelFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/ModelFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -51,7 +51,7 @@ * * @author Rossen Stoyanchev */ -public class ModelFactoryTests { +class ModelFactoryTests { private NativeWebRequest webRequest; @@ -65,7 +65,7 @@ public class ModelFactoryTests { @BeforeEach - public void setUp() throws Exception { + void setUp() { this.webRequest = new ServletWebRequest(new MockHttpServletRequest()); this.attributeStore = new DefaultSessionAttributeStore(); this.attributeHandler = new SessionAttributesHandler(TestController.class, this.attributeStore); @@ -75,7 +75,7 @@ public void setUp() throws Exception { @Test - public void modelAttributeMethod() throws Exception { + void modelAttributeMethod() throws Exception { ModelFactory modelFactory = createModelFactory("modelAttr", Model.class); HandlerMethod handlerMethod = createHandlerMethod("handle"); modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod); @@ -84,7 +84,7 @@ public void modelAttributeMethod() throws Exception { } @Test - public void modelAttributeMethodWithExplicitName() throws Exception { + void modelAttributeMethodWithExplicitName() throws Exception { ModelFactory modelFactory = createModelFactory("modelAttrWithName"); HandlerMethod handlerMethod = createHandlerMethod("handle"); modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod); @@ -93,7 +93,7 @@ public void modelAttributeMethodWithExplicitName() throws Exception { } @Test - public void modelAttributeMethodWithNameByConvention() throws Exception { + void modelAttributeMethodWithNameByConvention() throws Exception { ModelFactory modelFactory = createModelFactory("modelAttrConvention"); HandlerMethod handlerMethod = createHandlerMethod("handle"); modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod); @@ -102,7 +102,7 @@ public void modelAttributeMethodWithNameByConvention() throws Exception { } @Test - public void modelAttributeMethodWithNullReturnValue() throws Exception { + void modelAttributeMethodWithNullReturnValue() throws Exception { ModelFactory modelFactory = createModelFactory("nullModelAttr"); HandlerMethod handlerMethod = createHandlerMethod("handle"); modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod); @@ -112,7 +112,7 @@ public void modelAttributeMethodWithNullReturnValue() throws Exception { } @Test - public void modelAttributeWithBindingDisabled() throws Exception { + void modelAttributeWithBindingDisabled() throws Exception { ModelFactory modelFactory = createModelFactory("modelAttrWithBindingDisabled"); HandlerMethod handlerMethod = createHandlerMethod("handle"); modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod); @@ -122,7 +122,7 @@ public void modelAttributeWithBindingDisabled() throws Exception { } @Test - public void modelAttributeFromSessionWithBindingDisabled() throws Exception { + void modelAttributeFromSessionWithBindingDisabled() throws Exception { Foo foo = new Foo(); this.attributeStore.storeAttribute(this.webRequest, "foo", foo); @@ -136,7 +136,7 @@ public void modelAttributeFromSessionWithBindingDisabled() throws Exception { } @Test - public void sessionAttribute() throws Exception { + void sessionAttribute() throws Exception { this.attributeStore.storeAttribute(this.webRequest, "sessionAttr", "sessionAttrValue"); ModelFactory modelFactory = createModelFactory("modelAttr", Model.class); @@ -147,7 +147,7 @@ public void sessionAttribute() throws Exception { } @Test - public void sessionAttributeNotPresent() throws Exception { + void sessionAttributeNotPresent() throws Exception { ModelFactory modelFactory = new ModelFactory(null, null, this.attributeHandler); HandlerMethod handlerMethod = createHandlerMethod("handleSessionAttr", String.class); assertThatExceptionOfType(HttpSessionRequiredException.class).isThrownBy(() -> @@ -161,7 +161,7 @@ public void sessionAttributeNotPresent() throws Exception { } @Test - public void updateModelBindingResult() throws Exception { + void updateModelBindingResult() throws Exception { String commandName = "attr1"; Object command = new Object(); ModelAndViewContainer container = new ModelAndViewContainer(); @@ -181,7 +181,7 @@ public void updateModelBindingResult() throws Exception { } @Test - public void updateModelSessionAttributesSaved() throws Exception { + void updateModelSessionAttributesSaved() throws Exception { String attributeName = "sessionAttr"; String attribute = "value"; ModelAndViewContainer container = new ModelAndViewContainer(); @@ -199,7 +199,7 @@ public void updateModelSessionAttributesSaved() throws Exception { } @Test - public void updateModelSessionAttributesRemoved() throws Exception { + void updateModelSessionAttributesRemoved() throws Exception { String attributeName = "sessionAttr"; String attribute = "value"; ModelAndViewContainer container = new ModelAndViewContainer(); diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/ModelMethodProcessorTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/ModelMethodProcessorTests.java index 8b28fdd4cf9f..debacf90dd47 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/ModelMethodProcessorTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/ModelMethodProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -36,7 +36,7 @@ * * @author Rossen Stoyanchev */ -public class ModelMethodProcessorTests { +class ModelMethodProcessorTests { private ModelMethodProcessor processor; @@ -49,7 +49,7 @@ public class ModelMethodProcessorTests { private NativeWebRequest webRequest; @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { processor = new ModelMethodProcessor(); mavContainer = new ModelAndViewContainer(); @@ -61,22 +61,22 @@ public void setUp() throws Exception { } @Test - public void supportsParameter() { + void supportsParameter() { assertThat(processor.supportsParameter(paramModel)).isTrue(); } @Test - public void supportsReturnType() { + void supportsReturnType() { assertThat(processor.supportsReturnType(returnParamModel)).isTrue(); } @Test - public void resolveArgumentValue() throws Exception { + void resolveArgumentValue() throws Exception { assertThat(processor.resolveArgument(paramModel, mavContainer, webRequest, null)).isSameAs(mavContainer.getModel()); } @Test - public void handleModelReturnValue() throws Exception { + void handleModelReturnValue() throws Exception { mavContainer.addAttribute("attr1", "value1"); Model returnValue = new ExtendedModelMap(); returnValue.addAttribute("attr2", "value2"); diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolverTests.java index 87e14b6a6411..f48f0423cf04 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -42,7 +42,7 @@ * @author Arjen Poutsma * @author Rossen Stoyanchev */ -public class RequestHeaderMapMethodArgumentResolverTests { +class RequestHeaderMapMethodArgumentResolverTests { private RequestHeaderMapMethodArgumentResolver resolver; @@ -60,7 +60,7 @@ public class RequestHeaderMapMethodArgumentResolverTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { resolver = new RequestHeaderMapMethodArgumentResolver(); Method method = getClass().getMethod("params", Map.class, MultiValueMap.class, HttpHeaders.class, Map.class); @@ -75,7 +75,7 @@ public void setup() throws Exception { @Test - public void supportsParameter() { + void supportsParameter() { assertThat(resolver.supportsParameter(paramMap)).as("Map parameter not supported").isTrue(); assertThat(resolver.supportsParameter(paramMultiValueMap)).as("MultiValueMap parameter not supported").isTrue(); assertThat(resolver.supportsParameter(paramHttpHeaders)).as("HttpHeaders parameter not supported").isTrue(); @@ -83,7 +83,7 @@ public void supportsParameter() { } @Test - public void resolveMapArgument() throws Exception { + void resolveMapArgument() throws Exception { String name = "foo"; String value = "bar"; Map expected = Collections.singletonMap(name, value); @@ -97,7 +97,7 @@ public void resolveMapArgument() throws Exception { } @Test - public void resolveMultiValueMapArgument() throws Exception { + void resolveMultiValueMapArgument() throws Exception { String name = "foo"; String value1 = "bar"; String value2 = "baz"; @@ -117,7 +117,7 @@ public void resolveMultiValueMapArgument() throws Exception { } @Test - public void resolveHttpHeadersArgument() throws Exception { + void resolveHttpHeadersArgument() throws Exception { String name = "foo"; String value1 = "bar"; String value2 = "baz"; diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolverTests.java index 9626628e8809..e9bc98e35065 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolverTests.java @@ -76,7 +76,6 @@ class RequestHeaderMethodArgumentResolverTests { @BeforeEach - @SuppressWarnings("resource") void setup() throws Exception { GenericWebApplicationContext context = new GenericWebApplicationContext(); context.refresh(); @@ -197,7 +196,7 @@ void resolveDefaultValueFromRequest() throws Exception { } @Test - void notFound() throws Exception { + void notFound() { assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() -> resolver.resolveArgument(paramNamedValueStringArray, null, webRequest, null)); } @@ -256,16 +255,16 @@ void uuidConversionWithInvalidValue() { } @Test - void uuidConversionWithEmptyValue() throws Exception { + void uuidConversionWithEmptyValue() { uuidConversionWithEmptyOrBlankValue(""); } @Test - void uuidConversionWithBlankValue() throws Exception { + void uuidConversionWithBlankValue() { uuidConversionWithEmptyOrBlankValue(" "); } - private void uuidConversionWithEmptyOrBlankValue(String uuid) throws Exception { + private void uuidConversionWithEmptyOrBlankValue(String uuid) { servletRequest.addHeader("name", uuid); ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer(); diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolverTests.java index 51d1cc577833..e704b2b90658 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -46,7 +46,7 @@ * @author Rossen Stoyanchev * @author Juergen Hoeller */ -public class RequestParamMapMethodArgumentResolverTests { +class RequestParamMapMethodArgumentResolverTests { private RequestParamMapMethodArgumentResolver resolver = new RequestParamMapMethodArgumentResolver(); @@ -58,7 +58,7 @@ public class RequestParamMapMethodArgumentResolverTests { @Test - public void supportsParameter() { + void supportsParameter() { MethodParameter param = this.testMethod.annot(requestParam().noName()).arg(Map.class, String.class, String.class); assertThat(resolver.supportsParameter(param)).isTrue(); @@ -73,7 +73,7 @@ public void supportsParameter() { } @Test - public void resolveMapOfString() throws Exception { + void resolveMapOfString() throws Exception { String name = "foo"; String value = "bar"; request.addParameter(name, value); @@ -88,7 +88,7 @@ public void resolveMapOfString() throws Exception { } @Test - public void resolveMultiValueMapOfString() throws Exception { + void resolveMultiValueMapOfString() throws Exception { String name = "foo"; String value1 = "bar"; String value2 = "baz"; diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolverTests.java index 96b252e6beb0..81aaf4151cbe 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -61,7 +61,7 @@ * @author Rossen Stoyanchev * @author Brian Clozel */ -public class RequestParamMethodArgumentResolverTests { +class RequestParamMethodArgumentResolverTests { private RequestParamMethodArgumentResolver resolver = new RequestParamMethodArgumentResolver(null, true); @@ -73,7 +73,7 @@ public class RequestParamMethodArgumentResolverTests { @Test - public void supportsParameter() { + void supportsParameter() { resolver = new RequestParamMethodArgumentResolver(null, true); MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class); @@ -143,7 +143,7 @@ public void supportsParameter() { } @Test - public void resolveString() throws Exception { + void resolveString() throws Exception { String expected = "foo"; request.addParameter("name", expected); @@ -155,7 +155,7 @@ public void resolveString() throws Exception { } @Test - public void resolveStringArray() throws Exception { + void resolveStringArray() throws Exception { String[] expected = new String[] {"foo", "bar"}; request.addParameter("name", expected); @@ -167,7 +167,7 @@ public void resolveStringArray() throws Exception { } @Test - public void resolveMultipartFile() throws Exception { + void resolveMultipartFile() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected = new MockMultipartFile("mfile", "Hello World".getBytes()); request.addFile(expected); @@ -181,7 +181,7 @@ public void resolveMultipartFile() throws Exception { } @Test - public void resolveMultipartFileList() throws Exception { + void resolveMultipartFileList() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected1 = new MockMultipartFile("mfilelist", "Hello World 1".getBytes()); MultipartFile expected2 = new MockMultipartFile("mfilelist", "Hello World 2".getBytes()); @@ -199,7 +199,7 @@ public void resolveMultipartFileList() throws Exception { } @Test - public void resolveMultipartFileListMissing() throws Exception { + void resolveMultipartFileListMissing() { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); request.addFile(new MockMultipartFile("other", "Hello World 3".getBytes())); webRequest = new ServletWebRequest(request); @@ -210,7 +210,7 @@ public void resolveMultipartFileListMissing() throws Exception { } @Test - public void resolveMultipartFileArray() throws Exception { + void resolveMultipartFileArray() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected1 = new MockMultipartFile("mfilearray", "Hello World 1".getBytes()); MultipartFile expected2 = new MockMultipartFile("mfilearray", "Hello World 2".getBytes()); @@ -231,7 +231,7 @@ public void resolveMultipartFileArray() throws Exception { } @Test - public void resolveMultipartFileArrayMissing() throws Exception { + void resolveMultipartFileArrayMissing() { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); request.addFile(new MockMultipartFile("other", "Hello World 3".getBytes())); webRequest = new ServletWebRequest(request); @@ -242,7 +242,7 @@ public void resolveMultipartFileArrayMissing() throws Exception { } @Test - public void resolvePart() throws Exception { + void resolvePart() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); MockPart expected = new MockPart("pfile", "Hello World".getBytes()); request.setMethod("POST"); @@ -259,7 +259,7 @@ public void resolvePart() throws Exception { } @Test - public void resolvePartList() throws Exception { + void resolvePartList() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); request.setContentType("multipart/form-data"); @@ -279,7 +279,7 @@ public void resolvePartList() throws Exception { } @Test - public void resolvePartListMissing() throws Exception { + void resolvePartListMissing() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); request.setContentType("multipart/form-data"); @@ -292,7 +292,7 @@ public void resolvePartListMissing() throws Exception { } @Test - public void resolvePartArray() throws Exception { + void resolvePartArray() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); MockPart expected1 = new MockPart("pfilearray", "Hello World 1".getBytes()); MockPart expected2 = new MockPart("pfilearray", "Hello World 2".getBytes()); @@ -315,7 +315,7 @@ public void resolvePartArray() throws Exception { } @Test - public void resolvePartArrayMissing() throws Exception { + void resolvePartArrayMissing() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); request.setContentType("multipart/form-data"); @@ -328,7 +328,7 @@ public void resolvePartArrayMissing() throws Exception { } @Test - public void resolveMultipartFileNotAnnot() throws Exception { + void resolveMultipartFileNotAnnot() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected = new MockMultipartFile("multipartFileNotAnnot", "Hello World".getBytes()); request.addFile(expected); @@ -342,7 +342,7 @@ public void resolveMultipartFileNotAnnot() throws Exception { } @Test - public void resolveMultipartFileListNotannot() throws Exception { + void resolveMultipartFileListNotannot() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected1 = new MockMultipartFile("multipartFileList", "Hello World 1".getBytes()); MultipartFile expected2 = new MockMultipartFile("multipartFileList", "Hello World 2".getBytes()); @@ -360,7 +360,7 @@ public void resolveMultipartFileListNotannot() throws Exception { } @Test - public void isMultipartRequest() throws Exception { + void isMultipartRequest() { MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile.class); assertThatExceptionOfType(MultipartException.class).isThrownBy(() -> resolver.resolveArgument(param, null, webRequest, null)); @@ -384,7 +384,7 @@ public void isMultipartRequestHttpPut() throws Exception { } @Test - public void noMultipartContent() throws Exception { + void noMultipartContent() { request.setMethod("POST"); MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile.class); assertThatExceptionOfType(MultipartException.class).isThrownBy(() -> @@ -392,7 +392,7 @@ public void noMultipartContent() throws Exception { } @Test - public void missingMultipartFile() throws Exception { + void missingMultipartFile() { request.setMethod("POST"); request.setContentType("multipart/form-data"); MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile.class); @@ -401,7 +401,7 @@ public void missingMultipartFile() throws Exception { } @Test - public void resolvePartNotAnnot() throws Exception { + void resolvePartNotAnnot() throws Exception { MockPart expected = new MockPart("part", "Hello World".getBytes()); MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); @@ -417,7 +417,7 @@ public void resolvePartNotAnnot() throws Exception { } @Test - public void resolveDefaultValue() throws Exception { + void resolveDefaultValue() throws Exception { MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class); Object result = resolver.resolveArgument(param, null, webRequest, null); boolean condition = result instanceof String; @@ -426,7 +426,7 @@ public void resolveDefaultValue() throws Exception { } @Test - public void missingRequestParam() throws Exception { + void missingRequestParam() { MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class); assertThatExceptionOfType(MissingServletRequestParameterException.class).isThrownBy(() -> resolver.resolveArgument(param, null, webRequest, null)); @@ -462,7 +462,7 @@ public void missingRequestParamAfterConversionWithDefaultValue() throws Exceptio } @Test - public void missingRequestParamEmptyValueNotRequired() throws Exception { + void missingRequestParamEmptyValueNotRequired() throws Exception { WebDataBinder binder = new WebRequestDataBinder(null); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); @@ -492,7 +492,7 @@ public void missingRequestParamEmptyValueNotRequiredWithDefaultValue() throws Ex } @Test - public void resolveSimpleTypeParam() throws Exception { + void resolveSimpleTypeParam() throws Exception { request.setParameter("stringNotAnnot", "plainValue"); MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class); Object result = resolver.resolveArgument(param, null, webRequest, null); @@ -518,7 +518,7 @@ public void resolveEmptyValueToDefault() throws Exception { } @Test - public void resolveEmptyValueWithoutDefault() throws Exception { + void resolveEmptyValueWithoutDefault() throws Exception { request.addParameter("stringNotAnnot", ""); MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class); Object result = resolver.resolveArgument(param, null, webRequest, null); @@ -526,7 +526,7 @@ public void resolveEmptyValueWithoutDefault() throws Exception { } @Test - public void resolveEmptyValueRequiredWithoutDefault() throws Exception { + void resolveEmptyValueRequiredWithoutDefault() throws Exception { request.addParameter("name", ""); MethodParameter param = this.testMethod.annot(requestParam().notRequired()).arg(String.class); Object result = resolver.resolveArgument(param, null, webRequest, null); @@ -633,7 +633,7 @@ public void missingOptionalParamList() throws Exception { } @Test - public void resolveOptionalMultipartFile() throws Exception { + void resolveOptionalMultipartFile() throws Exception { ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); initializer.setConversionService(new DefaultConversionService()); WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer); @@ -652,7 +652,7 @@ public void resolveOptionalMultipartFile() throws Exception { } @Test - public void missingOptionalMultipartFile() throws Exception { + void missingOptionalMultipartFile() throws Exception { ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); initializer.setConversionService(new DefaultConversionService()); WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer); @@ -667,7 +667,7 @@ public void missingOptionalMultipartFile() throws Exception { } @Test - public void optionalMultipartFileWithoutMultipartRequest() throws Exception { + void optionalMultipartFileWithoutMultipartRequest() throws Exception { ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); initializer.setConversionService(new DefaultConversionService()); WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer); diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/SessionAttributesHandlerTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/SessionAttributesHandlerTests.java index 9c856d2d5337..98c1c33415b1 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/SessionAttributesHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/SessionAttributesHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -37,7 +37,7 @@ * Test fixture with {@link SessionAttributesHandler}. * @author Rossen Stoyanchev */ -public class SessionAttributesHandlerTests { +class SessionAttributesHandlerTests { private final SessionAttributeStore sessionAttributeStore = new DefaultSessionAttributeStore(); @@ -48,7 +48,7 @@ public class SessionAttributesHandlerTests { @Test - public void isSessionAttribute() throws Exception { + void isSessionAttribute() { assertThat(sessionAttributesHandler.isHandlerSessionAttribute("attr1", String.class)).isTrue(); assertThat(sessionAttributesHandler.isHandlerSessionAttribute("attr2", String.class)).isTrue(); assertThat(sessionAttributesHandler.isHandlerSessionAttribute("simple", TestBean.class)).isTrue(); @@ -56,7 +56,7 @@ public void isSessionAttribute() throws Exception { } @Test - public void retrieveAttributes() throws Exception { + void retrieveAttributes() { sessionAttributeStore.storeAttribute(request, "attr1", "value1"); sessionAttributeStore.storeAttribute(request, "attr2", "value2"); sessionAttributeStore.storeAttribute(request, "attr3", new TestBean()); @@ -71,7 +71,7 @@ public void retrieveAttributes() throws Exception { } @Test - public void cleanupAttributes() throws Exception { + void cleanupAttributes() { sessionAttributeStore.storeAttribute(request, "attr1", "value1"); sessionAttributeStore.storeAttribute(request, "attr2", "value2"); sessionAttributeStore.storeAttribute(request, "attr3", new TestBean()); @@ -90,7 +90,7 @@ public void cleanupAttributes() throws Exception { } @Test - public void storeAttributes() throws Exception { + void storeAttributes() { ModelMap model = new ModelMap(); model.put("attr1", "value1"); model.put("attr2", "value2"); diff --git a/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodArgumentResolverCompositeTests.java b/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodArgumentResolverCompositeTests.java index c4d8e7bf7be6..abd39c4e50db 100644 --- a/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodArgumentResolverCompositeTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodArgumentResolverCompositeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -31,7 +31,7 @@ * * @author Rossen Stoyanchev */ -public class HandlerMethodArgumentResolverCompositeTests { +class HandlerMethodArgumentResolverCompositeTests { private HandlerMethodArgumentResolverComposite resolverComposite; @@ -41,7 +41,7 @@ public class HandlerMethodArgumentResolverCompositeTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { this.resolverComposite = new HandlerMethodArgumentResolverComposite(); Method method = getClass().getDeclaredMethod("handle", Integer.class, String.class); @@ -51,7 +51,7 @@ public void setup() throws Exception { @Test - public void supportsParameter() throws Exception { + void supportsParameter() { this.resolverComposite.addResolver(new StubArgumentResolver(Integer.class)); assertThat(this.resolverComposite.supportsParameter(paramInt)).isTrue(); @@ -59,7 +59,7 @@ public void supportsParameter() throws Exception { } @Test - public void resolveArgument() throws Exception { + void resolveArgument() throws Exception { this.resolverComposite.addResolver(new StubArgumentResolver(55)); Object resolvedValue = this.resolverComposite.resolveArgument(paramInt, null, null, null); @@ -67,7 +67,7 @@ public void resolveArgument() throws Exception { } @Test - public void checkArgumentResolverOrder() throws Exception { + void checkArgumentResolverOrder() throws Exception { this.resolverComposite.addResolver(new StubArgumentResolver(1)); this.resolverComposite.addResolver(new StubArgumentResolver(2)); Object resolvedValue = this.resolverComposite.resolveArgument(paramInt, null, null, null); @@ -76,7 +76,7 @@ public void checkArgumentResolverOrder() throws Exception { } @Test - public void noSuitableArgumentResolver() throws Exception { + void noSuitableArgumentResolver() { assertThatIllegalArgumentException().isThrownBy(() -> this.resolverComposite.resolveArgument(paramStr, null, null, null)); } diff --git a/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerCompositeTests.java b/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerCompositeTests.java index 6a5857fb097f..f0a0e5bb6f8e 100644 --- a/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerCompositeTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerCompositeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -59,7 +59,7 @@ void setup() throws Exception { @Test - void supportsReturnType() throws Exception { + void supportsReturnType() { assertThat(this.handlers.supportsReturnType(this.integerType)).isTrue(); assertThat(this.handlers.supportsReturnType(this.stringType)).isFalse(); } diff --git a/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodValidationExceptionTests.java b/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodValidationExceptionTests.java index 1f13e8bbe431..c7aceb0c0b88 100644 --- a/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodValidationExceptionTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodValidationExceptionTests.java @@ -59,7 +59,7 @@ * * @author Rossen Stoyanchev */ -public class HandlerMethodValidationExceptionTests { +class HandlerMethodValidationExceptionTests { private static final Person person = new Person("Faustino1234"); diff --git a/spring-web/src/test/java/org/springframework/web/method/support/InvocableHandlerMethodTests.java b/spring-web/src/test/java/org/springframework/web/method/support/InvocableHandlerMethodTests.java index 9b1a8bee1f5b..49d81f5cfb73 100644 --- a/spring-web/src/test/java/org/springframework/web/method/support/InvocableHandlerMethodTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/support/InvocableHandlerMethodTests.java @@ -41,7 +41,7 @@ * * @author Rossen Stoyanchev */ -public class InvocableHandlerMethodTests { +class InvocableHandlerMethodTests { private NativeWebRequest request; @@ -49,13 +49,13 @@ public class InvocableHandlerMethodTests { @BeforeEach - public void setUp() throws Exception { + void setUp() { this.request = new ServletWebRequest(new MockHttpServletRequest(), new MockHttpServletResponse()); } @Test - public void resolveArg() throws Exception { + void resolveArg() throws Exception { this.composite.addResolver(new StubArgumentResolver(99)); this.composite.addResolver(new StubArgumentResolver("value")); @@ -69,7 +69,7 @@ public void resolveArg() throws Exception { } @Test - public void resolveNoArgValue() throws Exception { + void resolveNoArgValue() throws Exception { this.composite.addResolver(new StubArgumentResolver(Integer.class)); this.composite.addResolver(new StubArgumentResolver(String.class)); @@ -81,14 +81,14 @@ public void resolveNoArgValue() throws Exception { } @Test - public void cannotResolveArg() throws Exception { + void cannotResolveArg() { assertThatIllegalStateException().isThrownBy(() -> getInvocable(Integer.class, String.class).invokeForRequest(request, null)) .withMessageContaining("Could not resolve parameter [0]"); } @Test - public void resolveProvidedArg() throws Exception { + void resolveProvidedArg() throws Exception { Object value = getInvocable(Integer.class, String.class).invokeForRequest(request, null, 99, "value"); assertThat(value).isNotNull(); @@ -97,7 +97,7 @@ public void resolveProvidedArg() throws Exception { } @Test - public void resolveProvidedArgFirst() throws Exception { + void resolveProvidedArgFirst() throws Exception { this.composite.addResolver(new StubArgumentResolver(1)); this.composite.addResolver(new StubArgumentResolver("value1")); Object value = getInvocable(Integer.class, String.class).invokeForRequest(request, null, 2, "value2"); @@ -106,14 +106,14 @@ public void resolveProvidedArgFirst() throws Exception { } @Test - public void exceptionInResolvingArg() throws Exception { + void exceptionInResolvingArg() { this.composite.addResolver(new ExceptionRaisingArgumentResolver()); assertThatIllegalArgumentException().isThrownBy(() -> getInvocable(Integer.class, String.class).invokeForRequest(request, null)); } @Test - public void illegalArgumentException() throws Exception { + void illegalArgumentException() { this.composite.addResolver(new StubArgumentResolver(Integer.class, "__not_an_int__")); this.composite.addResolver(new StubArgumentResolver("value")); assertThatIllegalStateException().isThrownBy(() -> @@ -127,7 +127,7 @@ public void illegalArgumentException() throws Exception { } @Test - public void invocationTargetException() throws Exception { + void invocationTargetException() { RuntimeException runtimeException = new RuntimeException("error"); assertThatRuntimeException() .isThrownBy(() -> getInvocable(Throwable.class).invokeForRequest(this.request, null, runtimeException)) @@ -151,7 +151,7 @@ public void invocationTargetException() throws Exception { } @Test // SPR-13917 - public void invocationErrorMessage() throws Exception { + public void invocationErrorMessage() { this.composite.addResolver(new StubArgumentResolver(double.class)); assertThatIllegalStateException() .isThrownBy(() -> getInvocable(double.class).invokeForRequest(this.request, null)) diff --git a/spring-web/src/test/java/org/springframework/web/method/support/ModelAndViewContainerTests.java b/spring-web/src/test/java/org/springframework/web/method/support/ModelAndViewContainerTests.java index e7a9db064a9f..8ff840e81113 100644 --- a/spring-web/src/test/java/org/springframework/web/method/support/ModelAndViewContainerTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/support/ModelAndViewContainerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -29,26 +29,26 @@ * @author Rossen Stoyanchev * @since 3.1 */ -public class ModelAndViewContainerTests { +class ModelAndViewContainerTests { private ModelAndViewContainer mavContainer; @BeforeEach - public void setup() { + void setup() { this.mavContainer = new ModelAndViewContainer(); } @Test - public void getModel() { + void getModel() { this.mavContainer.addAttribute("name", "value"); assertThat(this.mavContainer.getModel()).hasSize(1); assertThat(this.mavContainer.getModel().get("name")).isEqualTo("value"); } @Test - public void redirectScenarioWithRedirectModel() { + void redirectScenarioWithRedirectModel() { this.mavContainer.addAttribute("name1", "value1"); this.mavContainer.setRedirectModel(new ModelMap("name2", "value2")); this.mavContainer.setRedirectModelScenario(true); @@ -69,7 +69,7 @@ public void redirectScenarioWithoutRedirectModel() { } @Test - public void ignoreDefaultModel() { + void ignoreDefaultModel() { this.mavContainer.addAttribute("name", "value"); this.mavContainer.setRedirectModelScenario(true); diff --git a/spring-web/src/test/java/org/springframework/web/multipart/support/ByteArrayMultipartFileEditorTests.java b/spring-web/src/test/java/org/springframework/web/multipart/support/ByteArrayMultipartFileEditorTests.java index 488a89fcb491..dcd61ea18202 100644 --- a/spring-web/src/test/java/org/springframework/web/multipart/support/ByteArrayMultipartFileEditorTests.java +++ b/spring-web/src/test/java/org/springframework/web/multipart/support/ByteArrayMultipartFileEditorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -31,26 +31,26 @@ * @author Rick Evans * @author Sam Brannen */ -public class ByteArrayMultipartFileEditorTests { +class ByteArrayMultipartFileEditorTests { private final ByteArrayMultipartFileEditor editor = new ByteArrayMultipartFileEditor(); @Test - public void setValueAsByteArray() throws Exception { + void setValueAsByteArray() { String expectedValue = "Shumwere, shumhow, a shuck ish washing you. - Drunken Far Side"; editor.setValue(expectedValue.getBytes()); assertThat(editor.getAsText()).isEqualTo(expectedValue); } @Test - public void setValueAsString() throws Exception { + void setValueAsString() { String expectedValue = "'Green Wing' - classic British comedy"; editor.setValue(expectedValue); assertThat(editor.getAsText()).isEqualTo(expectedValue); } @Test - public void setValueAsCustomObjectInvokesToString() throws Exception { + void setValueAsCustomObjectInvokesToString() { final String expectedValue = "'Green Wing' - classic British comedy"; Object object = new Object() { @Override @@ -64,13 +64,13 @@ public String toString() { } @Test - public void setValueAsNullGetsBackEmptyString() throws Exception { + void setValueAsNullGetsBackEmptyString() { editor.setValue(null); assertThat(editor.getAsText()).isEmpty(); } @Test - public void setValueAsMultipartFile() throws Exception { + void setValueAsMultipartFile() throws Exception { String expectedValue = "That is comforting to know"; MultipartFile file = mock(); given(file.getBytes()).willReturn(expectedValue.getBytes()); @@ -79,7 +79,7 @@ public void setValueAsMultipartFile() throws Exception { } @Test - public void setValueAsMultipartFileWithBadBytes() throws Exception { + void setValueAsMultipartFileWithBadBytes() throws Exception { MultipartFile file = mock(); given(file.getBytes()).willThrow(new IOException()); assertThatIllegalArgumentException().isThrownBy(() -> diff --git a/spring-web/src/test/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequestTests.java b/spring-web/src/test/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequestTests.java index 7e5fd702b65f..06447e8b2d03 100644 --- a/spring-web/src/test/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequestTests.java +++ b/spring-web/src/test/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequestTests.java @@ -33,7 +33,7 @@ * * @author Rossen Stoyanchev */ -public class DefaultMultipartHttpServletRequestTests { +class DefaultMultipartHttpServletRequestTests { private final MockHttpServletRequest servletRequest = new MockHttpServletRequest(); diff --git a/spring-web/src/test/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequestTests.java b/spring-web/src/test/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequestTests.java index 2298ec981c42..6d2e8d215c41 100644 --- a/spring-web/src/test/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequestTests.java +++ b/spring-web/src/test/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequestTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -39,14 +39,14 @@ * @author Rossen Stoyanchev * @author Juergen Hoeller */ -public class RequestPartServletServerHttpRequestTests { +class RequestPartServletServerHttpRequestTests { private final MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest(); @Test - public void getMethod() throws Exception { - this.mockRequest.addFile(new MockMultipartFile("part", "", "", "content".getBytes("UTF-8"))); + void getMethod() throws Exception { + this.mockRequest.addFile(new MockMultipartFile("part", "", "", "content".getBytes(StandardCharsets.UTF_8))); ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part"); this.mockRequest.setMethod("POST"); @@ -54,8 +54,8 @@ public void getMethod() throws Exception { } @Test - public void getURI() throws Exception { - this.mockRequest.addFile(new MockMultipartFile("part", "", "application/json", "content".getBytes("UTF-8"))); + void getURI() throws Exception { + this.mockRequest.addFile(new MockMultipartFile("part", "", "application/json", "content".getBytes(StandardCharsets.UTF_8))); ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part"); URI uri = URI.create("https://example.com/path?query"); @@ -68,8 +68,8 @@ public void getURI() throws Exception { } @Test - public void getContentType() throws Exception { - MultipartFile part = new MockMultipartFile("part", "", "application/json", "content".getBytes("UTF-8")); + void getContentType() throws Exception { + MultipartFile part = new MockMultipartFile("part", "", "application/json", "content".getBytes(StandardCharsets.UTF_8)); this.mockRequest.addFile(part); ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part"); @@ -79,8 +79,8 @@ public void getContentType() throws Exception { } @Test - public void getBody() throws Exception { - byte[] bytes = "content".getBytes("UTF-8"); + void getBody() throws Exception { + byte[] bytes = "content".getBytes(StandardCharsets.UTF_8); MultipartFile part = new MockMultipartFile("part", "", "application/json", bytes); this.mockRequest.addFile(part); ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part"); @@ -91,7 +91,7 @@ public void getBody() throws Exception { @Test // SPR-13317 public void getBodyWithWrappedRequest() throws Exception { - byte[] bytes = "content".getBytes("UTF-8"); + byte[] bytes = "content".getBytes(StandardCharsets.UTF_8); MultipartFile part = new MockMultipartFile("part", "", "application/json", bytes); this.mockRequest.addFile(part); HttpServletRequest wrapped = new HttpServletRequestWrapper(this.mockRequest); @@ -120,7 +120,7 @@ public HttpHeaders getMultipartHeaders(String paramOrFileName) { } @Test - public void getBodyViaRequestParameterWithRequestEncoding() throws Exception { + void getBodyViaRequestParameterWithRequestEncoding() throws Exception { MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() { @Override public HttpHeaders getMultipartHeaders(String paramOrFileName) { @@ -140,7 +140,7 @@ public HttpHeaders getMultipartHeaders(String paramOrFileName) { @Test // gh-25829 public void getBodyViaRequestPart() throws Exception { - byte[] bytes = "content".getBytes("UTF-8"); + byte[] bytes = "content".getBytes(StandardCharsets.UTF_8); MockPart mockPart = new MockPart("part", bytes); mockPart.getHeaders().setContentType(MediaType.APPLICATION_JSON); this.mockRequest.addPart(mockPart); diff --git a/spring-web/src/test/java/org/springframework/web/multipart/support/StandardServletMultipartResolverTests.java b/spring-web/src/test/java/org/springframework/web/multipart/support/StandardServletMultipartResolverTests.java index 4cd5ae0d9fb5..44884776f091 100644 --- a/spring-web/src/test/java/org/springframework/web/multipart/support/StandardServletMultipartResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/multipart/support/StandardServletMultipartResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 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. @@ -26,10 +26,10 @@ /** * @author Juergen Hoeller */ -public class StandardServletMultipartResolverTests { +class StandardServletMultipartResolverTests { @Test - public void isMultipartWithDefaultSetting() { + void isMultipartWithDefaultSetting() { StandardServletMultipartResolver resolver = new StandardServletMultipartResolver(); MockHttpServletRequest request = new MockHttpServletRequest("POST", "/"); @@ -58,7 +58,7 @@ public void isMultipartWithDefaultSetting() { } @Test - public void isMultipartWithStrictSetting() { + void isMultipartWithStrictSetting() { StandardServletMultipartResolver resolver = new StandardServletMultipartResolver(); resolver.setStrictServletCompliance(true); diff --git a/spring-web/src/test/java/org/springframework/web/server/adapter/DefaultServerWebExchangeCheckNotModifiedTests.java b/spring-web/src/test/java/org/springframework/web/server/adapter/DefaultServerWebExchangeCheckNotModifiedTests.java index e65e85837e66..3d890f010b84 100644 --- a/spring-web/src/test/java/org/springframework/web/server/adapter/DefaultServerWebExchangeCheckNotModifiedTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/adapter/DefaultServerWebExchangeCheckNotModifiedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -85,7 +85,7 @@ void checkNotModifiedHeaderAlreadySet() { } @Test - void checkNotModifiedTimestamp() throws Exception { + void checkNotModifiedTimestamp() { MockServerHttpRequest request = get("/").ifModifiedSince(currentDate.toEpochMilli()).build(); MockServerWebExchange exchange = MockServerWebExchange.from(request); diff --git a/spring-web/src/test/java/org/springframework/web/server/adapter/DefaultServerWebExchangeTests.java b/spring-web/src/test/java/org/springframework/web/server/adapter/DefaultServerWebExchangeTests.java index 011d32caf6c1..2c5f4d332b71 100644 --- a/spring-web/src/test/java/org/springframework/web/server/adapter/DefaultServerWebExchangeTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/adapter/DefaultServerWebExchangeTests.java @@ -33,23 +33,23 @@ * @author Arjen Poutsma * @author Rossen Stoyanchev */ -public class DefaultServerWebExchangeTests { +class DefaultServerWebExchangeTests { @Test - public void transformUrlDefault() { + void transformUrlDefault() { ServerWebExchange exchange = createExchange(); assertThat(exchange.transformUrl("/foo")).isEqualTo("/foo"); } @Test - public void transformUrlWithEncoder() { + void transformUrlWithEncoder() { ServerWebExchange exchange = createExchange(); exchange.addUrlTransformer(s -> s + "?nonce=123"); assertThat(exchange.transformUrl("/foo")).isEqualTo("/foo?nonce=123"); } @Test - public void transformUrlWithMultipleEncoders() { + void transformUrlWithMultipleEncoders() { ServerWebExchange exchange = createExchange(); exchange.addUrlTransformer(s -> s + ";p=abc"); exchange.addUrlTransformer(s -> s + "?q=123"); diff --git a/spring-web/src/test/java/org/springframework/web/server/adapter/WebHttpHandlerBuilderTests.java b/spring-web/src/test/java/org/springframework/web/server/adapter/WebHttpHandlerBuilderTests.java index fbfc57c98e27..4d9283b7294b 100644 --- a/spring-web/src/test/java/org/springframework/web/server/adapter/WebHttpHandlerBuilderTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/adapter/WebHttpHandlerBuilderTests.java @@ -58,7 +58,7 @@ * @author Rossen Stoyanchev * @author Brian Clozel */ -public class WebHttpHandlerBuilderTests { +class WebHttpHandlerBuilderTests { @Test // SPR-15074 void orderedWebFilterBeans() { diff --git a/spring-web/src/test/java/org/springframework/web/server/handler/ExceptionHandlingWebHandlerTests.java b/spring-web/src/test/java/org/springframework/web/server/handler/ExceptionHandlingWebHandlerTests.java index 1212acfb0ea1..6f2e7ddf2d25 100644 --- a/spring-web/src/test/java/org/springframework/web/server/handler/ExceptionHandlingWebHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/handler/ExceptionHandlingWebHandlerTests.java @@ -37,7 +37,7 @@ * * @author Rossen Stoyanchev */ -public class ExceptionHandlingWebHandlerTests { +class ExceptionHandlingWebHandlerTests { private final WebHandler targetHandler = new StubWebHandler(new IllegalStateException("boo")); diff --git a/spring-web/src/test/java/org/springframework/web/server/handler/FilteringWebHandlerTests.java b/spring-web/src/test/java/org/springframework/web/server/handler/FilteringWebHandlerTests.java index cea7ed27282a..53c1d15c8924 100644 --- a/spring-web/src/test/java/org/springframework/web/server/handler/FilteringWebHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/handler/FilteringWebHandlerTests.java @@ -43,13 +43,13 @@ * * @author Rossen Stoyanchev */ -public class FilteringWebHandlerTests { +class FilteringWebHandlerTests { - private static Log logger = LogFactory.getLog(FilteringWebHandlerTests.class); + private static final Log logger = LogFactory.getLog(FilteringWebHandlerTests.class); @Test - public void multipleFilters() throws Exception { + void multipleFilters() { TestFilter filter1 = new TestFilter(); TestFilter filter2 = new TestFilter(); @@ -67,7 +67,7 @@ public void multipleFilters() throws Exception { } @Test - public void zeroFilters() throws Exception { + void zeroFilters() { StubWebHandler targetHandler = new StubWebHandler(); @@ -79,7 +79,7 @@ public void zeroFilters() throws Exception { } @Test - public void shortcircuitFilter() throws Exception { + void shortcircuitFilter() { TestFilter filter1 = new TestFilter(); ShortcircuitingFilter filter2 = new ShortcircuitingFilter(); @@ -97,7 +97,7 @@ public void shortcircuitFilter() throws Exception { } @Test - public void asyncFilter() throws Exception { + void asyncFilter() { AsyncFilter filter = new AsyncFilter(); StubWebHandler targetHandler = new StubWebHandler(); @@ -111,7 +111,7 @@ public void asyncFilter() throws Exception { } @Test - public void handleErrorFromFilter() throws Exception { + void handleErrorFromFilter() { MockServerHttpRequest request = MockServerHttpRequest.get("/").build(); MockServerHttpResponse response = new MockServerHttpResponse(); diff --git a/spring-web/src/test/java/org/springframework/web/server/handler/ResponseStatusExceptionHandlerTests.java b/spring-web/src/test/java/org/springframework/web/server/handler/ResponseStatusExceptionHandlerTests.java index 0fbcd8b2993b..1d0a39e17cb0 100644 --- a/spring-web/src/test/java/org/springframework/web/server/handler/ResponseStatusExceptionHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/handler/ResponseStatusExceptionHandlerTests.java @@ -24,7 +24,7 @@ * @author Rossen Stoyanchev * @author Juergen Hoeller */ -public class ResponseStatusExceptionHandlerTests extends AbstractResponseStatusExceptionHandlerTests { +class ResponseStatusExceptionHandlerTests extends AbstractResponseStatusExceptionHandlerTests { // all tests in superclass diff --git a/spring-web/src/test/java/org/springframework/web/server/i18n/AcceptHeaderLocaleContextResolverTests.java b/spring-web/src/test/java/org/springframework/web/server/i18n/AcceptHeaderLocaleContextResolverTests.java index 8c357c72ca7e..fe855f7f785c 100644 --- a/spring-web/src/test/java/org/springframework/web/server/i18n/AcceptHeaderLocaleContextResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/i18n/AcceptHeaderLocaleContextResolverTests.java @@ -44,63 +44,63 @@ * @author Sebastien Deleuze * @author Juergen Hoeller */ -public class AcceptHeaderLocaleContextResolverTests { +class AcceptHeaderLocaleContextResolverTests { private final AcceptHeaderLocaleContextResolver resolver = new AcceptHeaderLocaleContextResolver(); @Test - public void resolve() { + void resolve() { assertThat(this.resolver.resolveLocaleContext(exchange(CANADA)).getLocale()).isEqualTo(CANADA); assertThat(this.resolver.resolveLocaleContext(exchange(US, CANADA)).getLocale()).isEqualTo(US); } @Test - public void resolvePreferredSupported() { + void resolvePreferredSupported() { this.resolver.setSupportedLocales(Collections.singletonList(CANADA)); assertThat(this.resolver.resolveLocaleContext(exchange(US, CANADA)).getLocale()).isEqualTo(CANADA); } @Test - public void resolvePreferredNotSupported() { + void resolvePreferredNotSupported() { this.resolver.setSupportedLocales(Collections.singletonList(CANADA)); assertThat(this.resolver.resolveLocaleContext(exchange(US, UK)).getLocale()).isEqualTo(US); } @Test - public void resolvePreferredNotSupportedWithDefault() { + void resolvePreferredNotSupportedWithDefault() { this.resolver.setSupportedLocales(Arrays.asList(US, JAPAN)); this.resolver.setDefaultLocale(JAPAN); assertThat(this.resolver.resolveLocaleContext(exchange(KOREA)).getLocale()).isEqualTo(JAPAN); } @Test - public void resolvePreferredAgainstLanguageOnly() { + void resolvePreferredAgainstLanguageOnly() { this.resolver.setSupportedLocales(Collections.singletonList(ENGLISH)); assertThat(this.resolver.resolveLocaleContext(exchange(GERMANY, US, UK)).getLocale()).isEqualTo(ENGLISH); } @Test - public void resolvePreferredAgainstCountryIfPossible() { + void resolvePreferredAgainstCountryIfPossible() { this.resolver.setSupportedLocales(Arrays.asList(ENGLISH, UK)); assertThat(this.resolver.resolveLocaleContext(exchange(GERMANY, US, UK)).getLocale()).isEqualTo(UK); } @Test - public void resolvePreferredAgainstLanguageWithMultipleSupportedLocales() { + void resolvePreferredAgainstLanguageWithMultipleSupportedLocales() { this.resolver.setSupportedLocales(Arrays.asList(GERMAN, US)); assertThat(this.resolver.resolveLocaleContext(exchange(GERMANY, US, UK)).getLocale()).isEqualTo(GERMAN); } @Test - public void resolveMissingAcceptLanguageHeader() { + void resolveMissingAcceptLanguageHeader() { MockServerHttpRequest request = MockServerHttpRequest.get("/").build(); MockServerWebExchange exchange = MockServerWebExchange.from(request); assertThat(this.resolver.resolveLocaleContext(exchange).getLocale()).isNull(); } @Test - public void resolveMissingAcceptLanguageHeaderWithDefault() { + void resolveMissingAcceptLanguageHeaderWithDefault() { this.resolver.setDefaultLocale(US); MockServerHttpRequest request = MockServerHttpRequest.get("/").build(); @@ -109,14 +109,14 @@ public void resolveMissingAcceptLanguageHeaderWithDefault() { } @Test - public void resolveEmptyAcceptLanguageHeader() { + void resolveEmptyAcceptLanguageHeader() { MockServerHttpRequest request = MockServerHttpRequest.get("/").header(HttpHeaders.ACCEPT_LANGUAGE, "").build(); MockServerWebExchange exchange = MockServerWebExchange.from(request); assertThat(this.resolver.resolveLocaleContext(exchange).getLocale()).isNull(); } @Test - public void resolveEmptyAcceptLanguageHeaderWithDefault() { + void resolveEmptyAcceptLanguageHeaderWithDefault() { this.resolver.setDefaultLocale(US); MockServerHttpRequest request = MockServerHttpRequest.get("/").header(HttpHeaders.ACCEPT_LANGUAGE, "").build(); @@ -125,14 +125,14 @@ public void resolveEmptyAcceptLanguageHeaderWithDefault() { } @Test - public void resolveInvalidAcceptLanguageHeader() { + void resolveInvalidAcceptLanguageHeader() { MockServerHttpRequest request = MockServerHttpRequest.get("/").header(HttpHeaders.ACCEPT_LANGUAGE, "en_US").build(); MockServerWebExchange exchange = MockServerWebExchange.from(request); assertThat(this.resolver.resolveLocaleContext(exchange).getLocale()).isNull(); } @Test - public void resolveInvalidAcceptLanguageHeaderWithDefault() { + void resolveInvalidAcceptLanguageHeaderWithDefault() { this.resolver.setDefaultLocale(US); MockServerHttpRequest request = MockServerHttpRequest.get("/").header(HttpHeaders.ACCEPT_LANGUAGE, "en_US").build(); @@ -141,7 +141,7 @@ public void resolveInvalidAcceptLanguageHeaderWithDefault() { } @Test - public void defaultLocale() { + void defaultLocale() { this.resolver.setDefaultLocale(JAPANESE); MockServerHttpRequest request = MockServerHttpRequest.get("/").build(); MockServerWebExchange exchange = MockServerWebExchange.from(request); diff --git a/spring-web/src/test/java/org/springframework/web/server/i18n/FixedLocaleContextResolverTests.java b/spring-web/src/test/java/org/springframework/web/server/i18n/FixedLocaleContextResolverTests.java index 28f425767b36..8f1721bc3ee9 100644 --- a/spring-web/src/test/java/org/springframework/web/server/i18n/FixedLocaleContextResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/i18n/FixedLocaleContextResolverTests.java @@ -38,29 +38,29 @@ * * @author Sebastien Deleuze */ -public class FixedLocaleContextResolverTests { +class FixedLocaleContextResolverTests { @BeforeEach - public void setup() { + void setup() { Locale.setDefault(US); } @Test - public void resolveDefaultLocale() { + void resolveDefaultLocale() { FixedLocaleContextResolver resolver = new FixedLocaleContextResolver(); assertThat(resolver.resolveLocaleContext(exchange()).getLocale()).isEqualTo(US); assertThat(resolver.resolveLocaleContext(exchange(CANADA)).getLocale()).isEqualTo(US); } @Test - public void resolveCustomizedLocale() { + void resolveCustomizedLocale() { FixedLocaleContextResolver resolver = new FixedLocaleContextResolver(FRANCE); assertThat(resolver.resolveLocaleContext(exchange()).getLocale()).isEqualTo(FRANCE); assertThat(resolver.resolveLocaleContext(exchange(CANADA)).getLocale()).isEqualTo(FRANCE); } @Test - public void resolveCustomizedAndTimeZoneLocale() { + void resolveCustomizedAndTimeZoneLocale() { TimeZone timeZone = TimeZone.getTimeZone(ZoneId.of("UTC")); FixedLocaleContextResolver resolver = new FixedLocaleContextResolver(FRANCE, timeZone); TimeZoneAwareLocaleContext context = (TimeZoneAwareLocaleContext) resolver.resolveLocaleContext(exchange()); diff --git a/spring-web/src/test/java/org/springframework/web/server/session/CookieWebSessionIdResolverTests.java b/spring-web/src/test/java/org/springframework/web/server/session/CookieWebSessionIdResolverTests.java index 5e59e82c028c..25078ae0f6f8 100644 --- a/spring-web/src/test/java/org/springframework/web/server/session/CookieWebSessionIdResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/session/CookieWebSessionIdResolverTests.java @@ -31,7 +31,7 @@ * * @author Rossen Stoyanchev */ -public class CookieWebSessionIdResolverTests { +class CookieWebSessionIdResolverTests { private final CookieWebSessionIdResolver resolver = new CookieWebSessionIdResolver(); @@ -40,13 +40,13 @@ public class CookieWebSessionIdResolverTests { @Test - public void setSessionId() { + void setSessionId() { this.resolver.setSessionId(this.exchange, "123"); assertCookieValue("SESSION=123; Path=/; Secure; HttpOnly; SameSite=Lax"); } @Test - public void cookieInitializer() { + void cookieInitializer() { this.resolver.addCookieInitializer(builder -> builder.domain("example.org")); this.resolver.addCookieInitializer(builder -> builder.sameSite("Strict")); this.resolver.addCookieInitializer(builder -> builder.secure(false)); @@ -56,7 +56,7 @@ public void cookieInitializer() { } @Test - public void expireSessionWhenMaxAgeSetViaInitializer() { + void expireSessionWhenMaxAgeSetViaInitializer() { this.resolver.addCookieInitializer(builder -> builder.maxAge(600)); this.resolver.expireSession(this.exchange); diff --git a/spring-web/src/test/java/org/springframework/web/server/session/DefaultWebSessionManagerTests.java b/spring-web/src/test/java/org/springframework/web/server/session/DefaultWebSessionManagerTests.java index 8c51569968c5..6c6a5ba94c23 100644 --- a/spring-web/src/test/java/org/springframework/web/server/session/DefaultWebSessionManagerTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/session/DefaultWebSessionManagerTests.java @@ -69,7 +69,7 @@ class DefaultWebSessionManagerTests { @BeforeEach - void setUp() throws Exception { + void setUp() { given(this.createSession.save()).willReturn(Mono.empty()); given(this.createSession.getId()).willReturn("create-session-id"); given(this.updateSession.getId()).willReturn("update-session-id"); diff --git a/spring-web/src/test/java/org/springframework/web/server/session/InMemoryWebSessionStoreTests.java b/spring-web/src/test/java/org/springframework/web/server/session/InMemoryWebSessionStoreTests.java index f12d7ad78026..0bf488eda75a 100644 --- a/spring-web/src/test/java/org/springframework/web/server/session/InMemoryWebSessionStoreTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/session/InMemoryWebSessionStoreTests.java @@ -36,13 +36,13 @@ * * @author Rob Winch */ -public class InMemoryWebSessionStoreTests { +class InMemoryWebSessionStoreTests { private InMemoryWebSessionStore store = new InMemoryWebSessionStore(); @Test - public void startsSessionExplicitly() { + void startsSessionExplicitly() { WebSession session = this.store.createWebSession().block(); assertThat(session).isNotNull(); session.start(); @@ -50,7 +50,7 @@ public void startsSessionExplicitly() { } @Test - public void startsSessionImplicitly() { + void startsSessionImplicitly() { WebSession session = this.store.createWebSession().block(); assertThat(session).isNotNull(); session.start(); @@ -66,7 +66,7 @@ public void createSessionDoesNotBlock() { } @Test - public void retrieveExpiredSession() { + void retrieveExpiredSession() { WebSession session = this.store.createWebSession().block(); assertThat(session).isNotNull(); session.getAttributes().put("foo", "bar"); @@ -84,7 +84,7 @@ public void retrieveExpiredSession() { } @Test - public void lastAccessTimeIsUpdatedOnRetrieve() { + void lastAccessTimeIsUpdatedOnRetrieve() { WebSession session1 = this.store.createWebSession().block(); assertThat(session1).isNotNull(); String id = session1.getId(); @@ -131,7 +131,7 @@ public void sessionInvalidatedBeforeSave() { } @Test - public void expirationCheckPeriod() { + void expirationCheckPeriod() { DirectFieldAccessor accessor = new DirectFieldAccessor(this.store); Map sessions = (Map) accessor.getPropertyValue("sessions"); @@ -151,7 +151,7 @@ public void expirationCheckPeriod() { } @Test - public void maxSessions() { + void maxSessions() { IntStream.range(0, 10000).forEach(i -> insertSession()); assertThatIllegalStateException().isThrownBy( diff --git a/spring-web/src/test/java/org/springframework/web/server/session/WebSessionIntegrationTests.java b/spring-web/src/test/java/org/springframework/web/server/session/WebSessionIntegrationTests.java index ccba5fcfd2cb..1cae7c7c96d4 100644 --- a/spring-web/src/test/java/org/springframework/web/server/session/WebSessionIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/session/WebSessionIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -45,7 +45,7 @@ * @author Rossen Stoyanchev * @author Sam Brannen */ -public class WebSessionIntegrationTests extends AbstractHttpHandlerIntegrationTests { +class WebSessionIntegrationTests extends AbstractHttpHandlerIntegrationTests { private final RestTemplate restTemplate = new RestTemplate(); diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java index c8d115c1a1d3..dc9851027bff 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -91,7 +91,7 @@ void service() { assertThat(voidEntity.getBody()).isNull(); List list = service.getList(); - assertThat(list).element(0).isEqualTo("exchangeForBody"); + assertThat(list).containsExactly("exchangeForBody"); } @Test @@ -144,7 +144,7 @@ void rxJavaService() { assertThat(bodySingle.blockingGet()).isEqualTo("exchangeForBodyMono"); Flowable bodyFlow = service.getFlowableBody(); - assertThat(bodyFlow.toList().blockingGet()).asList().containsExactly("exchange", "For", "Body", "Flux"); + assertThat(bodyFlow.toList().blockingGet()).containsExactly("exchange", "For", "Body", "Flux"); Single> voidEntity = service.getVoidEntity(); assertThat(voidEntity.blockingGet().getBody()).isNull(); diff --git a/spring-web/src/test/java/org/springframework/web/util/ContentCachingRequestWrapperTests.java b/spring-web/src/test/java/org/springframework/web/util/ContentCachingRequestWrapperTests.java index 82f8777a1c08..df5b778268fc 100644 --- a/spring-web/src/test/java/org/springframework/web/util/ContentCachingRequestWrapperTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/ContentCachingRequestWrapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -34,7 +34,7 @@ * @author Brian Clozel * @author Stephane Nicoll */ -public class ContentCachingRequestWrapperTests { +class ContentCachingRequestWrapperTests { protected static final String FORM_CONTENT_TYPE = MediaType.APPLICATION_FORM_URLENCODED_VALUE; diff --git a/spring-web/src/test/java/org/springframework/web/util/DefaultUriBuilderFactoryTests.java b/spring-web/src/test/java/org/springframework/web/util/DefaultUriBuilderFactoryTests.java index ed834815f32c..a17c4bfed5c6 100644 --- a/spring-web/src/test/java/org/springframework/web/util/DefaultUriBuilderFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/DefaultUriBuilderFactoryTests.java @@ -32,10 +32,10 @@ * * @author Rossen Stoyanchev */ -public class DefaultUriBuilderFactoryTests { +class DefaultUriBuilderFactoryTests { @Test - public void defaultSettings() { + void defaultSettings() { DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(); URI uri = factory.uriString("/foo/{id}").build("a/b"); assertThat(uri.toString()).isEqualTo("/foo/a%2Fb"); @@ -49,28 +49,28 @@ public void defaultSettingsWithBuilder() { } @Test - public void baseUri() { + void baseUri() { DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("https://foo.example/v1?id=123"); URI uri = factory.uriString("/bar").port(8080).build(); assertThat(uri.toString()).isEqualTo("https://foo.example:8080/v1/bar?id=123"); } @Test - public void baseUriWithFullOverride() { + void baseUriWithFullOverride() { DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("https://foo.example/v1?id=123"); URI uri = factory.uriString("https://example.com/1/2").build(); assertThat(uri.toString()).as("Use of host should case baseUri to be completely ignored").isEqualTo("https://example.com/1/2"); } @Test - public void baseUriWithPathOverride() { + void baseUriWithPathOverride() { DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("https://foo.example/v1"); URI uri = factory.builder().replacePath("/baz").build(); assertThat(uri.toString()).isEqualTo("https://foo.example/baz"); } @Test - public void defaultUriVars() { + void defaultUriVars() { DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("https://{host}/v1"); factory.setDefaultUriVariables(singletonMap("host", "foo.example")); URI uri = factory.uriString("/{id}").build(singletonMap("id", "123")); @@ -78,7 +78,7 @@ public void defaultUriVars() { } @Test - public void defaultUriVarsWithOverride() { + void defaultUriVarsWithOverride() { DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("https://{host}/v1"); factory.setDefaultUriVariables(singletonMap("host", "spring.io")); URI uri = factory.uriString("/bar").build(singletonMap("host", "docs.spring.io")); @@ -86,7 +86,7 @@ public void defaultUriVarsWithOverride() { } @Test - public void defaultUriVarsWithEmptyVarArg() { + void defaultUriVarsWithEmptyVarArg() { DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("https://{host}/v1"); factory.setDefaultUriVariables(singletonMap("host", "foo.example")); URI uri = factory.uriString("/bar").build(); @@ -94,7 +94,7 @@ public void defaultUriVarsWithEmptyVarArg() { } @Test - public void defaultUriVarsSpr14147() { + void defaultUriVarsSpr14147() { Map defaultUriVars = new HashMap<>(2); defaultUriVars.put("host", "api.example.com"); defaultUriVars.put("port", "443"); @@ -106,7 +106,7 @@ public void defaultUriVarsSpr14147() { } @Test - public void encodeTemplateAndValues() { + void encodeTemplateAndValues() { DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(); factory.setEncodingMode(EncodingMode.TEMPLATE_AND_VALUES); UriBuilder uriBuilder = factory.uriString("/hotel list/{city} specials?q={value}"); @@ -122,7 +122,7 @@ public void encodeTemplateAndValues() { } @Test - public void encodingValuesOnly() { + void encodingValuesOnly() { DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(); factory.setEncodingMode(EncodingMode.VALUES_ONLY); UriBuilder uriBuilder = factory.uriString("/foo/a%2Fb/{id}"); @@ -135,7 +135,7 @@ public void encodingValuesOnly() { } @Test - public void encodingValuesOnlySpr14147() { + void encodingValuesOnlySpr14147() { DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(); factory.setEncodingMode(EncodingMode.VALUES_ONLY); factory.setDefaultUriVariables(singletonMap("host", "www.example.com")); @@ -145,7 +145,7 @@ public void encodingValuesOnlySpr14147() { } @Test - public void encodingNone() { + void encodingNone() { DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(); factory.setEncodingMode(EncodingMode.NONE); UriBuilder uriBuilder = factory.uriString("/foo/a%2Fb/{id}"); @@ -158,14 +158,14 @@ public void encodingNone() { } @Test - public void parsePathWithDefaultSettings() { + void parsePathWithDefaultSettings() { DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("/foo/{bar}"); URI uri = factory.uriString("/baz/{id}").build("a/b", "c/d"); assertThat(uri.toString()).isEqualTo("/foo/a%2Fb/baz/c%2Fd"); } @Test - public void parsePathIsTurnedOff() { + void parsePathIsTurnedOff() { DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("/foo/{bar}"); factory.setEncodingMode(EncodingMode.URI_COMPONENT); factory.setParsePath(false); @@ -181,7 +181,7 @@ public void pathWithTrailingSlash() { } @Test - public void pathWithDuplicateSlashes() { + void pathWithDuplicateSlashes() { DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(); URI uri = factory.expand("/foo/////////bar"); assertThat(uri.toString()).isEqualTo("/foo/bar"); diff --git a/spring-web/src/test/java/org/springframework/web/util/HtmlCharacterEntityReferencesTests.java b/spring-web/src/test/java/org/springframework/web/util/HtmlCharacterEntityReferencesTests.java index ea6c1a66ce8a..37f610d79b49 100644 --- a/spring-web/src/test/java/org/springframework/web/util/HtmlCharacterEntityReferencesTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/HtmlCharacterEntityReferencesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 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. @@ -21,6 +21,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.StreamTokenizer; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; @@ -32,12 +33,12 @@ * @author Martin Kersten * @author Juergen Hoeller */ -public class HtmlCharacterEntityReferencesTests { +class HtmlCharacterEntityReferencesTests { private static final String DTD_FILE = "HtmlCharacterEntityReferences.dtd"; @Test - public void testSupportsAllCharacterEntityReferencesDefinedByHtml() { + void testSupportsAllCharacterEntityReferencesDefinedByHtml() { HtmlCharacterEntityReferences references = new HtmlCharacterEntityReferences(); Map charactersMap = getReferenceCharacterMap(); for (int character = 0; character < 10000; character++) { @@ -80,7 +81,7 @@ else if (character == 39) { // SPR-9293 @Test - public void testConvertToReferenceUTF8() { + void testConvertToReferenceUTF8() { HtmlCharacterEntityReferences entityReferences = new HtmlCharacterEntityReferences(); String utf8 = "UTF-8"; assertThat(entityReferences.convertToReference('<', utf8)).isEqualTo("<"); @@ -118,7 +119,7 @@ public CharacterEntityResourceIterator() { if (inputStream == null) { throw new IOException("Cannot find definition resource [" + DTD_FILE + "]"); } - tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(inputStream, "UTF-8"))); + tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))); } catch (IOException ex) { throw new IllegalStateException("Failed to open definition resource [" + DTD_FILE + "]"); diff --git a/spring-web/src/test/java/org/springframework/web/util/HtmlUtilsTests.java b/spring-web/src/test/java/org/springframework/web/util/HtmlUtilsTests.java index 12436cc50f7d..53d0e585df3f 100644 --- a/spring-web/src/test/java/org/springframework/web/util/HtmlUtilsTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/HtmlUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -25,7 +25,7 @@ * @author Martin Kersten * @author Rick Evans */ -public class HtmlUtilsTests { +class HtmlUtilsTests { @Test void testHtmlEscape() { diff --git a/spring-web/src/test/java/org/springframework/web/util/JavaScriptUtilsTests.java b/spring-web/src/test/java/org/springframework/web/util/JavaScriptUtilsTests.java index 6fb380337ded..d00782214489 100644 --- a/spring-web/src/test/java/org/springframework/web/util/JavaScriptUtilsTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/JavaScriptUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2021 the original author or authors. + * Copyright 2002-2024 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. @@ -16,8 +16,6 @@ package org.springframework.web.util; -import java.io.UnsupportedEncodingException; - import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -27,10 +25,10 @@ * * @author Rossen Stoyanchev */ -public class JavaScriptUtilsTests { +class JavaScriptUtilsTests { @Test - public void escape() { + void escape() { StringBuilder sb = new StringBuilder(); sb.append('"'); sb.append('\''); @@ -48,7 +46,7 @@ public void escape() { // SPR-9983 @Test - public void escapePsLsLineTerminators() { + void escapePsLsLineTerminators() { StringBuilder sb = new StringBuilder(); sb.append('\u2028'); sb.append('\u2029'); @@ -60,7 +58,7 @@ public void escapePsLsLineTerminators() { // SPR-9983 @Test - public void escapeLessThanGreaterThanSigns() throws UnsupportedEncodingException { + void escapeLessThanGreaterThanSigns() { assertThat(JavaScriptUtils.javaScriptEscape("<>")).isEqualTo("\\u003C\\u003E"); } diff --git a/spring-web/src/test/java/org/springframework/web/util/NestedServletExceptionTests.java b/spring-web/src/test/java/org/springframework/web/util/NestedServletExceptionTests.java index f7f29e62cca9..eb3a2c16f785 100644 --- a/spring-web/src/test/java/org/springframework/web/util/NestedServletExceptionTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/NestedServletExceptionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -26,13 +26,13 @@ public class NestedServletExceptionTests { @Test - public void testNestedServletExceptionString() { + void testNestedServletExceptionString() { NestedServletException exception = new NestedServletException("foo"); assertThat(exception.getMessage()).isEqualTo("foo"); } @Test - public void testNestedServletExceptionStringThrowable() { + void testNestedServletExceptionStringThrowable() { Throwable cause = new RuntimeException(); NestedServletException exception = new NestedServletException("foo", cause); assertThat(exception.getMessage()).isEqualTo(NestedExceptionUtils.buildMessage("foo", cause)); @@ -40,7 +40,7 @@ public void testNestedServletExceptionStringThrowable() { } @Test - public void testNestedServletExceptionStringNullThrowable() { + void testNestedServletExceptionStringNullThrowable() { // This can happen if someone is sloppy with Throwable causes... NestedServletException exception = new NestedServletException("foo", null); assertThat(exception.getMessage()).isEqualTo("foo"); diff --git a/spring-web/src/test/java/org/springframework/web/util/ServletContextPropertyUtilsTests.java b/spring-web/src/test/java/org/springframework/web/util/ServletContextPropertyUtilsTests.java index d87c7c416518..c792ece66c27 100644 --- a/spring-web/src/test/java/org/springframework/web/util/ServletContextPropertyUtilsTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/ServletContextPropertyUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -26,10 +26,10 @@ * @author Marten Deinum * @since 3.2.2 */ -public class ServletContextPropertyUtilsTests { +class ServletContextPropertyUtilsTests { @Test - public void resolveAsServletContextInitParameter() { + void resolveAsServletContextInitParameter() { MockServletContext servletContext = new MockServletContext(); servletContext.setInitParameter("test.prop", "bar"); String resolved = ServletContextPropertyUtils.resolvePlaceholders("${test.prop:foo}", servletContext); @@ -37,7 +37,7 @@ public void resolveAsServletContextInitParameter() { } @Test - public void fallbackToSystemProperties() { + void fallbackToSystemProperties() { MockServletContext servletContext = new MockServletContext(); System.setProperty("test.prop", "bar"); try { diff --git a/spring-web/src/test/java/org/springframework/web/util/ServletRequestPathUtilsTests.java b/spring-web/src/test/java/org/springframework/web/util/ServletRequestPathUtilsTests.java index e4042f8b4ac1..aa2e28037263 100644 --- a/spring-web/src/test/java/org/springframework/web/util/ServletRequestPathUtilsTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/ServletRequestPathUtilsTests.java @@ -30,7 +30,7 @@ * * @author Rossen Stoyanchev */ -public class ServletRequestPathUtilsTests { +class ServletRequestPathUtilsTests { @Test void parseAndCache() { diff --git a/spring-web/src/test/java/org/springframework/web/util/TagUtilsTests.java b/spring-web/src/test/java/org/springframework/web/util/TagUtilsTests.java index e3d3bfc1918c..11f19730adf5 100644 --- a/spring-web/src/test/java/org/springframework/web/util/TagUtilsTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/TagUtilsTests.java @@ -31,10 +31,10 @@ * @author Alef Arendsen * @author Rick Evans */ -public class TagUtilsTests { +class TagUtilsTests { @Test - public void getScopeSunnyDay() { + void getScopeSunnyDay() { assertThat(TagUtils.SCOPE_PAGE).isEqualTo("page"); assertThat(TagUtils.SCOPE_APPLICATION).isEqualTo("application"); assertThat(TagUtils.SCOPE_SESSION).isEqualTo("session"); @@ -51,31 +51,31 @@ public void getScopeSunnyDay() { } @Test - public void getScopeWithNullScopeArgument() { + void getScopeWithNullScopeArgument() { assertThatIllegalArgumentException().isThrownBy(() -> TagUtils.getScope(null)); } @Test - public void hasAncestorOfTypeWhereAncestorTagIsNotATagType() throws Exception { + void hasAncestorOfTypeWhereAncestorTagIsNotATagType() { assertThatIllegalArgumentException().isThrownBy(() -> TagUtils.hasAncestorOfType(new TagSupport(), String.class)); } @Test - public void hasAncestorOfTypeWithNullTagArgument() throws Exception { + void hasAncestorOfTypeWithNullTagArgument() { assertThatIllegalArgumentException().isThrownBy(() -> TagUtils.hasAncestorOfType(null, TagSupport.class)); } @Test - public void hasAncestorOfTypeWithNullAncestorTagClassArgument() throws Exception { + void hasAncestorOfTypeWithNullAncestorTagClassArgument() { assertThatIllegalArgumentException().isThrownBy(() -> TagUtils.hasAncestorOfType(new TagSupport(), null)); } @Test - public void hasAncestorOfTypeTrueScenario() throws Exception { + void hasAncestorOfTypeTrueScenario() { Tag a = new TagA(); Tag b = new TagB(); Tag c = new TagC(); @@ -87,7 +87,7 @@ public void hasAncestorOfTypeTrueScenario() throws Exception { } @Test - public void hasAncestorOfTypeFalseScenario() throws Exception { + void hasAncestorOfTypeFalseScenario() { Tag a = new TagA(); Tag b = new TagB(); Tag anotherB = new TagB(); @@ -99,24 +99,24 @@ public void hasAncestorOfTypeFalseScenario() throws Exception { } @Test - public void hasAncestorOfTypeWhenTagHasNoParent() throws Exception { + void hasAncestorOfTypeWhenTagHasNoParent() { assertThat(TagUtils.hasAncestorOfType(new TagA(), TagC.class)).isFalse(); } @Test - public void assertHasAncestorOfTypeWithNullTagName() throws Exception { + void assertHasAncestorOfTypeWithNullTagName() { assertThatIllegalArgumentException().isThrownBy(() -> TagUtils.assertHasAncestorOfType(new TagA(), TagC.class, null, "c")); } @Test - public void assertHasAncestorOfTypeWithNullAncestorTagName() throws Exception { + void assertHasAncestorOfTypeWithNullAncestorTagName() { assertThatIllegalArgumentException().isThrownBy(() -> TagUtils.assertHasAncestorOfType(new TagA(), TagC.class, "a", null)); } @Test - public void assertHasAncestorOfTypeThrowsExceptionOnFail() throws Exception { + void assertHasAncestorOfTypeThrowsExceptionOnFail() { Tag a = new TagA(); Tag b = new TagB(); Tag anotherB = new TagB(); @@ -129,7 +129,7 @@ public void assertHasAncestorOfTypeThrowsExceptionOnFail() throws Exception { } @Test - public void testAssertHasAncestorOfTypeDoesNotThrowExceptionOnPass() throws Exception { + void testAssertHasAncestorOfTypeDoesNotThrowExceptionOnPass() { Tag a = new TagA(); Tag b = new TagB(); Tag c = new TagC(); diff --git a/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java b/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java index 75e636456c96..67744a2b3363 100644 --- a/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java @@ -599,7 +599,7 @@ void buildAndExpandOpaque() { void queryParamWithValueWithEquals() { UriComponents uriComponents = UriComponentsBuilder.fromUriString("https://example.com/foo?bar=baz").build(); assertThat(uriComponents.toUriString()).isEqualTo("https://example.com/foo?bar=baz"); - assertThat(uriComponents.getQueryParams().get("bar")).element(0).isEqualTo("baz"); + assertThat(uriComponents.getQueryParams().get("bar")).containsExactly("baz"); } @Test diff --git a/spring-web/src/test/java/org/springframework/web/util/UriUtilsTests.java b/spring-web/src/test/java/org/springframework/web/util/UriUtilsTests.java index 61a01c6cdacc..16c4e131bbf2 100644 --- a/spring-web/src/test/java/org/springframework/web/util/UriUtilsTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/UriUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -29,49 +29,49 @@ * @author Juergen Hoeller * @author Med Belamachi */ -public class UriUtilsTests { +class UriUtilsTests { private static final Charset CHARSET = StandardCharsets.UTF_8; @Test - public void encodeScheme() { + void encodeScheme() { assertThat(UriUtils.encodeScheme("foobar+-.", CHARSET)).as("Invalid encoded result").isEqualTo("foobar+-."); assertThat(UriUtils.encodeScheme("foo bar", CHARSET)).as("Invalid encoded result").isEqualTo("foo%20bar"); } @Test - public void encodeUserInfo() { + void encodeUserInfo() { assertThat(UriUtils.encodeUserInfo("foobar:", CHARSET)).as("Invalid encoded result").isEqualTo("foobar:"); assertThat(UriUtils.encodeUserInfo("foo bar", CHARSET)).as("Invalid encoded result").isEqualTo("foo%20bar"); } @Test - public void encodeHost() { + void encodeHost() { assertThat(UriUtils.encodeHost("foobar", CHARSET)).as("Invalid encoded result").isEqualTo("foobar"); assertThat(UriUtils.encodeHost("foo bar", CHARSET)).as("Invalid encoded result").isEqualTo("foo%20bar"); } @Test - public void encodePort() { + void encodePort() { assertThat(UriUtils.encodePort("80", CHARSET)).as("Invalid encoded result").isEqualTo("80"); } @Test - public void encodePath() { + void encodePath() { assertThat(UriUtils.encodePath("/foo/bar", CHARSET)).as("Invalid encoded result").isEqualTo("/foo/bar"); assertThat(UriUtils.encodePath("/foo bar", CHARSET)).as("Invalid encoded result").isEqualTo("/foo%20bar"); assertThat(UriUtils.encodePath("/Z\u00fcrich", CHARSET)).as("Invalid encoded result").isEqualTo("/Z%C3%BCrich"); } @Test - public void encodePathSegment() { + void encodePathSegment() { assertThat(UriUtils.encodePathSegment("foobar", CHARSET)).as("Invalid encoded result").isEqualTo("foobar"); assertThat(UriUtils.encodePathSegment("/foo/bar", CHARSET)).as("Invalid encoded result").isEqualTo("%2Ffoo%2Fbar"); } @Test - public void encodeQuery() { + void encodeQuery() { assertThat(UriUtils.encodeQuery("foobar", CHARSET)).as("Invalid encoded result").isEqualTo("foobar"); assertThat(UriUtils.encodeQuery("foo bar", CHARSET)).as("Invalid encoded result").isEqualTo("foo%20bar"); assertThat(UriUtils.encodeQuery("foobar/+", CHARSET)).as("Invalid encoded result").isEqualTo("foobar/+"); @@ -79,27 +79,27 @@ public void encodeQuery() { } @Test - public void encodeQueryParam() { + void encodeQueryParam() { assertThat(UriUtils.encodeQueryParam("foobar", CHARSET)).as("Invalid encoded result").isEqualTo("foobar"); assertThat(UriUtils.encodeQueryParam("foo bar", CHARSET)).as("Invalid encoded result").isEqualTo("foo%20bar"); assertThat(UriUtils.encodeQueryParam("foo&bar", CHARSET)).as("Invalid encoded result").isEqualTo("foo%26bar"); } @Test - public void encodeFragment() { + void encodeFragment() { assertThat(UriUtils.encodeFragment("foobar", CHARSET)).as("Invalid encoded result").isEqualTo("foobar"); assertThat(UriUtils.encodeFragment("foo bar", CHARSET)).as("Invalid encoded result").isEqualTo("foo%20bar"); assertThat(UriUtils.encodeFragment("foobar/", CHARSET)).as("Invalid encoded result").isEqualTo("foobar/"); } @Test - public void encode() { + void encode() { assertThat(UriUtils.encode("foo", CHARSET)).as("Invalid encoded result").isEqualTo("foo"); assertThat(UriUtils.encode("https://example.com/foo bar", CHARSET)).as("Invalid encoded result").isEqualTo("https%3A%2F%2Fexample.com%2Ffoo%20bar"); } @Test - public void decode() { + void decode() { assertThat(UriUtils.decode("", CHARSET)).as("Invalid encoded URI").isEmpty(); assertThat(UriUtils.decode("foobar", CHARSET)).as("Invalid encoded URI").isEqualTo("foobar"); assertThat(UriUtils.decode("foo%20bar", CHARSET)).as("Invalid encoded URI").isEqualTo("foo bar"); @@ -110,13 +110,13 @@ public void decode() { } @Test - public void decodeInvalidSequence() { + void decodeInvalidSequence() { assertThatIllegalArgumentException().isThrownBy(() -> UriUtils.decode("foo%2", CHARSET)); } @Test - public void extractFileExtension() { + void extractFileExtension() { assertThat(UriUtils.extractFileExtension("index.html")).isEqualTo("html"); assertThat(UriUtils.extractFileExtension("/index.html")).isEqualTo("html"); assertThat(UriUtils.extractFileExtension("/products/view.html")).isEqualTo("html"); diff --git a/spring-web/src/test/java/org/springframework/web/util/WebUtilsTests.java b/spring-web/src/test/java/org/springframework/web/util/WebUtilsTests.java index d246a5863236..68712d808855 100644 --- a/spring-web/src/test/java/org/springframework/web/util/WebUtilsTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/WebUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -41,7 +41,7 @@ * @author Rossen Stoyanchev * @author Sebastien Deleuze */ -public class WebUtilsTests { +class WebUtilsTests { @Test void findParameterValue() { diff --git a/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternParserTests.java b/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternParserTests.java index d15ece539c8a..5d477e3808c2 100644 --- a/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternParserTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -37,12 +37,12 @@ * @author Andy Clement * @author Sam Brannen */ -public class PathPatternParserTests { +class PathPatternParserTests { private PathPattern pathPattern; @Test - public void basicPatterns() { + void basicPatterns() { checkStructure("/"); checkStructure("/foo"); checkStructure("foo"); @@ -52,7 +52,7 @@ public void basicPatterns() { } @Test - public void singleCharWildcardPatterns() { + void singleCharWildcardPatterns() { pathPattern = checkStructure("?"); assertPathElements(pathPattern, SingleCharWildcardedPathElement.class); checkStructure("/?/"); @@ -60,7 +60,7 @@ public void singleCharWildcardPatterns() { } @Test - public void multiwildcardPattern() { + void multiwildcardPattern() { pathPattern = checkStructure("/**"); assertPathElements(pathPattern, WildcardTheRestPathElement.class); // this is not double wildcard, it's / then **acb (an odd, unnecessary use of double *) @@ -69,7 +69,7 @@ public void multiwildcardPattern() { } @Test - public void toStringTests() { + void toStringTests() { assertThat(checkStructure("/{*foobar}").toChainString()).isEqualTo("CaptureTheRest(/{*foobar})"); assertThat(checkStructure("{foobar}").toChainString()).isEqualTo("CaptureVariable({foobar})"); assertThat(checkStructure("abc").toChainString()).isEqualTo("Literal(abc)"); @@ -81,7 +81,7 @@ public void toStringTests() { } @Test - public void captureTheRestPatterns() { + void captureTheRestPatterns() { pathPattern = parse("{*foobar}"); assertThat(pathPattern.computePatternString()).isEqualTo("/{*foobar}"); assertPathElements(pathPattern, CaptureTheRestPathElement.class); @@ -99,7 +99,7 @@ public void captureTheRestPatterns() { } @Test - public void equalsAndHashcode() { + void equalsAndHashcode() { PathPatternParser caseInsensitiveParser = new PathPatternParser(); caseInsensitiveParser.setCaseSensitive(false); PathPatternParser caseSensitiveParser = new PathPatternParser(); @@ -117,7 +117,7 @@ public void equalsAndHashcode() { } @Test - public void regexPathElementPatterns() { + void regexPathElementPatterns() { checkError("/{var:[^/]*}", 8, PatternMessage.MISSING_CLOSE_CAPTURE); checkError("/{var:abc", 8, PatternMessage.MISSING_CLOSE_CAPTURE); @@ -183,7 +183,7 @@ public void regexPathElementPatterns() { } @Test - public void completeCapturingPatterns() { + void completeCapturingPatterns() { pathPattern = checkStructure("{foo}"); assertThat(pathPattern.getHeadSection().getClass().getName()).isEqualTo(CaptureVariablePathElement.class.getName()); checkStructure("/{foo}"); @@ -193,7 +193,7 @@ public void completeCapturingPatterns() { } @Test - public void noEncoding() { + void noEncoding() { // Check no encoding of expressions or constraints PathPattern pp = parse("/{var:f o}"); assertThat(pp.toChainString()).isEqualTo("Separator(/) CaptureVariable({var:f o})"); @@ -206,7 +206,7 @@ public void noEncoding() { } @Test - public void completeCaptureWithConstraints() { + void completeCaptureWithConstraints() { pathPattern = checkStructure("{foo:...}"); assertPathElements(pathPattern, CaptureVariablePathElement.class); pathPattern = checkStructure("{foo:[0-9]*}"); @@ -215,7 +215,7 @@ public void completeCaptureWithConstraints() { } @Test - public void partialCapturingPatterns() { + void partialCapturingPatterns() { pathPattern = checkStructure("{foo}abc"); assertThat(pathPattern.getHeadSection().getClass().getName()).isEqualTo(RegexPathElement.class.getName()); checkStructure("abc{foo}"); @@ -228,7 +228,7 @@ public void partialCapturingPatterns() { } @Test - public void illegalCapturePatterns() { + void illegalCapturePatterns() { checkError("{abc/", 4, PatternMessage.MISSING_CLOSE_CAPTURE); checkError("{abc:}/", 5, PatternMessage.MISSING_REGEX_CONSTRAINT); checkError("{", 1, PatternMessage.MISSING_CLOSE_CAPTURE); @@ -256,7 +256,7 @@ public void illegalCapturePatterns() { } @Test - public void badPatterns() { + void badPatterns() { // checkError("/{foo}{bar}/",6,PatternMessage.CANNOT_HAVE_ADJACENT_CAPTURES); checkError("/{?}/", 2, PatternMessage.ILLEGAL_CHARACTER_AT_START_OF_CAPTURE_DESCRIPTOR, "?"); checkError("/{a?b}/", 3, PatternMessage.ILLEGAL_CHARACTER_IN_CAPTURE_DESCRIPTOR, "?"); @@ -266,7 +266,7 @@ public void badPatterns() { } @Test - public void patternPropertyGetCaptureCountTests() { + void patternPropertyGetCaptureCountTests() { // Test all basic section types assertThat(parse("{foo}").getCapturedVariableCount()).isEqualTo(1); assertThat(parse("foo").getCapturedVariableCount()).isEqualTo(0); @@ -288,7 +288,7 @@ public void patternPropertyGetCaptureCountTests() { } @Test - public void patternPropertyGetWildcardCountTests() { + void patternPropertyGetWildcardCountTests() { // Test all basic section types assertThat(parse("{foo}").getScore()).isEqualTo(computeScore(1, 0)); assertThat(parse("foo").getScore()).isEqualTo(computeScore(0, 0)); @@ -311,7 +311,7 @@ public void patternPropertyGetWildcardCountTests() { } @Test - public void multipleSeparatorPatterns() { + void multipleSeparatorPatterns() { pathPattern = checkStructure("///aaa"); assertThat(pathPattern.getNormalizedLength()).isEqualTo(6); assertPathElements(pathPattern, SeparatorPathElement.class, SeparatorPathElement.class, @@ -329,7 +329,7 @@ public void multipleSeparatorPatterns() { } @Test - public void patternPropertyGetLengthTests() { + void patternPropertyGetLengthTests() { // Test all basic section types assertThat(parse("{foo}").getNormalizedLength()).isEqualTo(1); assertThat(parse("foo").getNormalizedLength()).isEqualTo(3); @@ -351,7 +351,7 @@ public void patternPropertyGetLengthTests() { } @Test - public void compareTests() { + void compareTests() { PathPattern p1, p2, p3; // Based purely on number of captures @@ -415,7 +415,7 @@ public void compareTests() { } @Test - public void captureTheRestWithinPatternNotSupported() { + void captureTheRestWithinPatternNotSupported() { PathPatternParser parser = new PathPatternParser(); assertThatThrownBy(() -> parser.parse("/resources/**/details")) .isInstanceOf(PatternParseException.class) @@ -423,7 +423,7 @@ public void captureTheRestWithinPatternNotSupported() { } @Test - public void separatorTests() { + void separatorTests() { PathPatternParser parser = new PathPatternParser(); parser.setPathOptions(PathContainer.Options.create('.', false)); String rawPattern = "first.second.{last}"; diff --git a/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternRouteMatcherTests.java b/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternRouteMatcherTests.java index b02f3f2cda63..c0f9bb63648e 100644 --- a/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternRouteMatcherTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternRouteMatcherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -31,17 +31,17 @@ * @author Brian Clozel * @since 5.2 */ -public class PathPatternRouteMatcherTests { +class PathPatternRouteMatcherTests { @Test - public void matchRoute() { + void matchRoute() { PathPatternRouteMatcher routeMatcher = new PathPatternRouteMatcher(); RouteMatcher.Route route = routeMatcher.parseRoute("projects.spring-framework"); assertThat(routeMatcher.match("projects.{name}", route)).isTrue(); } @Test - public void matchRouteWithCustomSeparator() { + void matchRouteWithCustomSeparator() { PathPatternParser parser = new PathPatternParser(); parser.setPathOptions(PathContainer.Options.create('/', false)); PathPatternRouteMatcher routeMatcher = new PathPatternRouteMatcher(parser); diff --git a/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternTests.java b/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternTests.java index 8a273a574747..cdf9a475d97b 100644 --- a/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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,10 +38,10 @@ * * @author Andy Clement */ -public class PathPatternTests { +class PathPatternTests { @Test - public void pathContainer() { + void pathContainer() { assertThat(elementsToString(toPathContainer("/abc/def").elements())).isEqualTo("[/][abc][/][def]"); assertThat(elementsToString(toPathContainer("abc/def").elements())).isEqualTo("[abc][/][def]"); assertThat(elementsToString(toPathContainer("abc/def/").elements())).isEqualTo("[abc][/][def][/]"); @@ -51,7 +51,7 @@ public void pathContainer() { } @Test - public void hasPatternSyntax() { + void hasPatternSyntax() { PathPatternParser parser = new PathPatternParser(); assertThat(parser.parse("/foo/*").hasPatternSyntax()).isTrue(); assertThat(parser.parse("/foo/**").hasPatternSyntax()).isTrue(); @@ -63,7 +63,7 @@ public void hasPatternSyntax() { } @Test - public void matching_LiteralPathElement() { + void matching_LiteralPathElement() { checkMatches("foo", "foo"); checkNoMatch("foo", "bar"); checkNoMatch("foo", "/foo"); @@ -78,7 +78,7 @@ public void matching_LiteralPathElement() { } @Test - public void basicMatching() { + void basicMatching() { checkMatches("", ""); checkMatches("", "/"); checkMatches("", null); @@ -101,7 +101,7 @@ private void assertNoMatch(PathPattern pp, String path) { @SuppressWarnings("deprecation") @Test - public void optionalTrailingSeparators() { + void optionalTrailingSeparators() { PathPattern pp; // LiteralPathElement pp = parse("/resource"); @@ -305,7 +305,7 @@ public void optionalTrailingSeparators() { } @Test - public void pathRemainderBasicCases_spr15336() { + void pathRemainderBasicCases_spr15336() { // Cover all PathElement kinds assertThat(getPathRemaining("/foo", "/foo/bar").getPathRemaining().value()).isEqualTo("/bar"); assertThat(getPathRemaining("/foo", "/foo/").getPathRemaining().value()).isEqualTo("/"); @@ -326,7 +326,7 @@ public void pathRemainderBasicCases_spr15336() { } @Test - public void encodingAndBoundVariablesCapturePathElement() { + void encodingAndBoundVariablesCapturePathElement() { checkCapture("{var}","f%20o","var","f o"); checkCapture("{var1}/{var2}","f%20o/f%7Co","var1","f o","var2","f|o"); checkCapture("{var1}/{var2}","f%20o/f%7co","var1","f o","var2","f|o"); // lower case encoding @@ -338,7 +338,7 @@ public void encodingAndBoundVariablesCapturePathElement() { } @Test - public void encodingAndBoundVariablesCaptureTheRestPathElement() { + void encodingAndBoundVariablesCaptureTheRestPathElement() { checkCapture("/{*var}","/f%20o","var","/f o"); checkCapture("{var1}/{*var2}","f%20o/f%7Co","var1","f o","var2","/f|o"); checkCapture("/{*var}","/foo","var","/foo"); @@ -348,7 +348,7 @@ public void encodingAndBoundVariablesCaptureTheRestPathElement() { } @Test - public void encodingAndBoundVariablesRegexPathElement() { + void encodingAndBoundVariablesRegexPathElement() { checkCapture("/{var1:f o}_ _{var2}","/f%20o_%20_f%7co","var1","f o","var2","f|o"); checkCapture("/{var1}_{var2}","/f%20o_foo","var1","f o","var2","foo"); checkCapture("/{var1}_ _{var2}","/f%20o_%20_f%7co","var1","f o","var2","f|o"); @@ -359,7 +359,7 @@ public void encodingAndBoundVariablesRegexPathElement() { } @Test - public void pathRemainingCornerCases_spr15336() { + void pathRemainingCornerCases_spr15336() { // No match when the literal path element is a longer form of the segment in the pattern assertThat(parse("/foo").matchStartOfPath(toPathContainer("/footastic/bar"))).isNull(); assertThat(parse("/f?o").matchStartOfPath(toPathContainer("/footastic/bar"))).isNull(); @@ -401,7 +401,7 @@ public void pathRemainingCornerCases_spr15336() { } @Test - public void questionMarks() { + void questionMarks() { checkNoMatch("a", "ab"); checkMatches("/f?o/bar", "/foo/bar"); checkNoMatch("/foo/b2r", "/foo/bar"); @@ -418,7 +418,7 @@ public void questionMarks() { } @Test - public void captureTheRest() { + void captureTheRest() { checkMatches("/resource/{*foobar}", "/resource"); checkNoMatch("/resource/{*foobar}", "/resourceX"); checkNoMatch("/resource/{*foobar}", "/resourceX/foobar"); @@ -438,7 +438,7 @@ public void captureTheRest() { } @Test - public void multipleSeparatorsInPattern() { + void multipleSeparatorsInPattern() { PathPattern pp = parse("a//b//c"); assertThat(pp.toChainString()).isEqualTo("Literal(a) Separator(/) Separator(/) Literal(b) Separator(/) Separator(/) Literal(c)"); assertMatches(pp,"a//b//c"); @@ -454,7 +454,7 @@ public void multipleSeparatorsInPattern() { } @Test - public void multipleSelectorsInPath() { + void multipleSelectorsInPath() { checkNoMatch("/abc", "////abc"); checkNoMatch("/", "//"); checkNoMatch("/abc/def/ghi", "/abc//def///ghi"); @@ -467,7 +467,7 @@ public void multipleSelectorsInPath() { } @Test - public void multipleSeparatorsInPatternAndPath() { + void multipleSeparatorsInPatternAndPath() { checkNoMatch("///one///two///three", "//one/////two///////three"); checkMatches("//one/////two///////three", "//one/////two///////three"); checkNoMatch("//one//two//three", "/one/////two/three"); @@ -477,7 +477,7 @@ public void multipleSeparatorsInPatternAndPath() { @SuppressWarnings("deprecation") @Test - public void wildcards() { + void wildcards() { checkMatches("/*/bar", "/foo/bar"); checkNoMatch("/*/bar", "/foo/baz"); checkNoMatch("/*/bar", "//bar"); @@ -506,7 +506,7 @@ public void wildcards() { } @Test - public void constrainedMatches() { + void constrainedMatches() { checkCapture("{foo:[0-9]*}", "123", "foo", "123"); checkNoMatch("{foo:[0-9]*}", "abc"); checkNoMatch("/{foo:[0-9]*}", "abc"); @@ -520,7 +520,7 @@ public void constrainedMatches() { } @Test - public void antPathMatcherTests() { + void antPathMatcherTests() { // test exact matching checkMatches("test", "test"); checkMatches("/test", "/test"); @@ -588,7 +588,7 @@ public void antPathMatcherTests() { } @Test - public void pathRemainingEnhancements_spr15419() { + void pathRemainingEnhancements_spr15419() { PathPattern pp; PathPattern.PathRemainingMatchInfo pri; // It would be nice to partially match a path and get any bound variables in one step @@ -625,7 +625,7 @@ public void pathRemainingEnhancements_spr15419() { } @Test - public void caseSensitivity() { + void caseSensitivity() { PathPatternParser pp = new PathPatternParser(); pp.setCaseSensitive(false); PathPattern p = pp.parse("abc"); @@ -706,7 +706,7 @@ public void caseSensitivity() { } @Test - public void extractPathWithinPattern_spr15259() { + void extractPathWithinPattern_spr15259() { checkExtractPathWithinPattern("/**","//",""); checkExtractPathWithinPattern("/**","/",""); checkExtractPathWithinPattern("/**","",""); @@ -714,7 +714,7 @@ public void extractPathWithinPattern_spr15259() { } @Test - public void extractPathWithinPattern() throws Exception { + void extractPathWithinPattern() { checkExtractPathWithinPattern("/welcome*/", "/welcome/", "welcome"); checkExtractPathWithinPattern("/docs/commit.html", "/docs/commit.html", ""); checkExtractPathWithinPattern("/docs/*", "/docs/cvs/commit", "cvs/commit"); @@ -752,7 +752,7 @@ public void extractPathWithinPattern() throws Exception { } @Test - public void extractPathWithinPatternCustomSeparator() { + void extractPathWithinPatternCustomSeparator() { PathPatternParser ppp = new PathPatternParser(); ppp.setPathOptions(PathContainer.Options.create('.', true)); PathPattern pp = ppp.parse("test.**"); @@ -825,7 +825,7 @@ public void extractUriTemplateVariables_spr15264() { } @Test - public void extractUriTemplateVariables() throws Exception { + void extractUriTemplateVariables() { assertMatches(parse("{hotel}"),"1"); assertMatches(parse("/hotels/{hotel}"),"/hotels/1"); checkCapture("/hotels/{hotel}", "/hotels/1", "hotel", "1"); @@ -856,7 +856,7 @@ public void extractUriTemplateVariables() throws Exception { } @Test - public void extractUriTemplateVariablesRegex() { + void extractUriTemplateVariablesRegex() { PathPatternParser pp = new PathPatternParser(); PathPattern p = null; @@ -872,7 +872,7 @@ public void extractUriTemplateVariablesRegex() { } @Test - public void extractUriTemplateVarsRegexQualifiers() { + void extractUriTemplateVarsRegexQualifiers() { PathPatternParser pp = new PathPatternParser(); PathPattern p = pp.parse("{symbolicName:[\\p{L}\\.]+}-sources-{version:[\\p{N}\\.]+}.jar"); @@ -896,7 +896,7 @@ public void extractUriTemplateVarsRegexQualifiers() { } @Test - public void extractUriTemplateVarsRegexCapturingGroups() { + void extractUriTemplateVarsRegexCapturingGroups() { PathPatternParser ppp = new PathPatternParser(); PathPattern pathPattern = ppp.parse("/web/{id:foo(bar)?}_{goo}"); assertThatIllegalArgumentException().isThrownBy(() -> @@ -905,7 +905,7 @@ public void extractUriTemplateVarsRegexCapturingGroups() { } @Test - public void combine() { + void combine() { TestPathCombiner pathMatcher = new TestPathCombiner(); assertThat(pathMatcher.combine("", "")).isEmpty(); assertThat(pathMatcher.combine("/hotels", "")).isEqualTo("/hotels"); @@ -945,14 +945,14 @@ public void combine() { } @Test - public void combineWithTwoFileExtensionPatterns() { + void combineWithTwoFileExtensionPatterns() { TestPathCombiner pathMatcher = new TestPathCombiner(); assertThatIllegalArgumentException().isThrownBy(() -> pathMatcher.combine("/*.html", "/*.txt")); } @Test - public void patternComparator() { + void patternComparator() { Comparator comparator = PathPattern.SPECIFICITY_COMPARATOR; assertThat(comparator.compare(parse("/hotels/new"), parse("/hotels/new"))).isEqualTo(0); @@ -1009,7 +1009,7 @@ public void patternComparator() { } @Test - public void compare_spr15597() { + void compare_spr15597() { PathPatternParser parser = new PathPatternParser(); PathPattern p1 = parser.parse("/{foo}"); PathPattern p2 = parser.parse("/{foo}.*"); @@ -1028,14 +1028,14 @@ public void compare_spr15597() { } @Test - public void patternCompareWithNull() { + void patternCompareWithNull() { assertThat(PathPattern.SPECIFICITY_COMPARATOR.compare(null, null)).isEqualTo(0); assertThat(PathPattern.SPECIFICITY_COMPARATOR.compare(parse("/abc"), null)).isLessThan(0); assertThat(PathPattern.SPECIFICITY_COMPARATOR.compare(null, parse("/abc"))).isGreaterThan(0); } @Test - public void patternComparatorSort() { + void patternComparatorSort() { Comparator comparator = PathPattern.SPECIFICITY_COMPARATOR; List paths = new ArrayList<>(3); @@ -1145,7 +1145,7 @@ public void caseInsensitive() { } @Test - public void parameters() { + void parameters() { // CaptureVariablePathElement PathPattern.PathMatchInfo result = matchAndExtract("/abc/{var}","/abc/one;two=three;four=five"); assertThat(result.getUriVariables()).containsEntry("var", "one");