### Question:
ReflectivePropertyAccessor implements PropertyAccessor { @Override public void write(final EvaluationContext context, final Object target, final String name, final Object newValue) throws AccessException { Objects.requireNonNull(target, "target cannot be null"); Objects.requireNonNull(name, "name cannot be null"); Class<?> type = target instanceof Class ? (Class<?>) target : target.getClass(); try { Method method = findSetterMethodForProperty(type, name); if (method != null ) { method.setAccessible(true); Class<?> expectedSetterType = method.getParameterTypes()[0]; Object converted = Converters.converts(context.getPropertyConverter(), newValue, expectedSetterType); method.invoke(target, converted); return; } } catch (Exception e) { throw new AccessException( String.format( "Cannot set property '%s' to '%s' on target type %s : %s", name, target.getClass().getSimpleName(), target.getClass().getSimpleName(), e.getMessage()) ); } throw new AccessException( String.format( "Cannot found setter method for attribute '%s' on class '%s'", name, target.getClass().getCanonicalName()) ); }  @Override boolean canRead(final EvaluationContext context,
                           final Object target,
                           final String name); @Override Object read(final EvaluationContext context,
                       final Object target,
                       final String name); @Override void write(final EvaluationContext context,
                      final Object target,
                      final String name,
                      final Object newValue); @Override boolean canWrite(final EvaluationContext context,
                            final Object target,
                            final String name);  }### Answer:
@Test(expected = AccessException.class) public void should_thrown_when_writing_invalid_property_using_getter_method_given_pojo() { ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor(); accessor.write(context, new DummyObject("foo"), "unknown", ""); }
@Test public void should_write_property_using_setter_method_given_pojo_and_expected_parameter() { ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor(); DummyObject object = new DummyObject(null); accessor.write(context, object, "field", "foo"); Assert.assertEquals("foo", object.field); }
@Test public void should_write_null_property_using_setter_method_given_pojo_and_expected_parameter() { ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor(); DummyObject object = new DummyObject("foo"); accessor.write(context, object, "field", null); Assert.assertEquals(null, object.field); }
@Test public void should_write_property_using_setter_method_given_pojo() { ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor(); DummyObject object = new DummyObject(null); accessor.write(context, object, "field", TypedValue.string("foo")); Assert.assertEquals("foo", object.field); }