Add support for making MapAccessor read-only

See gh-33222
This commit is contained in:
Yanming Zhou
2024-07-17 10:29:21 +08:00
committed by Stéphane Nicoll
parent ec383f69f2
commit a0e43b1f46
2 changed files with 33 additions and 2 deletions

View File

@@ -32,6 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link MapAccessor}.
*
* @author Andy Clement
* @author Yanming Zhou
*/
class MapAccessorTests {
@@ -80,6 +81,16 @@ class MapAccessorTests {
assertThat(ex.getValue(sec,testMap)).isEqualTo("bar2");
}
@Test
void mapAccessorNotWritable() {
Map<String, Object> testMap = getSimpleTestMap();
StandardEvaluationContext sec = new StandardEvaluationContext();
sec.addPropertyAccessor(new MapAccessor(false));
SpelExpressionParser sep = new SpelExpressionParser();
Expression ex = sep.parseExpression("foo");
assertThat(ex.isWritable(sec, testMap)).isFalse();
}
public static class MapGetter {
Map<String,Object> map = new HashMap<>();