### Question:
PropertyUtils { public static Accessor accessor(String nestedPropertyName) { if (nestedPropertyName == null) { throw new IllegalArgumentException("Null property name."); } if (nestedPropertyName.length() == 0) { throw new IllegalArgumentException("Empty property name."); } return compilePathAccessor(nestedPropertyName); } private  PropertyUtils(); static Accessor accessor(String nestedPropertyName); static Object getProperty(Object object, String nestedPropertyName); static void setProperty(Object object, String nestedPropertyName, Object value); static void installAccessorFactory(AccessorFactory accessorFactory);  }### Answer:
@Test public void testAccessor() { Accessor accessor = PropertyUtils.accessor("byteArrayField"); assertNotNull(accessor); TstJavaBean o1 = createBean(); assertSame(o1.getByteArrayField(), accessor.getValue(o1)); TstJavaBean o2 = new TstJavaBean(); assertNull(o2.getByteArrayField()); accessor.setValue(o2, o1.getByteArrayField()); assertNotNull(o2.getByteArrayField()); assertSame(o1.getByteArrayField(), o2.getByteArrayField()); }
@Test public void testAccessor_Cache() { Accessor accessor = PropertyUtils.accessor("p1"); assertNotNull(accessor); assertSame(accessor, PropertyUtils.accessor("p1")); assertSame(accessor, PropertyUtils.accessor("p1")); assertNotSame(accessor, PropertyUtils.accessor("p2")); }
@Test public void testAccessor_CacheNested() { Accessor accessor = PropertyUtils.accessor("p1.p2"); assertNotNull(accessor); assertSame(accessor, PropertyUtils.accessor("p1.p2")); assertNotSame(accessor, PropertyUtils.accessor("p1")); assertNotSame(accessor, PropertyUtils.accessor("p2")); }
@Test public void testAccessorNested() { Accessor accessor = PropertyUtils.accessor("related.byteArrayField"); assertNotNull(accessor); TstJavaBean o1 = createBean(); o1.setRelated(new TstJavaBean()); o1.getRelated().setByteArrayField(new byte[] { 3, 4, 5 }); assertSame(o1.getRelated().getByteArrayField(), accessor.getValue(o1)); TstJavaBean o2 = new TstJavaBean(); o2.setRelated(new TstJavaBean()); byte[] b1 = new byte[] { 6, 7, 8 }; accessor.setValue(o2, b1); assertSame(b1, o2.getRelated().getByteArrayField()); }
@Test public void testAccessorNested_Null() { Accessor accessor = PropertyUtils.accessor("related.byteArrayField"); assertNotNull(accessor); TstJavaBean o1 = createBean(); assertNull(accessor.getValue(o1)); }