Ensure MapAccessor#canWrite only returns true for a Map target
Closes gh-33265
This commit is contained in:
@@ -81,6 +81,22 @@ class MapAccessorTests {
|
||||
assertThat(ex.getValue(sec, testMap)).isEqualTo("bar2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void canWrite() throws Exception {
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
Map<String, Object> testMap = getSimpleTestMap();
|
||||
|
||||
MapAccessor mapAccessor = new MapAccessor();
|
||||
assertThat(mapAccessor.canWrite(context, new Object(), "foo")).isFalse();
|
||||
assertThat(mapAccessor.canWrite(context, testMap, "foo")).isTrue();
|
||||
// Cannot actually write to an immutable Map, but MapAccessor cannot easily check for that.
|
||||
assertThat(mapAccessor.canWrite(context, Map.of(), "x")).isTrue();
|
||||
|
||||
mapAccessor = new MapAccessor(false);
|
||||
assertThat(mapAccessor.canWrite(context, new Object(), "foo")).isFalse();
|
||||
assertThat(mapAccessor.canWrite(context, testMap, "foo")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void isWritable() {
|
||||
Map<String, Object> testMap = getSimpleTestMap();
|
||||
|
||||
Reference in New Issue
Block a user