AccessorSyntheticField implements SyntheticField { public Object get(Object object) throws IllegalAccessException, IllegalArgumentException { if (null != getter) { try { return getter.invoke(object); } catch (InvocationTargetException ite) { if (ite.getCause() instanceof RuntimeException && !(ite.getCause() instanceof JTransfoException)) { throw (RuntimeException) ite.getCause(); } throw new JTransfoException(String.format(GET_SET_ITO, getter.getName(), object.getClass().getName(), getter.getDeclaringClass().getName(), ite.getCause().getMessage()), ite.getCause()); } } else { if (!getUsingFieldLogged) { log.warn("Cannot find getter (not public, wrong name or wrong type), " + "using field to access field {} of {}.", name, field.getType().getName()); getUsingFieldLogged = true; } return field.get(object); } } 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 testGet() throws Exception { accessorSyntheticField.get(domain); verify(domain).getA(); }
@Test public void testGetNoGetter() throws Exception { ReflectionTestUtils.setField(domain, "a", "zzz"); ReflectionTestUtils.setField(accessorSyntheticField, "getter", null); assertThat(accessorSyntheticField.get(domain)).isEqualTo("zzz"); verify(domain, times(0)).getA(); }
@Test public void testGetInvocationTargetException() throws Exception { when(domain.getA()).thenThrow(new JTransfoException("xxx")); exception.expect(JTransfoException.class); exception.expectMessage("InvocationTargetException trying to use getA on object of type " + "org.jtransfo.object.SimpleBaseDomain"); exception.expectMessage(". Expected type is org.jtransfo.object.SimpleBaseDomain. Cause is: xxx"); accessorSyntheticField.get(domain); }
@Test public void testGetInvocationTargetException2() throws Exception { when(domain.getA()).thenThrow(new IOException("zzz")); exception.expect(JTransfoException.class); exception.expectMessage("InvocationTargetException trying to use getA on object of type " + "org.jtransfo.object.SimpleBaseDomain"); exception.expectMessage(". Expected type is org.jtransfo.object.SimpleBaseDomain. Cause is: zzz"); accessorSyntheticField.get(domain); }
@Test public void testGetInvocationTargetException3() throws Exception { when(domain.getA()).thenThrow(new IllegalStateException("yyy")); exception.expect(IllegalStateException.class); exception.expectMessage("yyy"); accessorSyntheticField.get(domain); }