@Test public void stringToNumber() throws Exception { StringProperty stringProperty = new StringProperty(); stringProperty.setValue("one"); NumberClass numberClass = mock(NumberClass.class); when(numberClass.newProperty()).thenReturn(new IntegerProperty()); when(numberClass.fromString(stringProperty.toText())).thenReturn(null); when(numberClass.getName()).thenReturn("age"); when(numberClass.getClassName()).thenReturn("Some.Class"); assertNull(this.mocker.getComponentUnderTest().convertProperty(stringProperty, numberClass)); verify(this.mocker.getMockedLogger()).warn( "Incompatible data migration when changing field [{}] of class [{}]", "age", "Some.Class"); }
public BaseProperty<?> convertProperty(BaseProperty<?> storedProperty, PropertyClass modifiedPropertyClass) { Object newValue = convertPropertyValue(storedProperty.getValue(), modifiedPropertyClass); BaseProperty<?> newProperty = null; if (newValue != null) { newProperty = modifiedPropertyClass.newProperty(); try { newProperty.setValue(newValue); } catch (Exception e) { newProperty = modifiedPropertyClass.fromString(storedProperty.toText()); } if (newProperty != null) { newProperty.setId(storedProperty.getId()); newProperty.setName(storedProperty.getName()); } else { this.logger.warn("Incompatible data migration when changing field [{}] of class [{}]", modifiedPropertyClass.getName(), modifiedPropertyClass.getClassName()); } } else { } return newProperty; }
PropertyConverter { public BaseProperty<?> convertProperty(BaseProperty<?> storedProperty, PropertyClass modifiedPropertyClass) { Object newValue = convertPropertyValue(storedProperty.getValue(), modifiedPropertyClass); BaseProperty<?> newProperty = null; if (newValue != null) { newProperty = modifiedPropertyClass.newProperty(); try { newProperty.setValue(newValue); } catch (Exception e) { newProperty = modifiedPropertyClass.fromString(storedProperty.toText()); } if (newProperty != null) { newProperty.setId(storedProperty.getId()); newProperty.setName(storedProperty.getName()); } else { this.logger.warn("Incompatible data migration when changing field [{}] of class [{}]", modifiedPropertyClass.getName(), modifiedPropertyClass.getClassName()); } } else { } return newProperty; } }
PropertyConverter { public BaseProperty<?> convertProperty(BaseProperty<?> storedProperty, PropertyClass modifiedPropertyClass) { Object newValue = convertPropertyValue(storedProperty.getValue(), modifiedPropertyClass); BaseProperty<?> newProperty = null; if (newValue != null) { newProperty = modifiedPropertyClass.newProperty(); try { newProperty.setValue(newValue); } catch (Exception e) { newProperty = modifiedPropertyClass.fromString(storedProperty.toText()); } if (newProperty != null) { newProperty.setId(storedProperty.getId()); newProperty.setName(storedProperty.getName()); } else { this.logger.warn("Incompatible data migration when changing field [{}] of class [{}]", modifiedPropertyClass.getName(), modifiedPropertyClass.getClassName()); } } else { } return newProperty; }  }
PropertyConverter { public BaseProperty<?> convertProperty(BaseProperty<?> storedProperty, PropertyClass modifiedPropertyClass) { Object newValue = convertPropertyValue(storedProperty.getValue(), modifiedPropertyClass); BaseProperty<?> newProperty = null; if (newValue != null) { newProperty = modifiedPropertyClass.newProperty(); try { newProperty.setValue(newValue); } catch (Exception e) { newProperty = modifiedPropertyClass.fromString(storedProperty.toText()); } if (newProperty != null) { newProperty.setId(storedProperty.getId()); newProperty.setName(storedProperty.getName()); } else { this.logger.warn("Incompatible data migration when changing field [{}] of class [{}]", modifiedPropertyClass.getName(), modifiedPropertyClass.getClassName()); } } else { } return newProperty; }  BaseProperty<?> convertProperty(BaseProperty<?> storedProperty, PropertyClass modifiedPropertyClass); }
PropertyConverter { public BaseProperty<?> convertProperty(BaseProperty<?> storedProperty, PropertyClass modifiedPropertyClass) { Object newValue = convertPropertyValue(storedProperty.getValue(), modifiedPropertyClass); BaseProperty<?> newProperty = null; if (newValue != null) { newProperty = modifiedPropertyClass.newProperty(); try { newProperty.setValue(newValue); } catch (Exception e) { newProperty = modifiedPropertyClass.fromString(storedProperty.toText()); } if (newProperty != null) { newProperty.setId(storedProperty.getId()); newProperty.setName(storedProperty.getName()); } else { this.logger.warn("Incompatible data migration when changing field [{}] of class [{}]", modifiedPropertyClass.getName(), modifiedPropertyClass.getClassName()); } } else { } return newProperty; }  BaseProperty<?> convertProperty(BaseProperty<?> storedProperty, PropertyClass modifiedPropertyClass);  }