### Question:
PropertyAccessorHelper { public static Object getObject(Object from, Field field) { if (!field.isAccessible()) { field.setAccessible(true); } try { return field.get(from); } catch (IllegalArgumentException iarg) { throw new PropertyAccessException(iarg); } catch (IllegalAccessException iacc) { throw new PropertyAccessException(iacc); } }  static void set(Object target, Field field, byte[] bytes); static void set(Object target, Field field, String fieldVal); static void set(Object target, Field field, Object value); static Object getObject(Object from, Field field); static Object getObjectCopy(Object from, Field field); static String getString(Object from, Field field); static byte[] get(Object from, Field field); static Object getId(Object entity, EntityMetadata metadata); static void setId(Object entity, EntityMetadata metadata, Object rowKey); static void setId(Object entity, EntityMetadata metadata, byte[] rowKey); @SuppressWarnings("null") // TODO: Too much code, improve this, possibly by breaking it static final Object getObject(Object obj, String fieldName); static Class<?> getGenericClass(Field collectionField); static List<Class<?>> getGenericClasses(Field collectionField); static Field[] getDeclaredFields(Field relationalField); static final boolean isCollection(Class<?> clazz); static final Object getObject(Class<?> clazz); static final byte[] toBytes(Object o, Field f); static final byte[] toBytes(Object o, Class c); static Object fromSourceToTargetClass(Class<?> targetClass, Class<?> sourceClass, Object o); static Object fromDate(Class<?> targetClass, Class<?> sourceClass, Object o); static byte[] getBytes(Object o); static String getString(Object o); static Object getObject(Class clazz, byte[] b); static final Collection getCollectionInstance(Field collectionField);  }### Answer:
@Test public void testGetObjectObjectField() { PersonnelDTO person = new PersonnelDTO("1", "Amresh", "Singh"); try { Object id = PropertyAccessorHelper.getObject(person, person.getClass().getDeclaredField("personId")); Object fn = PropertyAccessorHelper.getObject(person, person.getClass().getDeclaredField("firstName")); Object ln = PropertyAccessorHelper.getObject(person, person.getClass().getDeclaredField("lastName")); Assert.assertEquals("1", id); Assert.assertEquals("Amresh", fn); Assert.assertEquals("Singh", ln); } catch (SecurityException e) { Assert.fail(e.getMessage()); } catch (NoSuchFieldException e) { Assert.fail(e.getMessage()); } }
@Test public void testGetObjectObjectString() { PersonnelDTO person = new PersonnelDTO("1", "Amresh", "Singh"); try { Object id = PropertyAccessorHelper.getObject(person, "personId"); Object fn = PropertyAccessorHelper.getObject(person, "firstName"); Object ln = PropertyAccessorHelper.getObject(person, "lastName"); Assert.assertEquals("1", id); Assert.assertEquals("Amresh", fn); Assert.assertEquals("Singh", ln); } catch (SecurityException e) { Assert.fail(e.getMessage()); } }
@Test public void testGetObjectClassOfQ() { Object o = PropertyAccessorHelper.getObject(PhotographerUni_1_M_1_M.class); Assert.assertNotNull(o); Assert.assertTrue(o instanceof PhotographerUni_1_M_1_M); }