### Question:
ReflectionUtils { public static Object getFieldValue(Object entity, String fieldName) { try { Field field = getField(entity, fieldName); return field.get(entity); } catch (Exception e) { throw new HateoasInjectException(e); } } private  ReflectionUtils(); static boolean hasField(Object entity, String fieldName); static boolean hasFieldHierarchical(Object entity, String fieldName); static boolean hasField(Class clazz, String fieldName); static void setFieldAccessible(Field field); static Object getFieldValue(Object entity, String fieldName); static Object getFieldValueHierarchical(Object entity, String fieldName); static Field getField(Object entity, String fieldName); static Field getField(Class clazz, String fieldName); static Collection<Field> getFieldsHierarchical(Class clazz); static Field getFieldHierarchical(Class clazz, String fieldName); static void setFieldHierarchical(Object entity, String fieldName, Object value); static void setField(Object entity, String fieldName, Object value);  }### Answer:
@Test public void givenThatPrivateFieldExistsItWillBeRetrievedByGetFieldValue() { Object result = ReflectionUtils.getFieldValue(new DummyBean(), "value"); assertEquals("expectedValue", result); }
@Test public void givenThatPublicFieldExistsItWillBeRetrievedByGetFieldValue() { Object result = ReflectionUtils.getFieldValue(new DummyBean(), "otherValue"); assertEquals("otherExpectedValue", result); }
@Test(expected = HateoasInjectException.class) public void nonexistingFieldThrowsException() { ReflectionUtils.getFieldValue(new DummyBean(), "thisfielddoesntexist"); }