use of org.springframework.expression.PropertyAccessor in project spring-framework by spring-projects.
the class PropertyAccessTests method addingAndRemovingAccessors.
@Test
void addingAndRemovingAccessors() {
StandardEvaluationContext ctx = new StandardEvaluationContext();
// reflective property accessor is the only one by default
assertThat(ctx.getPropertyAccessors()).hasSize(1);
StringyPropertyAccessor spa = new StringyPropertyAccessor();
ctx.addPropertyAccessor(spa);
assertThat(ctx.getPropertyAccessors()).hasSize(2);
List<PropertyAccessor> copy = new ArrayList<>(ctx.getPropertyAccessors());
assertThat(ctx.removePropertyAccessor(spa)).isTrue();
assertThat(ctx.removePropertyAccessor(spa)).isFalse();
assertThat(ctx.getPropertyAccessors()).hasSize(1);
ctx.setPropertyAccessors(copy);
assertThat(ctx.getPropertyAccessors()).hasSize(2);
}
use of org.springframework.expression.PropertyAccessor in project spring-framework by spring-projects.
the class SpelReproTests method propertyAccessOnNullTarget_SPR5663.
@Test
void propertyAccessOnNullTarget_SPR5663() throws AccessException {
PropertyAccessor accessor = new ReflectivePropertyAccessor();
EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
assertThat(accessor.canRead(context, null, "abc")).isFalse();
assertThat(accessor.canWrite(context, null, "abc")).isFalse();
assertThatIllegalStateException().isThrownBy(() -> accessor.read(context, null, "abc"));
assertThatIllegalStateException().isThrownBy(() -> accessor.write(context, null, "abc", "foo"));
}
Aggregations