parent
fde7b1e545
commit
734ceed301
|
|
@ -34,16 +34,19 @@ import org.springframework.expression.spel.standard.SpelExpression;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
import org.springframework.expression.spel.support.SimpleEvaluationContext;
|
import org.springframework.expression.spel.support.SimpleEvaluationContext;
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
|
import org.springframework.expression.spel.testresources.Inventor;
|
||||||
import org.springframework.expression.spel.testresources.Person;
|
import org.springframework.expression.spel.testresources.Person;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests accessing of properties.
|
* Unit tests for property access.
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Joyce Zhan
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class PropertyAccessTests extends AbstractExpressionTests {
|
public class PropertyAccessTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
|
|
@ -254,6 +257,15 @@ public class PropertyAccessTests extends AbstractExpressionTests {
|
||||||
assertThat(context.getRootObject().getTypeDescriptor().getType()).isSameAs(Object.class);
|
assertThat(context.getRootObject().getTypeDescriptor().getType()).isSameAs(Object.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void propertyAccessWithArrayIndexOutOfBounds() {
|
||||||
|
EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
|
||||||
|
Expression expression = parser.parseExpression("stringArrayOfThreeItems[3]");
|
||||||
|
assertThatExceptionOfType(SpelEvaluationException.class)
|
||||||
|
.isThrownBy(() -> expression.getValue(context, new Inventor()))
|
||||||
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.ARRAY_INDEX_OUT_OF_BOUNDS));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// This can resolve the property 'flibbles' on any String (very useful...)
|
// This can resolve the property 'flibbles' on any String (very useful...)
|
||||||
private static class StringyPropertyAccessor implements PropertyAccessor {
|
private static class StringyPropertyAccessor implements PropertyAccessor {
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
package org.springframework.expression.spel.ast;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.expression.EvaluationException;
|
|
||||||
import org.springframework.expression.spel.standard.SpelExpression;
|
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
|
||||||
import org.springframework.expression.spel.support.SimpleEvaluationContext;
|
|
||||||
import org.springframework.expression.spel.testresources.Inventor;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Joyce Zhan
|
|
||||||
*/
|
|
||||||
public class IndexerTests {
|
|
||||||
@Test
|
|
||||||
public void testAccess() {
|
|
||||||
SimpleEvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
|
|
||||||
SpelExpression expression = (SpelExpression) new SpelExpressionParser().parseExpression("stringArrayOfThreeItems[3]");
|
|
||||||
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() ->
|
|
||||||
expression.getValue(context, new Inventor()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue