ReflectionUtils { public static Object getValue(final Object src, final String fieldName) throws IllegalAccessException, NoSuchFieldException { return getValue(src, findField(src, fieldName)); } private  ReflectionUtils(); static void injectValue(final Object obj, final String fieldName, final Object value); static void injectValue(final Object obj, final Field field, final Object value); static Object getValue(final Object src, final String fieldName); static Object getValue(final Object src, final Field field);  }
@Test public void testGetValeOfAPrivateFieldUsingFieldObject() throws Exception { privateField = 10l; final Field toi = getClass().getDeclaredField("privateField"); final Object value = ReflectionUtils.getValue(this, toi); assertThat(privateField, equalTo(value)); }
@Test public void testGetValeOfAPrivateFieldUsingFieldName() throws Exception { privateField = 10l; final Object value = ReflectionUtils.getValue(this, "privateField"); assertThat(privateField, equalTo(value)); }