Use lambdas when possible
Replace anonymous inner classes with lambda declarations (when possible using method references). See gh-9781
This commit is contained in:
committed by
Phillip Webb
parent
d16af43664
commit
2626a3a795
@@ -43,7 +43,6 @@ import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.ReflectionUtils.FieldCallback;
|
||||
|
||||
/**
|
||||
* Auto-configuration for Json testers.
|
||||
@@ -150,18 +149,10 @@ public class JsonTestersAutoConfiguration {
|
||||
extends InstantiationAwareBeanPostProcessorAdapter {
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(final Object bean, String beanName)
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
|
||||
ReflectionUtils.doWithFields(bean.getClass(), new FieldCallback() {
|
||||
|
||||
@Override
|
||||
public void doWith(Field field)
|
||||
throws IllegalArgumentException, IllegalAccessException {
|
||||
processField(bean, field);
|
||||
}
|
||||
|
||||
});
|
||||
ReflectionUtils.doWithFields(bean.getClass(),
|
||||
(field) -> processField(bean, field));
|
||||
return bean;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.test.autoconfigure.web.reactive;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
@@ -26,6 +27,7 @@ import org.springframework.boot.web.codec.CodecCustomizer;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.codec.ClientCodecConfigurer;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.reactive.function.client.ExchangeStrategies;
|
||||
@@ -53,14 +55,18 @@ public class WebTestClientAutoConfiguration {
|
||||
|
||||
private void customizeWebTestClientCodecs(WebTestClient.Builder builder,
|
||||
ApplicationContext applicationContext) {
|
||||
Collection<CodecCustomizer> codecCustomizers = applicationContext
|
||||
Collection<CodecCustomizer> customizers = applicationContext
|
||||
.getBeansOfType(CodecCustomizer.class).values();
|
||||
if (!CollectionUtils.isEmpty(codecCustomizers)) {
|
||||
builder.exchangeStrategies(ExchangeStrategies.builder().codecs((codecs) -> {
|
||||
codecCustomizers
|
||||
.forEach((codecCustomizer) -> codecCustomizer.customize(codecs));
|
||||
}).build());
|
||||
if (!CollectionUtils.isEmpty(customizers)) {
|
||||
builder.exchangeStrategies(ExchangeStrategies.builder()
|
||||
.codecs(applyCustomizers(customizers)).build());
|
||||
}
|
||||
}
|
||||
|
||||
private Consumer<ClientCodecConfigurer> applyCustomizers(
|
||||
Collection<CodecCustomizer> customizers) {
|
||||
return (codecs) -> customizers
|
||||
.forEach((customizer) -> customizer.customize(codecs));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,10 +21,8 @@ import java.util.Map;
|
||||
|
||||
import org.openqa.selenium.WebDriver;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.config.Scope;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -116,24 +114,20 @@ class WebDriverScope implements Scope {
|
||||
if (beanFactory.getRegisteredScope(NAME) == null) {
|
||||
beanFactory.registerScope(NAME, new WebDriverScope());
|
||||
}
|
||||
context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
|
||||
context.addBeanFactoryPostProcessor(WebDriverScope::postProcessBeanFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessBeanFactory(
|
||||
ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
for (String beanClass : BEAN_CLASSES) {
|
||||
for (String beanName : beanFactory.getBeanNamesForType(
|
||||
ClassUtils.resolveClassName(beanClass, null))) {
|
||||
BeanDefinition definition = beanFactory
|
||||
.getBeanDefinition(beanName);
|
||||
if (!StringUtils.hasLength(definition.getScope())) {
|
||||
definition.setScope(NAME);
|
||||
}
|
||||
}
|
||||
private static void postProcessBeanFactory(
|
||||
ConfigurableListableBeanFactory beanFactory) {
|
||||
for (String beanClass : BEAN_CLASSES) {
|
||||
for (String beanName : beanFactory
|
||||
.getBeanNamesForType(ClassUtils.resolveClassName(beanClass, null))) {
|
||||
BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
|
||||
if (!StringUtils.hasLength(definition.getScope())) {
|
||||
definition.setScope(NAME);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user