// null value
numberValue = VALUE_FACTORY.createNumberValue();
errors = numberType.verify(numberValue);
assertEquals(1, errors.size());
VerificationError error =
(VerificationError) errors.iterator().next();
assertEquals(VerificationError.TYPE_NULL_VALUE,
error.getType());
assertEquals("", error.getLocation());
assertEquals(numberValue, error.getInvalidValue());
assertNull(error.getConstraint());
// invalid type
BooleanValue booleanValue = VALUE_FACTORY.createBooleanValue();
errors = numberType.verify(booleanValue);
assertEquals(1, errors.size());
error = (VerificationError) errors.iterator().next();
assertEquals(VerificationError.TYPE_INVALID_IMPLEMENTATION,
error.getType());
assertEquals("", error.getLocation());
assertEquals(booleanValue, error.getInvalidValue());
assertNull(error.getConstraint());
// enumerated constraint
final MutableEnumeratedConstraint enumeratedConstraint =
CONSTRAINT_FACTORY.createEnumeratedConstraint();
final List enumeratedValues =
enumeratedConstraint.getMutableEnumeratedValues();
final MutableNumberValue constraintValue =
VALUE_FACTORY.createNumberValue();
constraintValue.setValue(new Integer(6));
enumeratedValues.add(constraintValue.createImmutable());
constraintValue.setValue(new Integer(7));
enumeratedValues.add(constraintValue.createImmutable());
numberType.setEnumeratedConstraint(enumeratedConstraint);
// check constraint with right value
numberValue.setValue(new Integer(6));
errors = numberType.verify(numberValue);
assertEquals(0, errors.size());
// check constraint violation
numberValue.setValue(new Integer(8));
errors = numberType.verify(numberValue);
assertEquals(1, errors.size());
error = (VerificationError) errors.iterator().next();
assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
error.getType());
assertEquals("", error.getLocation());
assertEquals(numberValue, error.getInvalidValue());
assertEquals(enumeratedConstraint, error.getConstraint());
numberType.setEnumeratedConstraint(null);
// sub type constraint
final ImmutableNumberSubTypeConstraint subTypeConstraint =
CONSTRAINT_FACTORY.getNumberSubTypeConstraint(Integer.class);
numberType.setNumberSubTypeConstraint(subTypeConstraint);
// check constraint with right value
numberValue.setValue(new Integer(6));
errors = numberType.verify(numberValue);
assertEquals(0, errors.size());
// check constraint violation
numberValue.setValue(new Long(8));
errors = numberType.verify(numberValue);
assertEquals(1, errors.size());
error = (VerificationError) errors.iterator().next();
assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
error.getType());
assertEquals("", error.getLocation());
assertEquals(numberValue, error.getInvalidValue());
assertEquals(subTypeConstraint, error.getConstraint());
numberType.setNumberSubTypeConstraint(null);
// minimum value constraint with inclusive set to true
final MutableMinimumValueConstraint minValueConstraint =
CONSTRAINT_FACTORY.createMinimumValueConstraint();
minValueConstraint.setLimit(new Integer(6));
minValueConstraint.setInclusive(true);
numberType.setMinimumValueConstraint(minValueConstraint);
// check constraint with right value
numberValue.setValue(new Integer(6));
errors = numberType.verify(numberValue);
assertEquals(0, errors.size());
// check constraint violation
numberValue.setValue(new Integer(5));
errors = numberType.verify(numberValue);
assertEquals(1, errors.size());
error = (VerificationError) errors.iterator().next();
assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
error.getType());
assertEquals("", error.getLocation());
assertEquals(numberValue, error.getInvalidValue());
assertEquals(minValueConstraint, error.getConstraint());
numberType.setEnumeratedConstraint(null);
// minimum value constraint with inclusive set to false
minValueConstraint.setInclusive(false);
numberType.setMinimumValueConstraint(minValueConstraint);
// check constraint with right value
numberValue.setValue(new Integer(7));
errors = numberType.verify(numberValue);
assertEquals(0, errors.size());
// check constraint violation
numberValue.setValue(new Integer(6));
errors = numberType.verify(numberValue);
assertEquals(1, errors.size());
error = (VerificationError) errors.iterator().next();
assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
error.getType());
assertEquals("", error.getLocation());
assertEquals(numberValue, error.getInvalidValue());
assertEquals(minValueConstraint, error.getConstraint());
numberType.setMinimumValueConstraint(null);
// maximum value constraint with inclusive set to true
final MutableMaximumValueConstraint maxValueConstraint =
CONSTRAINT_FACTORY.createMaximumValueConstraint();
maxValueConstraint.setLimit(new Integer(6));
maxValueConstraint.setInclusive(true);
numberType.setMaximumValueConstraint(maxValueConstraint);
// check constraint with right value
numberValue.setValue(new Integer(6));
errors = numberType.verify(numberValue);
assertEquals(0, errors.size());
// check constraint violation
numberValue.setValue(new Integer(7));
errors = numberType.verify(numberValue);
assertEquals(1, errors.size());
error = (VerificationError) errors.iterator().next();
assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
error.getType());
assertEquals("", error.getLocation());
assertEquals(numberValue, error.getInvalidValue());
assertEquals(maxValueConstraint, error.getConstraint());
numberType.setEnumeratedConstraint(null);
// maximum value constraint with inclusive set to false
maxValueConstraint.setInclusive(false);
numberType.setMaximumValueConstraint(maxValueConstraint);
// check constraint with right value
numberValue.setValue(new Integer(5));
errors = numberType.verify(numberValue);
assertEquals(0, errors.size());
// check constraint violation
numberValue.setValue(new Integer(6));
errors = numberType.verify(numberValue);
assertEquals(1, errors.size());
error = (VerificationError) errors.iterator().next();
assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
error.getType());
assertEquals("", error.getLocation());
assertEquals(numberValue, error.getInvalidValue());
assertEquals(maxValueConstraint, error.getConstraint());
numberType.setEnumeratedConstraint(null);
}