/** * Retrieves against value from {@link #than} for given property. If parsing fails the * {@link PropertyValidation} will be filled with error and <code>null</code> will be returned * as value. * * @param property * Property to get against value for. * @param propertyValidation * Validation to report errors. * @return Value or <code>null</code> if parsing fails. */ private T getAgainstValue(SingleProperty<? extends T> property, PropertyValidation propertyValidation) { T against = property.parseLiteral(than); if (null == against) { ValidationError validationError = new ValidationError(Collections.<SingleProperty<?>> singletonList(property), "Validation of property " + property.getName() + " failed because literal (" + than + ") to compare against can not be parsed."); propertyValidation.addValidationError(validationError); } return against; }
@Test public void validatorIsGreaterThanOrEqual() { when(singleProperty.getValue()).thenReturn(Integer.valueOf(10)); when(singleProperty.getLogicalName()).thenReturn("my.property"); GreaterOrEqualValidator<Number> validator = new GreaterOrEqualValidator<>(); when(singleProperty.parseLiteral(null)).thenReturn(9, 10, 11); validator.validate(singleProperty, propertyValidation); verifyZeroInteractions(propertyValidation); validator.validate(singleProperty, propertyValidation); validator.validate(singleProperty, propertyValidation); verify(propertyValidation, times(1)).addValidationError(Matchers.<ValidationError> anyObject()); }
@Test public void validatorIsLessThan() { when(singleProperty.getValue()).thenReturn(Integer.valueOf(10)); when(singleProperty.getLogicalName()).thenReturn("my.property"); LessValidator<Number> validator = new LessValidator<>(); when(singleProperty.parseLiteral(null)).thenReturn(11, 10, 9); validator.validate(singleProperty, propertyValidation); verifyZeroInteractions(propertyValidation); validator.validate(singleProperty, propertyValidation); validator.validate(singleProperty, propertyValidation); verify(propertyValidation, times(2)).addValidationError(Matchers.<ValidationError> anyObject()); }
@Test public void validatorIsLessThanOrEqual() { when(singleProperty.getValue()).thenReturn(Integer.valueOf(10)); when(singleProperty.getLogicalName()).thenReturn("my.property"); LessOrEqualValidator<Number> validator = new LessOrEqualValidator<>(); when(singleProperty.parseLiteral(null)).thenReturn(11, 10, 9); validator.validate(singleProperty, propertyValidation); validator.validate(singleProperty, propertyValidation); verifyZeroInteractions(propertyValidation); validator.validate(singleProperty, propertyValidation); verify(propertyValidation, times(1)).addValidationError(Matchers.<ValidationError> anyObject()); }
@Test public void validatorIsGreaterThan() { when(singleProperty.getValue()).thenReturn(Integer.valueOf(10)); when(singleProperty.getLogicalName()).thenReturn("my.property"); GreaterValidator<Number> validator = new GreaterValidator<>(); when(singleProperty.parseLiteral(null)).thenReturn(9, 10, 11); validator.validate(singleProperty, propertyValidation); verifyZeroInteractions(propertyValidation); validator.validate(singleProperty, propertyValidation); validator.validate(singleProperty, propertyValidation); verify(propertyValidation, times(2)).addValidationError(Matchers.<ValidationError> anyObject()); }