Browse Source

Polish contribution

See gh-23658
pull/23676/head
Sam Brannen 6 years ago
parent
commit
734ceed301
  1. 14
      spring-expression/src/test/java/org/springframework/expression/spel/PropertyAccessTests.java
  2. 23
      spring-expression/src/test/java/org/springframework/expression/spel/ast/IndexerTests.java

14
spring-expression/src/test/java/org/springframework/expression/spel/PropertyAccessTests.java

@ -34,16 +34,19 @@ import org.springframework.expression.spel.standard.SpelExpression; @@ -34,16 +34,19 @@ 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.support.StandardEvaluationContext;
import org.springframework.expression.spel.testresources.Inventor;
import org.springframework.expression.spel.testresources.Person;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests accessing of properties.
* Unit tests for property access.
*
* @author Andy Clement
* @author Juergen Hoeller
* @author Joyce Zhan
* @author Sam Brannen
*/
public class PropertyAccessTests extends AbstractExpressionTests {
@ -254,6 +257,15 @@ public class PropertyAccessTests extends AbstractExpressionTests { @@ -254,6 +257,15 @@ public class PropertyAccessTests extends AbstractExpressionTests {
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...)
private static class StringyPropertyAccessor implements PropertyAccessor {

23
spring-expression/src/test/java/org/springframework/expression/spel/ast/IndexerTests.java

@ -1,23 +0,0 @@ @@ -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…
Cancel
Save