### Question:
ReflectionUtils { public static <T> T getFieldValue(Object target, String fieldName) { try { Field field = target.getClass().getDeclaredField(fieldName); field.setAccessible(true); @SuppressWarnings("unchecked") T returnValue = (T) field.get(target); return returnValue; } 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 testGetFieldValue() { TestObject testObject = new TestObject(); assertEquals("testObject", ReflectionUtils.getFieldValue(testObject, "name")); assertEquals(1, ((Number) ReflectionUtils.getFieldValue(testObject, "version")).intValue()); }
@Test(expected = ReflectionException.class) public void testGetFieldValueThrowsReflectionException() { ReflectionUtils.getFieldValue(new TestObject(), "unknown"); }