Polish contribution

See gh-23658
This commit is contained in:
Sam Brannen 2019-09-19 22:00:57 +02:00
parent fde7b1e545
commit 734ceed301
2 changed files with 13 additions and 24 deletions

View File

@ -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 {
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 {

View File

@ -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()));
}
}