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
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -27,7 +27,6 @@ import org.springframework.test.context.ContextCustomizer;
|
||||
import org.springframework.test.context.ContextCustomizerFactory;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.ReflectionUtils.MethodCallback;
|
||||
|
||||
/**
|
||||
* {@link ContextCustomizerFactory} to allow {@code @Import} annotations to be used
|
||||
@@ -49,16 +48,12 @@ class ImportsContextCustomizerFactory implements ContextCustomizerFactory {
|
||||
}
|
||||
|
||||
private void assertHasNoBeanMethods(Class<?> testClass) {
|
||||
ReflectionUtils.doWithMethods(testClass, new MethodCallback() {
|
||||
|
||||
@Override
|
||||
public void doWith(Method method) {
|
||||
Assert.state(!AnnotatedElementUtils.isAnnotated(method, Bean.class),
|
||||
"Test classes cannot include @Bean methods");
|
||||
}
|
||||
|
||||
});
|
||||
ReflectionUtils.doWithMethods(testClass, this::assertHasNoBeanMethods);
|
||||
}
|
||||
|
||||
private void assertHasNoBeanMethods(Method method) {
|
||||
Assert.state(!AnnotatedElementUtils.isAnnotated(method, Bean.class),
|
||||
"Test classes cannot include @Bean methods");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import java.lang.reflect.Field;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
@@ -38,7 +37,6 @@ import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.ReflectionUtils.FieldCallback;
|
||||
|
||||
/**
|
||||
* Base class for AssertJ based JSON marshal testers. Exposes specific Asserts following a
|
||||
@@ -370,29 +368,15 @@ public abstract class AbstractJsonMarshalTester<T> {
|
||||
public void initFields(final Object testInstance, final M marshaller) {
|
||||
Assert.notNull(testInstance, "TestInstance must not be null");
|
||||
Assert.notNull(marshaller, "Marshaller must not be null");
|
||||
initFields(testInstance, new ObjectFactory<M>() {
|
||||
|
||||
@Override
|
||||
public M getObject() throws BeansException {
|
||||
return marshaller;
|
||||
}
|
||||
|
||||
});
|
||||
initFields(testInstance, () -> marshaller);
|
||||
}
|
||||
|
||||
public void initFields(final Object testInstance,
|
||||
final ObjectFactory<M> marshaller) {
|
||||
Assert.notNull(testInstance, "TestInstance must not be null");
|
||||
Assert.notNull(marshaller, "Marshaller must not be null");
|
||||
ReflectionUtils.doWithFields(testInstance.getClass(), new FieldCallback() {
|
||||
|
||||
@Override
|
||||
public void doWith(Field field)
|
||||
throws IllegalArgumentException, IllegalAccessException {
|
||||
doWithField(field, testInstance, marshaller);
|
||||
}
|
||||
|
||||
});
|
||||
ReflectionUtils.doWithFields(testInstance.getClass(),
|
||||
(field) -> doWithField(field, testInstance, marshaller));
|
||||
}
|
||||
|
||||
protected void doWithField(Field field, Object test,
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.ReflectionUtils.FieldCallback;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -60,15 +59,7 @@ class DefinitionsParser {
|
||||
|
||||
public void parse(Class<?> source) {
|
||||
parseElement(source);
|
||||
ReflectionUtils.doWithFields(source, new FieldCallback() {
|
||||
|
||||
@Override
|
||||
public void doWith(Field field)
|
||||
throws IllegalArgumentException, IllegalAccessException {
|
||||
parseElement(field);
|
||||
}
|
||||
|
||||
});
|
||||
ReflectionUtils.doWithFields(source, this::parseElement);
|
||||
}
|
||||
|
||||
private void parseElement(AnnotatedElement element) {
|
||||
|
||||
@@ -61,7 +61,6 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.ReflectionUtils.FieldCallback;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -371,15 +370,8 @@ public class MockitoPostProcessor extends InstantiationAwareBeanPostProcessorAda
|
||||
public PropertyValues postProcessPropertyValues(PropertyValues pvs,
|
||||
PropertyDescriptor[] pds, final Object bean, String beanName)
|
||||
throws BeansException {
|
||||
ReflectionUtils.doWithFields(bean.getClass(), new FieldCallback() {
|
||||
|
||||
@Override
|
||||
public void doWith(Field field)
|
||||
throws IllegalArgumentException, IllegalAccessException {
|
||||
postProcessField(bean, field);
|
||||
}
|
||||
|
||||
});
|
||||
ReflectionUtils.doWithFields(bean.getClass(),
|
||||
(field) -> postProcessField(bean, field));
|
||||
return pvs;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user