@SuppressWarnings("unchecked") @Test public void canUpdate() { SingleProperty<Object> singleProperty = new SingleProperty<Object>("", "", "property1", "defaultValue", false, false) { @Override public Object getDefaultValue() { return null; } @Override protected void setDefaultValue(Object defaultValue) { } @Override protected Object getUsedValue() { return "myValue"; } @Override protected void setUsedValue(Object usedValue) { } @Override public AbstractPropertyUpdate<Object> createPropertyUpdate(Object updateValue) { return null; } @Override public Object parseLiteral(String literal) { return null; } }; AbstractPropertyUpdate<Object> propertyUpdate = Mockito.mock(AbstractPropertyUpdate.class); when(propertyUpdate.getPropertyLogicalName()).thenReturn("someOtherName"); assertThat(singleProperty.canUpdate(propertyUpdate), is(false)); when(propertyUpdate.getPropertyLogicalName()).thenReturn("property1"); when(propertyUpdate.getUpdateValue()).thenReturn(new Object()); assertThat(singleProperty.canUpdate(propertyUpdate), is(false)); when(propertyUpdate.getUpdateValue()).thenReturn("myValue"); assertThat(singleProperty.canUpdate(propertyUpdate), is(false)); when(propertyUpdate.getUpdateValue()).thenReturn("updateValue"); assertThat(singleProperty.canUpdate(propertyUpdate), is(true)); }
@SuppressWarnings("unchecked") public boolean canUpdate(IPropertyUpdate<?> propertyUpdate) { if (propertyUpdate.isRestoreDefault()) { return true; } if (!logicalName.equals(propertyUpdate.getPropertyLogicalName())) { return false; } Object updateValue = propertyUpdate.getUpdateValue(); if (!getValue().getClass().equals(updateValue.getClass())) { return false; } if (getValue().equals(updateValue)) { return false; } PropertyValidation propertyValidation = this.validateForValue((T) updateValue); return !propertyValidation.hasErrors(); }
SingleProperty extends AbstractProperty { @SuppressWarnings("unchecked") public boolean canUpdate(IPropertyUpdate<?> propertyUpdate) { if (propertyUpdate.isRestoreDefault()) { return true; } if (!logicalName.equals(propertyUpdate.getPropertyLogicalName())) { return false; } Object updateValue = propertyUpdate.getUpdateValue(); if (!getValue().getClass().equals(updateValue.getClass())) { return false; } if (getValue().equals(updateValue)) { return false; } PropertyValidation propertyValidation = this.validateForValue((T) updateValue); return !propertyValidation.hasErrors(); } }
SingleProperty extends AbstractProperty { @SuppressWarnings("unchecked") public boolean canUpdate(IPropertyUpdate<?> propertyUpdate) { if (propertyUpdate.isRestoreDefault()) { return true; } if (!logicalName.equals(propertyUpdate.getPropertyLogicalName())) { return false; } Object updateValue = propertyUpdate.getUpdateValue(); if (!getValue().getClass().equals(updateValue.getClass())) { return false; } if (getValue().equals(updateValue)) { return false; } PropertyValidation propertyValidation = this.validateForValue((T) updateValue); return !propertyValidation.hasErrors(); } SingleProperty();  SingleProperty(String name, String description, String logicalName, T defaultValue, boolean advanced, boolean serverRestartRequired); }
SingleProperty extends AbstractProperty { @SuppressWarnings("unchecked") public boolean canUpdate(IPropertyUpdate<?> propertyUpdate) { if (propertyUpdate.isRestoreDefault()) { return true; } if (!logicalName.equals(propertyUpdate.getPropertyLogicalName())) { return false; } Object updateValue = propertyUpdate.getUpdateValue(); if (!getValue().getClass().equals(updateValue.getClass())) { return false; } if (getValue().equals(updateValue)) { return false; } PropertyValidation propertyValidation = this.validateForValue((T) updateValue); return !propertyValidation.hasErrors(); } SingleProperty();  SingleProperty(String name, String description, String logicalName, T defaultValue, boolean advanced, boolean serverRestartRequired); abstract T getDefaultValue(); abstract T parseLiteral(String literal); @Override boolean isAdvanced(); boolean isPassword(); @Override boolean isServerRestartRequired(); @Override void register(Properties properties); @Override SingleProperty<?> forLogicalname(String propertyLogicalName); void setToDefaultValue(); AbstractPropertyUpdate<T> createAndValidatePropertyUpdate(T updateValue); RestoreDefaultPropertyUpdate<T> createRestoreDefaultPropertyUpdate(); @SuppressWarnings("unchecked") boolean canUpdate(IPropertyUpdate<?> propertyUpdate); void addValidator(ISinglePropertyValidator<? super T> validator); boolean isDefaultValueUsed(); T getValue(); void setValue(T value); String getLogicalName(); String getFormattedValue(); @Override int hashCode(); @Override boolean equals(Object obj); }
SingleProperty extends AbstractProperty { @SuppressWarnings("unchecked") public boolean canUpdate(IPropertyUpdate<?> propertyUpdate) { if (propertyUpdate.isRestoreDefault()) { return true; } if (!logicalName.equals(propertyUpdate.getPropertyLogicalName())) { return false; } Object updateValue = propertyUpdate.getUpdateValue(); if (!getValue().getClass().equals(updateValue.getClass())) { return false; } if (getValue().equals(updateValue)) { return false; } PropertyValidation propertyValidation = this.validateForValue((T) updateValue); return !propertyValidation.hasErrors(); } SingleProperty();  SingleProperty(String name, String description, String logicalName, T defaultValue, boolean advanced, boolean serverRestartRequired); abstract T getDefaultValue(); abstract T parseLiteral(String literal); @Override boolean isAdvanced(); boolean isPassword(); @Override boolean isServerRestartRequired(); @Override void register(Properties properties); @Override SingleProperty<?> forLogicalname(String propertyLogicalName); void setToDefaultValue(); AbstractPropertyUpdate<T> createAndValidatePropertyUpdate(T updateValue); RestoreDefaultPropertyUpdate<T> createRestoreDefaultPropertyUpdate(); @SuppressWarnings("unchecked") boolean canUpdate(IPropertyUpdate<?> propertyUpdate); void addValidator(ISinglePropertyValidator<? super T> validator); boolean isDefaultValueUsed(); T getValue(); void setValue(T value); String getLogicalName(); String getFormattedValue(); @Override int hashCode(); @Override boolean equals(Object obj);  }