ValueSetter { public void invoke(String aKey, Object anOn, String aWith) { try { if (twoArgSetter) { setter.invoke(anOn, aKey, converter.convert(aWith)); } else { setter.invoke(anOn, converter.convert(aWith)); } } catch (ParsingException anExc) { throw anExc; } catch (IllegalArgumentException anExc) { throw new ParsingException( anExc.getMessage() + " while trying to invoke " + setter + " on " + anOn + " with " + ((aKey != null) ? aKey + " and " : "") + aWith + " converted by " + converter, anExc); } catch (Exception anExc) { throw new RuntimeException(anExc); } } ValueSetter(ConverterRegistry aConverters, Class<?> aContextType, String... aMaybeNames);  ValueSetter(ConverterRegistry aConverters, Class<?> aContextType, Class<?> aValueType, String... aMaybeNames); void invoke(String aKey, Object anOn, String aWith); String toString();  }
@Test public void introspectsModelClassToFindAndInvokeSetterMethods() { mockery.checking(new Expectations() {{ oneOf(converters).getConverter(Integer.class); will(returnValue(integerConverter)); oneOf(integerConverter).convert("53"); will(returnValue(new Integer(53))); oneOf(model).setFieldOne(new Integer(53)); }}); ValueSetter _s = new ValueSetter(converters, TestModel.class, "fieldOne"); _s.invoke("fieldOne", model, "53"); }
@Test public void introspectsModelClassToFindAndInvokeAddMethods() { mockery.checking(new Expectations() {{ oneOf(converters).getConverter(Integer.class); will(returnValue(integerConverter)); oneOf(integerConverter).convert("17"); will(returnValue(new Integer(17))); oneOf(model).addFieldTwo(new Integer(17)); }}); ValueSetter _s = new ValueSetter(converters, TestModel.class, "fieldTwo"); _s.invoke("fieldTwo", model, "17"); }
@Test public void introspectsModelClassToFindAndInvokeInsertMethods() { mockery.checking(new Expectations() {{ oneOf(converters).getConverter(Integer.class); will(returnValue(integerConverter)); oneOf(integerConverter).convert("98"); will(returnValue(new Integer(98))); oneOf(model).insertFieldThree(new Integer(98)); }}); ValueSetter _s = new ValueSetter(converters, TestModel.class, "fieldThree"); _s.invoke("fieldThree", model, "98"); }