ReflectionUtils { public static void injectValue(final Object obj, final String fieldName, final Object value) throws NoSuchFieldException, IllegalAccessException { injectValue(obj, findField(obj, fieldName), value); } 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 testInjectPrivateFieldUsingFieldObject() throws Exception { final Long value = 10L; final Field toi = getClass().getDeclaredField("privateField"); ReflectionUtils.injectValue(this, toi, value); assertThat(privateField, equalTo(value)); }
@Test public void testInjectPrivateFieldUsingFieldName() throws Exception { final Long value = 10L; ReflectionUtils.injectValue(this, "privateField", value); assertThat(privateField, equalTo(value)); }