Refactor.

This commit is contained in:
Olga Maciaszek-Sharma
2022-11-07 16:56:14 +01:00
parent a410fd1d10
commit 6f1fab1ab3
45 changed files with 98 additions and 130 deletions

View File

@@ -177,6 +177,7 @@ public class FeignAutoConfiguration {
return new AlphanumericCircuitBreakerNameResolver();
}
@SuppressWarnings("rawtypes")
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(CircuitBreakerFactory.class)
@@ -211,6 +212,7 @@ public class FeignAutoConfiguration {
// SC loadbalancer is not on the class path.
// see corresponding configurations in FeignLoadBalancerAutoConfiguration
// for load-balanced clients.
@SuppressWarnings("rawtypes")
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(ApacheHttpClient.class)
@ConditionalOnMissingBean(CloseableHttpClient.class)

View File

@@ -77,7 +77,7 @@ public final class FeignCircuitBreaker {
}
public <T> T target(Target<T> target, T fallback) {
return build(fallback != null ? new FallbackFactory.Default<T>(fallback) : null).newInstance(target);
return build(fallback != null ? new FallbackFactory.Default<>(fallback) : null).newInstance(target);
}
public <T> T target(Target<T> target, FallbackFactory<? extends T> fallbackFactory) {

View File

@@ -76,7 +76,7 @@ class FeignCircuitBreakerInvocationHandler implements InvocationHandler {
}
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
public Object invoke(final Object proxy, final Method method, final Object[] args) {
// early exit if the invoked method is from java.lang.Object
// code is the same as ReflectiveFeign.FeignInvocationHandler
if ("equals".equals(method.getName())) {
@@ -173,8 +173,7 @@ class FeignCircuitBreakerInvocationHandler implements InvocationHandler {
@Override
public boolean equals(Object obj) {
if (obj instanceof FeignCircuitBreakerInvocationHandler) {
FeignCircuitBreakerInvocationHandler other = (FeignCircuitBreakerInvocationHandler) obj;
if (obj instanceof FeignCircuitBreakerInvocationHandler other) {
return this.target.equals(other.target);
}
return false;

View File

@@ -41,10 +41,9 @@ class FeignCircuitBreakerTargeter implements Targeter {
@Override
public <T> T target(FeignClientFactoryBean factory, Feign.Builder feign, FeignContext context,
Target.HardCodedTarget<T> target) {
if (!(feign instanceof FeignCircuitBreaker.Builder)) {
if (!(feign instanceof FeignCircuitBreaker.Builder builder)) {
return feign.target(target);
}
FeignCircuitBreaker.Builder builder = (FeignCircuitBreaker.Builder) feign;
String name = !StringUtils.hasText(factory.getContextId()) ? factory.getName() : factory.getContextId();
Class<?> fallback = factory.getFallback();
if (fallback != void.class) {

View File

@@ -407,6 +407,7 @@ public class FeignClientFactoryBean
* @return a {@link Feign} client created with the specified data and the context
* information
*/
@SuppressWarnings("unchecked")
<T> T getTarget() {
FeignContext context = beanFactory != null ? beanFactory.getBean(FeignContext.class)
: applicationContext.getBean(FeignContext.class);
@@ -447,7 +448,7 @@ public class FeignClientFactoryBean
applyBuildCustomizers(context, builder);
Targeter targeter = get(context, Targeter.class);
return targeter.target(this, builder, context, (HardCodedTarget<T>) resolveTarget(context, contextId, url));
return targeter.target(this, builder, context, resolveTarget(context, contextId, url));
}
private String cleanPath() {
@@ -466,6 +467,7 @@ public class FeignClientFactoryBean
return path;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private <T> HardCodedTarget<T> resolveTarget(FeignContext context, String contextId, String url) {
if (StringUtils.hasText(url)) {
return new HardCodedTarget(type, name, url);

View File

@@ -64,18 +64,18 @@ public class FeignClientSpecification implements NamedContextFactory.Specificati
return false;
}
FeignClientSpecification that = (FeignClientSpecification) o;
return Objects.equals(this.name, that.name) && Arrays.equals(this.configuration, that.configuration);
return Objects.equals(name, that.name) && Arrays.equals(configuration, that.configuration);
}
@Override
public int hashCode() {
return Objects.hash(this.name, this.configuration);
return Objects.hash(name, Arrays.hashCode(configuration));
}
@Override
public String toString() {
return new StringBuilder("FeignClientSpecification{").append("name='").append(this.name).append("', ")
.append("configuration=").append(Arrays.toString(this.configuration)).append("}").toString();
return new StringBuilder("FeignClientSpecification{").append("name='").append(name).append("', ")
.append("configuration=").append(Arrays.toString(configuration)).append("}").toString();
}
}

View File

@@ -106,7 +106,7 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ResourceLo
host = new URI(url).getHost();
}
catch (URISyntaxException e) {
catch (URISyntaxException ignored) {
}
Assert.state(host != null, "Service id not legal hostname (" + name + ")");
return name;
@@ -187,9 +187,8 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ResourceLo
}
for (BeanDefinition candidateComponent : candidateComponents) {
if (candidateComponent instanceof AnnotatedBeanDefinition) {
if (candidateComponent instanceof AnnotatedBeanDefinition beanDefinition) {
// verify annotated class is an interface
AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) candidateComponent;
AnnotationMetadata annotationMetadata = beanDefinition.getMetadata();
Assert.isTrue(annotationMetadata.isInterface(), "@FeignClient can only be specified on an interface");
@@ -204,6 +203,7 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ResourceLo
}
}
@SuppressWarnings("unchecked")
private void registerFeignClient(BeanDefinitionRegistry registry, AnnotationMetadata annotationMetadata,
Map<String, Object> attributes) {
String className = annotationMetadata.getClassName();

View File

@@ -51,7 +51,7 @@ public class OptionsFactoryBean implements FactoryBean<Request.Options>, Applica
}
@Override
public Request.Options getObject() throws Exception {
public Request.Options getObject() {
if (options != null) {
return options;
}

View File

@@ -26,8 +26,9 @@ import feign.Target;
*/
public class RefreshableHardCodedTarget<T> extends Target.HardCodedTarget<T> {
private RefreshableUrl refreshableUrl;
private final RefreshableUrl refreshableUrl;
@SuppressWarnings("unchecked")
public RefreshableHardCodedTarget(Class type, String name, RefreshableUrl refreshableUrl) {
super(type, name, refreshableUrl.getUrl());
this.refreshableUrl = refreshableUrl;

View File

@@ -50,7 +50,7 @@ public class RefreshableUrlFactoryBean implements FactoryBean<RefreshableUrl>, A
}
@Override
public RefreshableUrl getObject() throws Exception {
public RefreshableUrl getObject() {
if (refreshableUrl != null) {
return refreshableUrl;
}

View File

@@ -69,6 +69,7 @@ public class MatrixVariableParameterProcessor implements AnnotatedParameterProce
return true;
}
@SuppressWarnings("unchecked")
private String expandMap(Object object) {
Map<String, Object> paramMap = (Map) object;

View File

@@ -56,14 +56,14 @@ public class PathVariableParameterProcessor implements AnnotatedParameterProcess
MethodMetadata data = context.getMethodMetadata();
String varName = '{' + name + '}';
String varNameRegex = ".*\\{" + name + "(:[^}]+)?\\}.*";
if (!data.template().url().matches(varNameRegex) && !searchMapValues(data.template().queries(), varName)
&& !searchMapValues(data.template().headers(), varName)) {
if (!data.template().url().matches(varNameRegex) && !containsMapValues(data.template().queries(), varName)
&& !containsMapValues(data.template().headers(), varName)) {
data.formParams().add(name);
}
return true;
}
private <K, V> boolean searchMapValues(Map<K, Collection<V>> map, V search) {
private <K, V> boolean containsMapValues(Map<K, Collection<V>> map, V search) {
Collection<Collection<V>> values = map.values();
if (values == null) {
return false;

View File

@@ -19,7 +19,6 @@ package org.springframework.cloud.openfeign.clientconfig;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.concurrent.TimeUnit;
@@ -112,10 +111,7 @@ public class HttpClient5FeignConfiguration {
sslContext.init(null, new TrustManager[] { new DisabledValidationTrustManager() }, new SecureRandom());
sslConnectionSocketFactoryBuilder.setSslContext(sslContext);
}
catch (NoSuchAlgorithmException e) {
LOG.warn("Error creating SSLContext", e);
}
catch (KeyManagementException e) {
catch (NoSuchAlgorithmException | KeyManagementException e) {
LOG.warn("Error creating SSLContext", e);
}
}
@@ -131,10 +127,10 @@ public class HttpClient5FeignConfiguration {
DisabledValidationTrustManager() {
}
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) {
}
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {
}
public X509Certificate[] getAcceptedIssuers() {

View File

@@ -39,7 +39,7 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(FeignClientEncodingProperties.class)
@ConditionalOnClass(Feign.class)
@ConditionalOnBean(Client.class)
@ConditionalOnProperty(value = "spring.cloud.openfeign.compression.response.enabled", matchIfMissing = false)
@ConditionalOnProperty("spring.cloud.openfeign.compression.response.enabled")
// The OK HTTP client uses "transparent" compression.
// If the accept-encoding header is present it disable transparent compression
@ConditionalOnMissingBean(type = "okhttp3.OkHttpClient")

View File

@@ -40,7 +40,7 @@ public class FeignClientEncodingProperties {
private int minRequestSize = 2048;
public String[] getMimeTypes() {
return this.mimeTypes;
return mimeTypes;
}
public void setMimeTypes(String[] mimeTypes) {
@@ -48,7 +48,7 @@ public class FeignClientEncodingProperties {
}
public int getMinRequestSize() {
return this.minRequestSize;
return minRequestSize;
}
public void setMinRequestSize(int minRequestSize) {
@@ -64,20 +64,19 @@ public class FeignClientEncodingProperties {
return false;
}
FeignClientEncodingProperties that = (FeignClientEncodingProperties) o;
return Arrays.equals(this.mimeTypes, that.mimeTypes)
&& Objects.equals(this.minRequestSize, that.minRequestSize);
return Arrays.equals(mimeTypes, that.mimeTypes) && Objects.equals(minRequestSize, that.minRequestSize);
}
@Override
public int hashCode() {
return Objects.hash(this.mimeTypes, this.minRequestSize);
return Objects.hash(Arrays.hashCode(mimeTypes), minRequestSize);
}
@Override
public String toString() {
return new StringBuilder("FeignClientEncodingProperties{").append("mimeTypes=")
.append(Arrays.toString(this.mimeTypes)).append(", ").append("minRequestSize=")
.append(this.minRequestSize).append("}").toString();
.append(Arrays.toString(mimeTypes)).append(", ").append("minRequestSize=").append(minRequestSize)
.append("}").toString();
}
}

View File

@@ -144,8 +144,7 @@ public class RetryableFeignBlockingLoadBalancerClient implements Client {
new RetryableRequestContext(null, buildRequestData(request), hint));
// On retries the policy will choose the server and set it in the context
// and extract the server and update the request being made
if (context instanceof LoadBalancedRetryContext) {
LoadBalancedRetryContext lbContext = (LoadBalancedRetryContext) context;
if (context instanceof LoadBalancedRetryContext lbContext) {
ServiceInstance serviceInstance = lbContext.getServiceInstance();
if (serviceInstance == null) {
if (LOG.isDebugEnabled()) {

View File

@@ -74,8 +74,7 @@ public abstract class AbstractFormWriter extends AbstractWriter {
}
return false;
}
else if (object instanceof Iterable) {
Iterable<?> iterable = (Iterable<?>) object;
else if (object instanceof Iterable<?> iterable) {
Iterator<?> iterator = iterable.iterator();
return iterator.hasNext() && isType.test(iterator.next());

View File

@@ -79,8 +79,7 @@ public class PageableSpringEncoder implements Encoder {
public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException {
if (supports(object)) {
if (object instanceof Pageable) {
Pageable pageable = (Pageable) object;
if (object instanceof Pageable pageable) {
if (pageable.isPaged()) {
template.query(pageParameter, String.valueOf(pageable.getPageNumber()));
@@ -91,8 +90,7 @@ public class PageableSpringEncoder implements Encoder {
applySort(template, pageable.getSort());
}
}
else if (object instanceof Sort) {
Sort sort = (Sort) object;
else if (object instanceof Sort sort) {
applySort(template, sort);
}
}

View File

@@ -68,8 +68,7 @@ public class PageableSpringQueryMapEncoder extends BeanQueryMapEncoder {
if (supports(object)) {
Map<String, Object> queryMap = new HashMap<>();
if (object instanceof Pageable) {
Pageable pageable = (Pageable) object;
if (object instanceof Pageable pageable) {
if (pageable.isPaged()) {
queryMap.put(pageParameter, pageable.getPageNumber());
@@ -80,8 +79,7 @@ public class PageableSpringQueryMapEncoder extends BeanQueryMapEncoder {
applySort(queryMap, pageable.getSort());
}
}
else if (object instanceof Sort) {
Sort sort = (Sort) object;
else if (object instanceof Sort sort) {
applySort(queryMap, sort);
}
return queryMap;

View File

@@ -70,8 +70,7 @@ public class ResponseEntityDecoder implements Decoder {
}
private boolean isHttpEntity(Type type) {
if (type instanceof Class) {
Class c = (Class) type;
if (type instanceof Class c) {
return HttpEntity.class.isAssignableFrom(c);
}
return false;

View File

@@ -87,17 +87,17 @@ public class SpringDecoder implements Decoder {
}
@Override
public HttpStatus getStatusCode() throws IOException {
public HttpStatus getStatusCode() {
return HttpStatus.valueOf(response.status());
}
@Override
public int getRawStatusCode() throws IOException {
public int getRawStatusCode() {
return response.status();
}
@Override
public String getStatusText() throws IOException {
public String getStatusText() {
return response.reason();
}

View File

@@ -247,7 +247,7 @@ public class SpringEncoder implements Encoder {
}
@Override
public OutputStream getBody() throws IOException {
public OutputStream getBody() {
return outputStream;
}

View File

@@ -195,12 +195,12 @@ public class SpringMvcContract extends Contract.BaseContract implements Resource
@Override
protected void processAnnotationOnMethod(MethodMetadata data, Annotation methodAnnotation, Method method) {
if (CollectionFormat.class.isInstance(methodAnnotation)) {
if (methodAnnotation instanceof CollectionFormat) {
CollectionFormat collectionFormat = findMergedAnnotation(method, CollectionFormat.class);
data.template().collectionFormat(collectionFormat.value());
}
if (!RequestMapping.class.isInstance(methodAnnotation)
if (!(methodAnnotation instanceof RequestMapping)
&& !methodAnnotation.annotationType().isAnnotationPresent(RequestMapping.class)) {
return;
}

View File

@@ -79,7 +79,7 @@ class FeignClientBuilderTests {
@Test
void safetyCheckForNewFieldsOnTheFeignClientAnnotation() {
final List<String> methodNames = new ArrayList();
final List<String> methodNames = new ArrayList<>();
for (final Method method : FeignClient.class.getMethods()) {
methodNames.add(method.getName());
}
@@ -168,7 +168,7 @@ class FeignClientBuilderTests {
final FeignClientBuilder.Builder builder = this.feignClientBuilder.forType(TestClient.class, "TestClient");
// expect: 'the build will fail right after calling build() with the mocked
// unusual exception'
assertThatExceptionOfType(ClosedFileSystemException.class).isThrownBy(() -> builder.build());
assertThatExceptionOfType(ClosedFileSystemException.class).isThrownBy(builder::build);
}
private interface TestFeignClient {

View File

@@ -57,6 +57,7 @@ class FeignClientUsingConfigurerTest {
@Autowired
private FeignContext context;
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
void testFeignClient() {
FeignClientFactoryBean factoryBean = (FeignClientFactoryBean) beanFactory
@@ -80,6 +81,7 @@ class FeignClientUsingConfigurerTest {
return ReflectionUtils.getField(builderField, builder);
}
@SuppressWarnings("unchecked")
@Test
void testNoInheritFeignClient() {
FeignClientFactoryBean factoryBean = (FeignClientFactoryBean) beanFactory
@@ -96,6 +98,7 @@ class FeignClientUsingConfigurerTest {
.hasAtLeastOneElementOfType(MicrometerCapability.class);
}
@SuppressWarnings("unchecked")
@Test
void testNoInheritFeignClient_ignoreProperties() {
FeignClientFactoryBean factoryBean = (FeignClientFactoryBean) beanFactory

View File

@@ -122,8 +122,8 @@ public class FeignClientWithRefreshableOptionsTest {
private void assertConnectionAndReadTimeout(OptionsTestClient.OptionsResponseForTests options,
int expectedConnectTimeoutInMillis, int expectedReadTimeoutInMillis) {
assertThat(options.getConnectTimeout()).isEqualTo(expectedConnectTimeoutInMillis);
assertThat(options.getReadTimeout()).isEqualTo(expectedReadTimeoutInMillis);
assertThat(options.connectTimeout()).isEqualTo(expectedConnectTimeoutInMillis);
assertThat(options.readTimeout()).isEqualTo(expectedReadTimeoutInMillis);
}
@Configuration
@@ -171,7 +171,7 @@ public class FeignClientWithRefreshableOptionsTest {
}
@Configuration
protected class OverrideConfig {
protected static class OverrideConfig {
@Bean
public Request.Options options() {

View File

@@ -111,6 +111,7 @@ class FeignClientsRegistrarTests {
.doesNotThrowAnyException();
}
@SuppressWarnings("unchecked")
@Test
@DisabledForJreRange(min = JRE.JAVA_16)
void shouldResolveNullUrl() {

View File

@@ -76,6 +76,7 @@ class FeignHttpClientConfigurationTests {
}
}
@SuppressWarnings("unchecked")
private Lookup<ConnectionSocketFactory> getConnectionSocketFactoryLookup(
HttpClientConnectionManager connectionManager) {
DefaultHttpClientConnectionOperator connectionOperator = (DefaultHttpClientConnectionOperator) this
@@ -84,8 +85,7 @@ class FeignHttpClientConfigurationTests {
}
private X509TrustManager getX509TrustManager(Lookup<ConnectionSocketFactory> socketFactoryRegistry) {
ConnectionSocketFactory connectionSocketFactory = (ConnectionSocketFactory) socketFactoryRegistry
.lookup("https");
ConnectionSocketFactory connectionSocketFactory = socketFactoryRegistry.lookup("https");
SSLSocketFactory sslSocketFactory = (SSLSocketFactory) this.getField(connectionSocketFactory, "socketfactory");
SSLContextSpi sslContext = (SSLContextSpi) this.getField(sslSocketFactory, "context");
return (X509TrustManager) this.getField(sslContext, "trustManager");
@@ -94,8 +94,7 @@ class FeignHttpClientConfigurationTests {
protected <T> Object getField(Object target, String name) {
Field field = ReflectionUtils.findField(target.getClass(), name);
ReflectionUtils.makeAccessible(field);
Object value = ReflectionUtils.getField(field, target);
return value;
return ReflectionUtils.getField(field, target);
}
}

View File

@@ -47,12 +47,12 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
* @author Spencer Gibb
* @author Olga Maciaszek-Sharma
*/
@SpringBootTest(classes = FeignHttpClientUrlTestsWithRetryableLoadBalancer.TestConfig.class,
@SpringBootTest(classes = FeignHttpClientUrlWithRetryableLoadBalancerTests.TestConfig.class,
webEnvironment = DEFINED_PORT,
value = { "spring.application.name=feignclienturlwithretryableloadbalancertest",
"spring.cloud.openfeign.hystrix.enabled=false", "spring.cloud.openfeign.okhttp.enabled=false" })
@DirtiesContext
class FeignHttpClientUrlTestsWithRetryableLoadBalancer {
class FeignHttpClientUrlWithRetryableLoadBalancerTests {
static int port;

View File

@@ -75,8 +75,7 @@ class FeignOkHttpConfigurationTests {
protected Object getField(Object target, String name) {
Field field = ReflectionUtils.findField(target.getClass(), name);
ReflectionUtils.makeAccessible(field);
Object value = ReflectionUtils.getField(field, target);
return value;
return ReflectionUtils.getField(field, target);
}
}

View File

@@ -16,7 +16,6 @@
package org.springframework.cloud.openfeign;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
@@ -44,7 +43,7 @@ public class OptionsTestClient implements Client {
}
@Override
public Response execute(Request request, Request.Options options) throws IOException {
public Response execute(Request request, Request.Options options) {
return Response.builder().status(200).request(request).headers(headers()).body(prepareResponse(options))
.build();
}
@@ -67,39 +66,8 @@ public class OptionsTestClient implements Client {
}
}
static class OptionsResponseForTests {
private final long connectTimeout;
private final TimeUnit connectTimeoutUnit;
private final long readTimeout;
private final TimeUnit readTimeoutUnit;
OptionsResponseForTests(long connectTimeout, TimeUnit connectTimeoutUnit, long readTimeout,
TimeUnit readTimeoutUnit) {
this.connectTimeout = connectTimeout;
this.connectTimeoutUnit = connectTimeoutUnit;
this.readTimeout = readTimeout;
this.readTimeoutUnit = readTimeoutUnit;
}
public long getConnectTimeout() {
return connectTimeout;
}
public TimeUnit getConnectTimeoutUnit() {
return connectTimeoutUnit;
}
public long getReadTimeout() {
return readTimeout;
}
public TimeUnit getReadTimeoutUnit() {
return readTimeoutUnit;
}
record OptionsResponseForTests(long connectTimeout, TimeUnit connectTimeoutUnit, long readTimeout,
TimeUnit readTimeoutUnit) {
@Override
public String toString() {

View File

@@ -254,7 +254,7 @@ class SpringDecoderTests extends FeignClientFactoryBean {
@Override
public ResponseEntity<String> getNotFound() {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body((String) null);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
@Override

View File

@@ -16,7 +16,6 @@
package org.springframework.cloud.openfeign;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
@@ -43,7 +42,7 @@ public class UrlTestClient implements Client {
}
@Override
public Response execute(Request request, Request.Options options) throws IOException {
public Response execute(Request request, Request.Options options) {
return Response.builder().status(200).request(request).headers(headers()).body(prepareResponse(request))
.build();
}

View File

@@ -117,7 +117,7 @@ class AsyncCircuitBreakerTests {
@Bean
CircuitBreakerFactory<Duration, ConfigBuilder<Duration>> circuitBreakerFactory(
@Qualifier("asyncWorker") ExecutorService asyncCircuitBreakerExecutor) {
return new CircuitBreakerFactory<Duration, ConfigBuilder<Duration>>() {
return new CircuitBreakerFactory<>() {
Function<String, Duration> defaultConfiguration = id -> Duration.ofMillis(1000);

View File

@@ -44,6 +44,7 @@ public class CircuitBreakerAutoConfigurationTests {
@Autowired
CircuitBreakerNameResolver nameResolver;
@SuppressWarnings("rawtypes")
@Test
public void assertDefaultNamingStrategy() throws Exception {
Target target = mock(Target.class);
@@ -65,6 +66,7 @@ public class CircuitBreakerAutoConfigurationTests {
@Autowired
CircuitBreakerNameResolver nameResolver;
@SuppressWarnings("rawtypes")
@Test
public void assertAlphanumericNamingStrategy() throws Exception {
Target target = mock(Target.class);

View File

@@ -232,6 +232,7 @@ class CircuitBreakerTests {
return new MyCircuitBreaker();
}
@SuppressWarnings("rawtypes")
@Bean
CircuitBreakerFactory circuitBreakerFactory(MyCircuitBreaker myCircuitBreaker) {
return new CircuitBreakerFactory() {

View File

@@ -118,6 +118,7 @@ public class CircuitBreakerWithNoFallbackTests {
return new MyCircuitBreaker();
}
@SuppressWarnings("rawtypes")
@Bean
CircuitBreakerFactory circuitBreakerFactory(MyCircuitBreaker myCircuitBreaker) {
return new CircuitBreakerFactory() {

View File

@@ -27,8 +27,14 @@ public final class ProtobufTest {
private static com.google.protobuf.Descriptors.FileDescriptor descriptor;
static {
String[] descriptorData = { "\n\023protobuf_test.proto\"\"\n\007Request\022\n\n\002id\030\001"
+ " \001(\005\022\013\n\003msg\030\002 \001(\tB\024\n\020feign.httpclientP\001b" + "\006proto3" };
String[] descriptorData = { """
\023protobuf_test.proto""
\007Request\022
\002id\030\001 \001(\005\022\013
\003msg\030\002 \001(\tB\024
\020feign.httpclientP\001b\006proto3""" };
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
public com.google.protobuf.ExtensionRegistry assignDescriptors(
com.google.protobuf.Descriptors.FileDescriptor root) {

View File

@@ -35,7 +35,7 @@ public final class Request extends com.google.protobuf.GeneratedMessageV3 implem
// @@protoc_insertion_point(class_scope:Request)
private static final Request DEFAULT_INSTANCE;
private static final com.google.protobuf.Parser<Request> PARSER = new com.google.protobuf.AbstractParser<Request>() {
private static final com.google.protobuf.Parser<Request> PARSER = new com.google.protobuf.AbstractParser<>() {
public Request parsePartialFrom(com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
@@ -275,10 +275,9 @@ public final class Request extends com.google.protobuf.GeneratedMessageV3 implem
if (obj == this) {
return true;
}
if (!(obj instanceof Request)) {
if (!(obj instanceof Request other)) {
return super.equals(obj);
}
Request other = (Request) obj;
boolean result = true;
result = result && (getId() == other.getId());
@@ -313,8 +312,7 @@ public final class Request extends com.google.protobuf.GeneratedMessageV3 implem
@Override
protected Builder newBuilderForType(BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
return new Builder(parent);
}
@Override

View File

@@ -16,8 +16,6 @@
package org.springframework.cloud.openfeign.support;
import java.io.IOException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -43,7 +41,7 @@ class AbstractFormWriterTests {
Assertions.assertFalse(formWriter.isApplicable(object));
}
class MockFormWriter extends AbstractFormWriter {
static class MockFormWriter extends AbstractFormWriter {
@Override
protected MediaType getContentType() {
@@ -51,13 +49,13 @@ class AbstractFormWriterTests {
}
@Override
protected String writeAsString(Object object) throws IOException {
protected String writeAsString(Object object) {
return null;
}
}
class UserPojo {
static class UserPojo {
}

View File

@@ -116,7 +116,7 @@ class SpringEncoderTests {
assertThat(encoder).isNotNull();
RequestTemplate request = new RequestTemplate();
ParameterizedTypeReference<List<String>> stringListType = new ParameterizedTypeReference<List<String>>() {
ParameterizedTypeReference<List<String>> stringListType = new ParameterizedTypeReference<>() {
};
request.header(HttpEncoding.CONTENT_TYPE, "application/mygenerictype");
@@ -305,8 +305,7 @@ class SpringEncoderTests {
}
private boolean isStringList(Type type) {
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
if (type instanceof ParameterizedType parameterizedType) {
return parameterizedType.getRawType() == List.class
&& parameterizedType.getActualTypeArguments()[0] == String.class;
}

View File

@@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import feign.MethodMetadata;
@@ -115,7 +116,7 @@ class SpringMvcContractTests {
Method isNamePresent = ReflectionUtils.findMethod(parameters[0].getClass(), "isNamePresent");
return Boolean.TRUE.equals(isNamePresent.invoke(parameters[0]));
}
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) {
}
}
return false;
@@ -827,7 +828,7 @@ class SpringMvcContractTests {
}
@JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE)
public class TestObject {
public static class TestObject {
public String something;
@@ -852,10 +853,10 @@ class SpringMvcContractTests {
TestObject that = (TestObject) o;
if (number != null ? !number.equals(that.number) : that.number != null) {
if (!Objects.equals(number, that.number)) {
return false;
}
if (something != null ? !something.equals(that.something) : that.something != null) {
if (!Objects.equals(something, that.something)) {
return false;
}

View File

@@ -90,13 +90,14 @@ class ApacheHttpClientConfigurationTests {
@Test
void testHttpClientWithFeign() {
Client delegate = feignClient.getDelegate();
assertThat(ApacheHttpClient.class.isInstance(delegate)).isTrue();
assertThat(delegate instanceof ApacheHttpClient).isTrue();
ApacheHttpClient apacheHttpClient = (ApacheHttpClient) delegate;
HttpClient httpClient = getField(apacheHttpClient, "client");
MockingDetails httpClientDetails = mockingDetails(httpClient);
assertThat(httpClientDetails.isMock()).isTrue();
}
@SuppressWarnings("unchecked")
protected <T> T getField(Object target, String name) {
Field field = ReflectionUtils.findField(target.getClass(), name);
ReflectionUtils.makeAccessible(field);

View File

@@ -72,13 +72,14 @@ class OkHttpClientConfigurationTests {
@Test
void testHttpClientWithFeign() {
Client delegate = feignClient.getDelegate();
assertThat(feign.okhttp.OkHttpClient.class.isInstance(delegate)).isTrue();
assertThat(delegate instanceof feign.okhttp.OkHttpClient).isTrue();
feign.okhttp.OkHttpClient okHttpClient = (feign.okhttp.OkHttpClient) delegate;
OkHttpClient httpClient = getField(okHttpClient, "delegate");
MockingDetails httpClientDetails = mockingDetails(httpClient);
assertThat(httpClientDetails.isMock()).isTrue();
}
@SuppressWarnings("unchecked")
protected <T> T getField(Object target, String name) {
Object value = ReflectionTestUtils.getField(target, target.getClass(), name);
return (T) value;

View File

@@ -18,7 +18,6 @@ package org.springframework.cloud.openfeign.valid;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.text.ParseException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
@@ -573,7 +572,7 @@ class ValidFeignClientTests {
}
@Override
public OtherArg parse(String text, Locale locale) throws ParseException {
public OtherArg parse(String text, Locale locale) {
return new OtherArg(text);
}
});