FieldPropertyDescriptor extends AbstractPropertyDescriptor implements DozerPropertyDescriptor { public void setPropertyValue(Object bean, Object value, FieldMap fieldMap) { Object intermediateResult = bean; for (int i = 0; i < descriptorChain.length; i++) { DozerPropertyDescriptor descriptor = descriptorChain[i]; if (i != descriptorChain.length - 1) { Object currentValue = descriptor.getPropertyValue(intermediateResult); if (currentValue == null) { currentValue = destBeanCreator.create(descriptor.getPropertyType()); descriptor.setPropertyValue(intermediateResult, currentValue, fieldMap); } intermediateResult = currentValue; } else { descriptor.setPropertyValue(intermediateResult, value, fieldMap); } } } FieldPropertyDescriptor(Class<?> clazz, String fieldName, boolean isIndexed, int index,
                                   HintContainer srcDeepIndexHintContainer, HintContainer destDeepIndexHintContainer,
                                   DestBeanCreator destBeanCreator); Class<?> getPropertyType(); Class<?> genericType(); Object getPropertyValue(Object bean); void setPropertyValue(Object bean, Object value, FieldMap fieldMap);  }
@Test public void setPropertyValue() { FieldPropertyDescriptor descriptor = new FieldPropertyDescriptor(Container.class, "value", false, 0, null, null, destBeanCreator); Container bean = new Container("A"); descriptor.setPropertyValue(bean, "B", mock(FieldMap.class)); assertEquals("B", bean.value); }
@Test public void setPropertyValueChained() { FieldPropertyDescriptor descriptor = new FieldPropertyDescriptor(Container.class, "container.value", false, 0, null, null, destBeanCreator); Container bean = new Container(""); bean.container = new Container(""); descriptor.setPropertyValue(bean, "A", mock(FieldMap.class)); assertEquals("A", bean.container.value); }
@Test public void setPropertyValueChained_ThirdLevel() { FieldPropertyDescriptor descriptor = new FieldPropertyDescriptor(Container.class, "container.container.value", false, 0, null, null, destBeanCreator); Container bean = new Container("X"); bean.container = new Container("X"); bean.container.container = new Container("X"); descriptor.setPropertyValue(bean, "Y", mock(FieldMap.class)); assertEquals("Y", bean.container.container.value); }
@Test public void setPropertyValueChained_IntermediateNull() { FieldPropertyDescriptor descriptor = new FieldPropertyDescriptor(Container.class, "container.value", false, 0, null, null, destBeanCreator); Container bean = new Container(""); descriptor.setPropertyValue(bean, "A", mock(FieldMap.class)); assertEquals("A", bean.container.value); }
@Test public void setPropertyValueIndexed() { FieldPropertyDescriptor descriptor = new FieldPropertyDescriptor(Container.class, "values", true, 0, null, null, destBeanCreator); Container container = new Container(""); descriptor.setPropertyValue(container, "A", mock(FieldMap.class)); assertEquals(1, container.values.size()); assertEquals("A", container.values.get(0)); }