### Question:
BeanUtils { public static void mapToBean(Object bean, Map<String, Object> data, boolean ignoreNotExistingSetter) throws InvocationTargetException, IllegalArgumentException { if (data == null || bean == null) { return; } for (Map.Entry<String, Object> entry : data.entrySet()) { try { Method mtd = getSetter(bean, entry.getKey()); if (mtd == null) { if (!ignoreNotExistingSetter) { throw new IllegalArgumentException(); } continue; } mtd.invoke(bean, entry.getValue()); } catch (IllegalAccessException ex) { } } }  static Map<String, Object> beanToMap(Object bean); static void mapToBean(Object bean, Map<String, Object> data, boolean ignoreNotExistingSetter); static Collection<Method> getGetters(Object bean); static Collection<Method> getSetters(Object bean); static String toAttributeName(Method m); static Method getSetter(Object bean, String attributeName);  }### Answer:
@Test public void testMapToBean1() throws Exception { Map<String, Object> map = new HashMap<String, Object>(); map.put("one", "hello"); map.put("two", true); Bean1 b = new Bean1(); BeanUtils.mapToBean(b, map, false); assertEquals("hello", b.getOne()); assertTrue(b.isTwo()); }
@Test public void testMapToBean2() throws Exception { Map<String, Object> map = new HashMap<String, Object>(); map.put("one", "hello"); map.put("two", true); map.put("some", "some"); Bean1 b = new Bean1(); BeanUtils.mapToBean(b, map, true); try { BeanUtils.mapToBean(b, map, false); assertTrue(false); } catch (IllegalArgumentException ex) { } }