MapUpdater implements Updater, PortableObject { @SuppressWarnings({"unchecked"}) public void update(Object target, Object value) { if (target == null) { throw new IllegalArgumentException("Updater target cannot be null"); } if (!(target instanceof Map)) { throw new IllegalArgumentException("Updater target is not a Map"); } ((Map) target).put(key, value); } MapUpdater();  MapUpdater(String key); @SuppressWarnings({"unchecked"}) 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 public void testWithNullProperty() { MapUpdater updater = new MapUpdater(null); Map<String, Object> target = new HashMap<String, Object>(); updater.update(target, "KEYED_BY_NULL"); }
@Test(expected = IllegalArgumentException.class) public void testWithNullTarget() { MapUpdater updater = new MapUpdater("prop"); updater.update(null, "PROP_VALUE"); }
@Test(expected = IllegalArgumentException.class) public void testWithNonMapTarget() { MapUpdater updater = new MapUpdater("prop"); updater.update("bad target", "PROP_VALUE"); }
@Test public void testWithNonNullProperty() { MapUpdater updater = new MapUpdater("address"); Address merced = new Address("Merced", "Santiago", "Chile"); Map<String, Object> target = new HashMap<String, Object>(); updater.update(target, merced); assertEquals(merced, target.get("address")); }