Optimize test code with lambdas where feasible
This commit optimizes test code with lambda expressions and method references where feasible. Closes gh-23626
This commit is contained in:
parent
00c07e3a50
commit
40fcf876ce
|
|
@ -277,14 +277,11 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||||
final BytesService service = new BytesService();
|
final BytesService service = new BytesService();
|
||||||
byte[] bytes = new byte[100];
|
byte[] bytes = new byte[100];
|
||||||
StandardEvaluationContext context = new StandardEvaluationContext(bytes);
|
StandardEvaluationContext context = new StandardEvaluationContext(bytes);
|
||||||
context.setBeanResolver(new BeanResolver() {
|
context.setBeanResolver((context1, beanName) -> {
|
||||||
@Override
|
|
||||||
public Object resolve(EvaluationContext context, String beanName) throws AccessException {
|
|
||||||
if ("service".equals(beanName)) {
|
if ("service".equals(beanName)) {
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
Expression expression = parser.parseExpression("@service.handleBytes(#root)");
|
Expression expression = parser.parseExpression("@service.handleBytes(#root)");
|
||||||
byte[] outBytes = expression.getValue(context, byte[].class);
|
byte[] outBytes = expression.getValue(context, byte[].class);
|
||||||
|
|
|
||||||
|
|
@ -5156,8 +5156,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertGetValueFail(Expression expression) {
|
private void assertGetValueFail(Expression expression) {
|
||||||
assertThatExceptionOfType(Exception.class).isThrownBy(() ->
|
assertThatExceptionOfType(Exception.class).isThrownBy(expression::getValue);
|
||||||
expression.getValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertIsCompiled(Expression expression) {
|
private void assertIsCompiled(Expression expression) {
|
||||||
|
|
|
||||||
|
|
@ -1326,10 +1326,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||||
@Override
|
@Override
|
||||||
public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name,
|
public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name,
|
||||||
List<TypeDescriptor> argumentTypes) throws AccessException {
|
List<TypeDescriptor> argumentTypes) throws AccessException {
|
||||||
return new MethodExecutor() {
|
return (context1, target, arguments) -> {
|
||||||
@Override
|
|
||||||
public TypedValue execute(EvaluationContext context, Object target, Object... arguments)
|
|
||||||
throws AccessException {
|
|
||||||
try {
|
try {
|
||||||
Method method = XYZ.class.getMethod("values");
|
Method method = XYZ.class.getMethod("values");
|
||||||
Object value = method.invoke(target, arguments);
|
Object value = method.invoke(target, arguments);
|
||||||
|
|
@ -1338,7 +1335,6 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new AccessException(ex.getMessage(), ex);
|
throw new AccessException(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -345,8 +345,7 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
|
||||||
assertThat(property.read(ctx, tester, "property").getValue()).isEqualTo("hello");
|
assertThat(property.read(ctx, tester, "property").getValue()).isEqualTo("hello");
|
||||||
// cached accessor used
|
// cached accessor used
|
||||||
assertThat(property.read(ctx, tester, "property").getValue()).isEqualTo("hello");
|
assertThat(property.read(ctx, tester, "property").getValue()).isEqualTo("hello");
|
||||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(property::getSpecificTargetClasses);
|
||||||
property.getSpecificTargetClasses());
|
|
||||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
||||||
property.write(ctx, tester, "property", null));
|
property.write(ctx, tester, "property", null));
|
||||||
|
|
||||||
|
|
@ -360,8 +359,7 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
|
||||||
assertThat(field.read(ctx, tester, "field").getValue()).isEqualTo(3);
|
assertThat(field.read(ctx, tester, "field").getValue()).isEqualTo(3);
|
||||||
// cached accessor used
|
// cached accessor used
|
||||||
assertThat(field.read(ctx, tester, "field").getValue()).isEqualTo(3);
|
assertThat(field.read(ctx, tester, "field").getValue()).isEqualTo(3);
|
||||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(field::getSpecificTargetClasses);
|
||||||
field.getSpecificTargetClasses());
|
|
||||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
||||||
field.write(ctx, tester, "field", null));
|
field.write(ctx, tester, "field", null));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue