BeanWrapperUpdater implements Updater, Serializable, PortableObject { public void update(Object target, Object value) { BeanWrapper bw = new BeanWrapperImpl(target); bw.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true)); bw.setPropertyValue(propertyName, value); } BeanWrapperUpdater();  BeanWrapperUpdater(String propertyName); void update(Object target, Object value); void readExternal(PofReader reader); void writeExternal(PofWriter writer); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test(expected = RuntimeException.class) public void testWithBadPropertyName() { BeanWrapperUpdater updater = new BeanWrapperUpdater("bad"); Person person = new Person(); updater.update(person, "value"); }
@Test public void testWithStringPropertyType() { BeanWrapperUpdater updater = new BeanWrapperUpdater("name"); Person person = new Person(); assertNull(person.getName()); updater.update(person, "Ivan"); assertEquals("Ivan", person.getName()); }
@Test public void testWithPrimitivePropertyType() { BeanWrapperUpdater updater = new BeanWrapperUpdater("id"); Person person = new Person(); assertEquals(0L, person.getId()); updater.update(person, 2504L); assertEquals(2504L, person.getId()); }
@SuppressWarnings("deprecation") @Test public void testWithDateType() { BeanWrapperUpdater updater = new BeanWrapperUpdater("dateOfBirth"); Person person = new Person(); assertEquals(null, person.getDateOfBirth()); updater.update(person, "1974-08-24"); assertEquals(74, person.getDateOfBirth().getYear()); assertEquals(7, person.getDateOfBirth().getMonth()); assertEquals(24, person.getDateOfBirth().getDate()); }
@Test public void testWithComplexPropertyType() { BeanWrapperUpdater updater = new BeanWrapperUpdater("address"); Person person = new Person(); assertNull(person.getAddress()); Address merced = new Address("Merced", "Santiago", "Chile"); updater.update(person, merced); assertEquals(merced, person.getAddress()); updater = new BeanWrapperUpdater("address.street"); updater.update(person, "Av Bernardo O'Higgins"); assertEquals("Av Bernardo O'Higgins", person.getAddress().getStreet()); }