### Question:
ReflectionUtils { public static void setFieldValue(Object target, String fieldName, Object value) { try { Field field = target.getClass().getDeclaredField(fieldName); field.setAccessible(true); field.set(target, value); } catch (NoSuchFieldException e) { throw handleException(fieldName, e); } catch (IllegalAccessException e) { throw handleException(fieldName, e); } } private  ReflectionUtils(); static Class<T> getClass(String className); static Class<T> getClassOrNull(String className); static T getFieldValue(Object target, String fieldName); static void setFieldValue(Object target, String fieldName, Object value); static Method getMethod(Object target, String methodName, Class... parameterTypes); static boolean hasMethod(Class<?> targetClass, String methodName, Class... parameterTypes); static Method getGetter(Object target, String property); static Method getSetter(Object target, String property, Class<?> parameterType); static T invoke(Object target, Method method, Object... parameters); static T invokeGetter(Object target, String property); static void invokeSetter(Object target, String property, Object parameter); static final String GETTER_PREFIX; static final String SETTER_PREFIX; }### Answer:
@Test public void testSetFieldValue() { TestObject testObject = new TestObject(); assertEquals("testObject", ReflectionUtils.getFieldValue(testObject, "name")); ReflectionUtils.setFieldValue(testObject, "name", "testObjectNameChanged"); assertEquals("testObjectNameChanged", ReflectionUtils.getFieldValue(testObject, "name")); ReflectionUtils.setFieldValue(testObject, "name", null); assertEquals(null, ReflectionUtils.getFieldValue(testObject, "name")); }
@Test(expected = ReflectionException.class) public void testSetFieldValueThrowsReflectionException() { ReflectionUtils.setFieldValue(new TestObject(), "unknown", "value"); }