DefaultBeanManager implements BeanManager { @Override public void populate(Object bean, Map<String, ?> values) throws PropertyException { Map<String, Object> remainingValues = new HashMap<>(values); populateBean(bean, remainingValues); if (!remainingValues.isEmpty() && bean instanceof RawProperties) { RawProperties rawProperties = (RawProperties) bean; for (Map.Entry<String, Object> entry : remainingValues.entrySet()) { rawProperties.set(entry.getKey(), entry.getValue()); } } validateBean(bean); }  ValidatorFactory getValidatorFactory(); @Override void populate(Object bean, Map<String, ?> values); @Override BeanDescriptor getBeanDescriptor(Class<?> beanClass);  }
@Test void populate() throws PropertyException { TestBean beanTest = new TestBean(); Map<String, String> values = new HashMap<>(); values.put("lowerprop", "lowerpropvalue"); values.put("upperprop", "upperPropvalue"); values.put("prop2", "42"); values.put("prop3", "true"); values.put("hiddenProperty", "hiddenPropertyvalue"); values.put("publicField", "publicFieldvalue"); values.put("genericProp", "1,2"); this.defaultBeanManager.populate(beanTest, values); assertEquals("lowerpropvalue", beanTest.getLowerprop()); assertEquals("upperPropvalue", beanTest.getUpperProp()); assertEquals(42, beanTest.getProp2()); assertTrue(beanTest.getProp3()); assertNull(beanTest.getHiddenProperty()); assertEquals("publicFieldvalue", beanTest.publicField); assertEquals(Arrays.asList(1, 2), beanTest.getGenericProp()); }
@Test void populateWhenMissingMandatoryProperty() { Throwable exception = assertThrows(PropertyMandatoryException.class, () -> this.defaultBeanManager.populate(new TestBean(), new HashMap<String, String>())); assertEquals("Property [prop2] mandatory", exception.getMessage()); }
@Test void populateRawProperties() throws PropertyException { Map<String, Object> values = new HashMap<>(); values.put("pro1", "value1"); values.put("prop2", 2); RawPropertiesTest bean = new RawPropertiesTest(); this.defaultBeanManager.populate(bean, values); assertEquals(values, bean); }