diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java index 54110bcd0d..4e004ea536 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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,7 +21,6 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; @@ -163,24 +162,22 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac /** - * Class modelling an AspectJ annotation, exposing its type enumeration and + * Class modeling an AspectJ annotation, exposing its type enumeration and * pointcut String. * @param the annotation type */ protected static class AspectJAnnotation { - private static final String[] EXPRESSION_ATTRIBUTES = new String[] {"pointcut", "value"}; + private static final String[] EXPRESSION_ATTRIBUTES = {"pointcut", "value"}; - private static Map, AspectJAnnotationType> annotationTypeMap = new HashMap<>(8); - - static { - annotationTypeMap.put(Pointcut.class, AspectJAnnotationType.AtPointcut); - annotationTypeMap.put(Around.class, AspectJAnnotationType.AtAround); - annotationTypeMap.put(Before.class, AspectJAnnotationType.AtBefore); - annotationTypeMap.put(After.class, AspectJAnnotationType.AtAfter); - annotationTypeMap.put(AfterReturning.class, AspectJAnnotationType.AtAfterReturning); - annotationTypeMap.put(AfterThrowing.class, AspectJAnnotationType.AtAfterThrowing); - } + private static final Map, AspectJAnnotationType> annotationTypeMap = Map.of( + Pointcut.class, AspectJAnnotationType.AtPointcut, // + Around.class, AspectJAnnotationType.AtAround, // + Before.class, AspectJAnnotationType.AtBefore, // + After.class, AspectJAnnotationType.AtAfter, // + AfterReturning.class, AspectJAnnotationType.AtAfterReturning, // + AfterThrowing.class, AspectJAnnotationType.AtAfterThrowing // + ); private final A annotation; @@ -196,7 +193,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac try { this.pointcutExpression = resolveExpression(annotation); Object argNames = AnnotationUtils.getValue(annotation, "argNames"); - this.argumentNames = (argNames instanceof String ? (String) argNames : ""); + this.argumentNames = (argNames instanceof String names ? names : ""); } catch (Exception ex) { throw new IllegalArgumentException(annotation + " is not a valid AspectJ annotation", ex); @@ -214,13 +211,11 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac private String resolveExpression(A annotation) { for (String attributeName : EXPRESSION_ATTRIBUTES) { Object val = AnnotationUtils.getValue(annotation, attributeName); - if (val instanceof String str) { - if (!str.isEmpty()) { - return str; - } + if (val instanceof String str && !str.isEmpty()) { + return str; } } - throw new IllegalStateException("Failed to resolve expression: " + annotation); + throw new IllegalStateException("Failed to resolve expression in: " + annotation); } public AspectJAnnotationType getAnnotationType() { diff --git a/spring-web/src/test/java/org/springframework/http/client/AbstractHttpRequestFactoryTests.java b/spring-web/src/test/java/org/springframework/http/client/AbstractHttpRequestFactoryTests.java index 427f21f619..87fc8ebba0 100644 --- a/spring-web/src/test/java/org/springframework/http/client/AbstractHttpRequestFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/AbstractHttpRequestFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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,15 +48,15 @@ abstract class AbstractHttpRequestFactoryTests extends AbstractMockWebServerTest @BeforeEach final void createFactory() throws Exception { factory = createRequestFactory(); - if (factory instanceof InitializingBean) { - ((InitializingBean) factory).afterPropertiesSet(); + if (factory instanceof InitializingBean initializingBean) { + initializingBean.afterPropertiesSet(); } } @AfterEach final void destroyFactory() throws Exception { - if (factory instanceof DisposableBean) { - ((DisposableBean) factory).destroy(); + if (factory instanceof DisposableBean disposableBean) { + disposableBean.destroy(); } } diff --git a/spring-web/src/test/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactoryTests.java b/spring-web/src/test/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactoryTests.java index 96a725d156..29c30d8c4c 100644 --- a/spring-web/src/test/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactoryTests.java @@ -38,7 +38,7 @@ import static org.mockito.Mockito.withSettings; /** * @author Stephane Nicoll */ -public class HttpComponentsClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests { +class HttpComponentsClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests { @Override protected ClientHttpRequestFactory createRequestFactory() { @@ -47,13 +47,14 @@ public class HttpComponentsClientHttpRequestFactoryTests extends AbstractHttpReq @Override @Test - public void httpMethods() throws Exception { + void httpMethods() throws Exception { super.httpMethods(); assertHttpMethod("patch", HttpMethod.PATCH); } @Test - public void assertCustomConfig() throws Exception { + @SuppressWarnings("deprecation") + void assertCustomConfig() throws Exception { HttpClient httpClient = HttpClientBuilder.create().build(); HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory(httpClient); hrf.setConnectTimeout(1234); @@ -71,7 +72,9 @@ public class HttpComponentsClientHttpRequestFactoryTests extends AbstractHttpReq } @Test - public void defaultSettingsOfHttpClientMergedOnExecutorCustomization() throws Exception { + @SuppressWarnings("deprecation") + void defaultSettingsOfHttpClientMergedOnExecutorCustomization() throws Exception { + @SuppressWarnings("deprecation") RequestConfig defaultConfig = RequestConfig.custom().setConnectTimeout(1234, MILLISECONDS).build(); CloseableHttpClient client = mock(CloseableHttpClient.class, withSettings().extraInterfaces(Configurable.class)); @@ -90,7 +93,8 @@ public class HttpComponentsClientHttpRequestFactoryTests extends AbstractHttpReq } @Test - public void localSettingsOverrideClientDefaultSettings() throws Exception { + @SuppressWarnings("deprecation") + void localSettingsOverrideClientDefaultSettings() throws Exception { RequestConfig defaultConfig = RequestConfig.custom() .setConnectTimeout(1234, MILLISECONDS) .setConnectionRequestTimeout(6789, MILLISECONDS) @@ -109,11 +113,12 @@ public class HttpComponentsClientHttpRequestFactoryTests extends AbstractHttpReq } @Test - public void mergeBasedOnCurrentHttpClient() throws Exception { + @SuppressWarnings("deprecation") + void mergeBasedOnCurrentHttpClient() throws Exception { RequestConfig defaultConfig = RequestConfig.custom() .setConnectionRequestTimeout(1234, MILLISECONDS) .build(); - final CloseableHttpClient client = mock(CloseableHttpClient.class, + CloseableHttpClient client = mock(CloseableHttpClient.class, withSettings().extraInterfaces(Configurable.class)); Configurable configurable = (Configurable) client; given(configurable.getConfig()).willReturn(defaultConfig); diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/CookieValueArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/CookieValueArgumentResolverTests.java index 2227002bb5..975268fad0 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/CookieValueArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/CookieValueArgumentResolverTests.java @@ -18,7 +18,6 @@ package org.springframework.web.service.invoker; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.util.ObjectUtils; @@ -29,6 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * Unit tests for {@link CookieValueArgumentResolver}. + * *

For base class functionality, see {@link NamedValueArgumentResolverTests}. * * @author Rossen Stoyanchev @@ -37,18 +37,9 @@ class CookieValueArgumentResolverTests { private final TestHttpClientAdapter client = new TestHttpClientAdapter(); - private Service service; + private final Service service = HttpServiceProxyFactory.builder(this.client).build().createClient(Service.class); - @BeforeEach - void setUp() throws Exception { - HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client).build(); - this.service = proxyFactory.createClient(Service.class); - } - - - // Base class functionality should be tested in NamedValueArgumentResolverTests. - @Test void cookieValue() { this.service.execute("test"); diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/HttpMethodArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/HttpMethodArgumentResolverTests.java index d4185496f2..97335dd58a 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/HttpMethodArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/HttpMethodArgumentResolverTests.java @@ -16,7 +16,6 @@ package org.springframework.web.service.invoker; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.http.HttpMethod; @@ -34,18 +33,11 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Olga Maciaszek-Sharma * @author Rossen Stoyanchev */ -public class HttpMethodArgumentResolverTests { +class HttpMethodArgumentResolverTests { private final TestHttpClientAdapter client = new TestHttpClientAdapter(); - private Service service; - - - @BeforeEach - void setUp() throws Exception { - HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client).build(); - this.service = proxyFactory.createClient(Service.class); - } + private final Service service = HttpServiceProxyFactory.builder(this.client).build().createClient(Service.class); @Test diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/HttpRequestValuesTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/HttpRequestValuesTests.java index 7d2428975d..55d26409c9 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/HttpRequestValuesTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/HttpRequestValuesTests.java @@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class HttpRequestValuesTests { +class HttpRequestValuesTests { @Test void defaultUri() { @@ -49,6 +49,7 @@ public class HttpRequestValuesTests { @ParameterizedTest @ValueSource(strings = {"POST", "PUT", "PATCH"}) + @SuppressWarnings("unchecked") void requestParamAsFormData(String httpMethod) { HttpRequestValues requestValues = HttpRequestValues.builder().setHttpMethod(HttpMethod.valueOf(httpMethod)) 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 beb6482db0..47ccdff83c 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 @@ -21,7 +21,6 @@ import java.util.Optional; import io.reactivex.rxjava3.core.Completable; import io.reactivex.rxjava3.core.Flowable; import io.reactivex.rxjava3.core.Single; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -52,20 +51,13 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; * * @author Rossen Stoyanchev */ -public class HttpServiceMethodTests { +class HttpServiceMethodTests { private static final ParameterizedTypeReference BODY_TYPE = new ParameterizedTypeReference<>() {}; - private final TestHttpClientAdapter client = new TestHttpClientAdapter(); - private HttpServiceProxyFactory proxyFactory; - - - @BeforeEach - void setUp() throws Exception { - this.proxyFactory = HttpServiceProxyFactory.builder(this.client).build(); - } + private final HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client).build(); @Test diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/PathVariableArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/PathVariableArgumentResolverTests.java index 83c39cee9b..868db74b4f 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/PathVariableArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/PathVariableArgumentResolverTests.java @@ -16,7 +16,6 @@ package org.springframework.web.service.invoker; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.lang.Nullable; @@ -27,6 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link PathVariableArgumentResolver}. + * *

For base class functionality, see {@link NamedValueArgumentResolverTests}. * * @author Olga Maciaszek-Sharma @@ -36,18 +36,9 @@ class PathVariableArgumentResolverTests { private final TestHttpClientAdapter client = new TestHttpClientAdapter(); - private Service service; + private final Service service = HttpServiceProxyFactory.builder(this.client).build().createClient(Service.class); - @BeforeEach - void setUp() throws Exception { - HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client).build(); - this.service = proxyFactory.createClient(Service.class); - } - - - // Base class functionality should be tested in NamedValueArgumentResolverTests. - @Test void pathVariable() { this.service.execute("test"); diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolverTests.java index 61ec118c22..4a63af4358 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolverTests.java @@ -16,7 +16,6 @@ package org.springframework.web.service.invoker; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.lang.Nullable; @@ -35,18 +34,9 @@ class RequestAttributeArgumentResolverTests { private final TestHttpClientAdapter client = new TestHttpClientAdapter(); - private Service service; + private final Service service = HttpServiceProxyFactory.builder(this.client).build().createClient(Service.class); - @BeforeEach - void setUp() throws Exception { - HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client).build(); - this.service = proxyFactory.createClient(Service.class); - } - - - // Base class functionality should be tested in NamedValueArgumentResolverTests. - @Test void cookieValue() { this.service.execute("test"); diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/RequestBodyArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/RequestBodyArgumentResolverTests.java index 1fe0d7b657..d74da77f31 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/RequestBodyArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/RequestBodyArgumentResolverTests.java @@ -18,7 +18,6 @@ package org.springframework.web.service.invoker; import io.reactivex.rxjava3.core.Completable; import io.reactivex.rxjava3.core.Single; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -36,18 +35,11 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * * @author Rossen Stoyanchev */ -public class RequestBodyArgumentResolverTests { +class RequestBodyArgumentResolverTests { private final TestHttpClientAdapter client = new TestHttpClientAdapter(); - private Service service; - - - @BeforeEach - void setUp() throws Exception { - HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client).build(); - this.service = proxyFactory.createClient(Service.class); - } + private final Service service = HttpServiceProxyFactory.builder(this.client).build().createClient(Service.class); @Test diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/RequestParamArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/RequestParamArgumentResolverTests.java index 07da632ae8..8a6f29ddbf 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/RequestParamArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/RequestParamArgumentResolverTests.java @@ -18,7 +18,6 @@ package org.springframework.web.service.invoker; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.util.MultiValueMap; @@ -38,24 +37,15 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class RequestParamArgumentResolverTests { +class RequestParamArgumentResolverTests { private final TestHttpClientAdapter client = new TestHttpClientAdapter(); - private Service service; + private final Service service = HttpServiceProxyFactory.builder(this.client).build().createClient(Service.class); - @BeforeEach - void setUp() throws Exception { - HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client).build(); - this.service = proxyFactory.createClient(Service.class); - } - - - // Base class functionality should be tested in NamedValueArgumentResolverTests. - // Form data vs query params tested in HttpRequestValuesTests. - @Test + @SuppressWarnings("unchecked") void requestParam() { this.service.postForm("value 1", "value 2"); diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/RequestPartArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/RequestPartArgumentResolverTests.java index 67d53b4da9..ba768c7a31 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/RequestPartArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/RequestPartArgumentResolverTests.java @@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class RequestPartArgumentResolverTests { +class RequestPartArgumentResolverTests { private final TestHttpClientAdapter client = new TestHttpClientAdapter(); diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/UrlArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/UrlArgumentResolverTests.java index 6e6ccfa240..3f236e0056 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/UrlArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/UrlArgumentResolverTests.java @@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * * @author Rossen Stoyanchev */ -public class UrlArgumentResolverTests { +class UrlArgumentResolverTests { private final TestHttpClientAdapter client = new TestHttpClientAdapter(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyMethodArgumentResolverTests.java index 2992dac9d6..9b91d7835c 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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.