AccessorSyntheticField implements SyntheticField { public void set(Object object, Object value) throws IllegalAccessException, IllegalArgumentException { if (null != setter) { try { setter.invoke(object, value); } catch (InvocationTargetException ite) { if (ite.getCause() instanceof RuntimeException && !(ite.getCause() instanceof JTransfoException)) { throw (RuntimeException) ite.getCause(); } throw new JTransfoException(String.format(GET_SET_ITO, setter.getName(), object.getClass().getName(), setter.getDeclaringClass().getName(), ite.getCause().getMessage()), ite.getCause()); } } else { if (!setUsingFieldLogged) { log.warn("Cannot find setter (not public, wrong name or wrong type), " + "using field to access field {} of {}.", name, field.getType().getName()); setUsingFieldLogged = true; } field.set(object, value); } } AccessorSyntheticField(ReflectionHelper reflectionHelper, Class<?> clazz, Field field);   AccessorSyntheticField(
            ReflectionHelper reflectionHelper, Class<?> clazz, String name, boolean readOnlyField); Object get(Object object); void set(Object object, Object value); String getName(); Class<?> getType(); Type getGenericType();  }
@Test public void testSet() throws Exception { accessorSyntheticField.set(domain, "bla"); verify(domain).setA("bla"); }
@Test public void testSetNoSetter() throws Exception { ReflectionTestUtils.setField(accessorSyntheticField, "setter", null); accessorSyntheticField.set(domain, "bla"); verify(domain, times(0)).setA("bla"); assertThat(domain.getA()).isEqualTo("bla"); }
@Test public void testSetInvocationTargetException() throws Exception { doThrow(new JTransfoException("xxx")).when(domain).setA("bla"); exception.expect(JTransfoException.class); exception.expectMessage("InvocationTargetException trying to use setA on object of type " + "org.jtransfo.object.SimpleBaseDomain"); exception.expectMessage(". Expected type is org.jtransfo.object.SimpleBaseDomain. Cause is: xxx"); accessorSyntheticField.set(domain, "bla"); }
@Test public void testSetInvocationTargetException2() throws Exception { doThrow(new IOException("zzz")).when(domain).setA("bla"); exception.expect(JTransfoException.class); exception.expectMessage("InvocationTargetException trying to use setA on object of type " + "org.jtransfo.object.SimpleBaseDomain"); exception.expectMessage(". Expected type is org.jtransfo.object.SimpleBaseDomain. Cause is: zzz"); accessorSyntheticField.set(domain, "bla"); }
@Test public void testSetInvocationTargetException3() throws Exception { doThrow(new IllegalStateException("yyy")).when(domain).setA("bla"); exception.expect(IllegalStateException.class); exception.expectMessage("yyy"); accessorSyntheticField.set(domain, "bla"); }