Polishing

This commit is contained in:
Sam Brannen 2019-09-12 13:16:48 +02:00
parent e124cbb310
commit 2b460854ce
1 changed files with 5 additions and 14 deletions

View File

@ -120,16 +120,14 @@ public class MethodInvocationTests extends AbstractExpressionTests {
// Now cause it to throw an exception: // Now cause it to throw an exception:
eContext.setVariable("bar", 1); eContext.setVariable("bar", 1);
assertThatExceptionOfType(Exception.class).isThrownBy(() -> assertThatExceptionOfType(Exception.class).isThrownBy(() -> expr.getValue(eContext))
expr.getValue(eContext))
.isNotInstanceOf(SpelEvaluationException.class); .isNotInstanceOf(SpelEvaluationException.class);
// If counter is 4 then the method got called twice! // If counter is 4 then the method got called twice!
assertThat(parser.parseExpression("counter").getValue(eContext)).isEqualTo(3); assertThat(parser.parseExpression("counter").getValue(eContext)).isEqualTo(3);
eContext.setVariable("bar", 4); eContext.setVariable("bar", 4);
assertThatExceptionOfType(ExpressionInvocationTargetException.class).isThrownBy(() -> assertThatExceptionOfType(ExpressionInvocationTargetException.class).isThrownBy(() -> expr.getValue(eContext));
expr.getValue(eContext));
// If counter is 5 then the method got called twice! // If counter is 5 then the method got called twice!
assertThat(parser.parseExpression("counter").getValue(eContext)).isEqualTo(4); assertThat(parser.parseExpression("counter").getValue(eContext)).isEqualTo(4);
@ -150,8 +148,7 @@ public class MethodInvocationTests extends AbstractExpressionTests {
Expression expr = parser.parseExpression("throwException(#bar)"); Expression expr = parser.parseExpression("throwException(#bar)");
context.setVariable("bar", 2); context.setVariable("bar", 2);
assertThatExceptionOfType(Exception.class).isThrownBy(() -> assertThatExceptionOfType(Exception.class).isThrownBy(() -> expr.getValue(context))
expr.getValue(context))
.satisfies(ex -> assertThat(ex).isNotInstanceOf(SpelEvaluationException.class)); .satisfies(ex -> assertThat(ex).isNotInstanceOf(SpelEvaluationException.class));
} }
@ -167,8 +164,7 @@ public class MethodInvocationTests extends AbstractExpressionTests {
Expression expr = parser.parseExpression("throwException(#bar)"); Expression expr = parser.parseExpression("throwException(#bar)");
context.setVariable("bar", 4); context.setVariable("bar", 4);
assertThatExceptionOfType(ExpressionInvocationTargetException.class).isThrownBy(() -> assertThatExceptionOfType(ExpressionInvocationTargetException.class).isThrownBy(() -> expr.getValue(context))
expr.getValue(context))
.satisfies(ex -> assertThat(ex.getCause().getClass().getName()).isEqualTo( .satisfies(ex -> assertThat(ex.getCause().getClass().getName()).isEqualTo(
"org.springframework.expression.spel.testresources.Inventor$TestException")); "org.springframework.expression.spel.testresources.Inventor$TestException"));
} }
@ -276,12 +272,7 @@ 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((context1, beanName) -> { context.setBeanResolver((context1, beanName) -> ("service".equals(beanName) ? service : null));
if ("service".equals(beanName)) {
return service;
}
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);
assertThat(outBytes).isSameAs(bytes); assertThat(outBytes).isSameAs(bytes);