PropertyUtil { public static <V> void inject(Object obj, Map<String, V> parameters) { Class clazz = obj.getClass(); List<PropertyInjector> injectors = getInjectors(clazz); if (!injectors.isEmpty()) { for(PropertyInjector injector: injectors) { injector.inject(obj, parameters); } } }  static Object convert(Class type, V value); static void inject(Object obj, Map<String, V> parameters); static Properties getResourceAsProperties(String resource); static Properties getResourceAsProperties(ClassLoader classLoader, String resource);  }
@Test public void inject() throws Exception { Map<String, Object> map = new HashMap<String, Object>(); map.put("int1", 123); map.put("int2", new Object()); map.put("long1", 123); map.put("long2", ""); map.put("boolean1", true); map.put("boolean2", ""); map.put("str1", "abc"); map.put("str2", new Object()); map.put("sample_enum", SampleEnum.THREE); map.put("sample_service", new SampleImpl()); SimpleBean bean = new SimpleBean(); PropertyUtil.inject(bean, map); assertEquals(bean.int1, 123); assertEquals(bean.int2, 2); assertEquals(bean.long1, 123); assertEquals(bean.long2, 2); assertEquals(bean.boolean1, true); assertEquals(bean.boolean2, true); assertEquals(bean.str1, "abc"); assertEquals(bean.str2, "str2"); assertEquals(bean.sampleEnum, SampleEnum.THREE); assertNotNull(bean.sampleService); PropertyUtil.inject(new NoInjection(), map); PropertyUtil.inject(new IllegalAccess(), map); try { PropertyUtil.inject(new UnsupportedType(), map); fail("Unsupported"); } catch(Exception ex) { } }