class 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);
		}
	}

}

class ValueSetterTest {

	private ConverterRegistry converters;
	private TestModel model;
	private StringConverter<Integer> integerConverter;
	private Mockery mockery;

	@Test
	public void introspectsModelClassToFindAndInvokeAddMethods() {

		mockery.checking(new Expectations() {{
			oneOf(converters).getConverter(Integer.class); // parameter to the setFieldOne method is of type Integer
			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");
	}

}